国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists)

這篇具有很好參考價(jià)值的文章主要介紹了CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists)。希望對大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

cmake基礎(chǔ)學(xué)習(xí)教程
https://juejin.cn/post/6844903557183832078

官方完整CMakeLists

cmake_minimum_required(VERSION 3.0)
project(PaddleObjectDetector CXX C)

option(WITH_MKL        "Compile demo with MKL/OpenBlas support,defaultuseMKL."          ON)
option(WITH_GPU        "Compile demo with GPU/CPU, default use CPU."                    ON)
option(WITH_TENSORRT   "Compile demo with TensorRT."                                    OFF)

option(WITH_KEYPOINT        "Whether to Compile KeyPoint detector"                    OFF)
option(WITH_MOT       "Whether to Compile MOT detector" OFF)

SET(PADDLE_DIR "" CACHE PATH "Location of libraries")
SET(PADDLE_LIB_NAME "" CACHE STRING "libpaddle_inference")
SET(OPENCV_DIR "" CACHE PATH "Location of libraries")
SET(CUDA_LIB "" CACHE PATH "Location of libraries")
SET(CUDNN_LIB "" CACHE PATH "Location of libraries")
SET(TENSORRT_INC_DIR "" CACHE PATH "Compile demo with TensorRT")
SET(TENSORRT_LIB_DIR "" CACHE PATH "Compile demo with TensorRT")

include(cmake/yaml-cpp.cmake)

include_directories("${CMAKE_SOURCE_DIR}/")
include_directories("${CMAKE_CURRENT_BINARY_DIR}/ext/yaml-cpp/src/ext-yaml-cpp/include")
link_directories("${CMAKE_CURRENT_BINARY_DIR}/ext/yaml-cpp/lib")

if (WITH_KEYPOINT)
    set(SRCS src/main_keypoint.cc src/preprocess_op.cc src/object_detector.cc src/picodet_postprocess.cc src/utils.cc src/keypoint_detector.cc src/keypoint_postprocess.cc)
elseif (WITH_MOT)
    set(SRCS src/main_jde.cc src/preprocess_op.cc src/object_detector.cc src/jde_detector.cc src/tracker.cc src/trajectory.cc src/lapjv.cpp src/picodet_postprocess.cc src/utils.cc)
else ()
    set(SRCS src/main.cc src/preprocess_op.cc src/object_detector.cc src/picodet_postprocess.cc src/utils.cc)
endif()

#這個(gè)宏定義的意思是如果這些flag中有MD即動(dòng)態(tài)版本,都要替換成靜態(tài)版本
macro(safe_set_static_flag)
    foreach(flag_var
        CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
        CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
      if(${flag_var} MATCHES "/MD")
        string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
      endif(${flag_var} MATCHES "/MD")
    endforeach(flag_var)
endmacro()

if (WITH_MKL)
    ADD_DEFINITIONS(-DUSE_MKL)
endif()

if (NOT DEFINED PADDLE_DIR OR ${PADDLE_DIR} STREQUAL "")
    message(FATAL_ERROR "please set PADDLE_DIR with -DPADDLE_DIR=/path/paddle_influence_dir")
endif()
message("PADDLE_DIR IS:" ${PADDLE_DIR})

if (NOT DEFINED OPENCV_DIR OR ${OPENCV_DIR} STREQUAL "")
    message(FATAL_ERROR "please set OPENCV_DIR with -DOPENCV_DIR=/path/opencv")
endif()

include_directories("${CMAKE_SOURCE_DIR}/")
include_directories("${PADDLE_DIR}/")
include_directories("${PADDLE_DIR}/third_party/install/protobuf/include")
include_directories("${PADDLE_DIR}/third_party/install/glog/include")
include_directories("${PADDLE_DIR}/third_party/install/gflags/include")
include_directories("${PADDLE_DIR}/third_party/install/xxhash/include")
if (EXISTS "${PADDLE_DIR}/third_party/install/snappy/include")
    include_directories("${PADDLE_DIR}/third_party/install/snappy/include")
endif()
if(EXISTS "${PADDLE_DIR}/third_party/install/snappystream/include")
    include_directories("${PADDLE_DIR}/third_party/install/snappystream/include")
endif()
include_directories("${PADDLE_DIR}/third_party/boost")
include_directories("${PADDLE_DIR}/third_party/eigen3")

if (EXISTS "${PADDLE_DIR}/third_party/install/snappy/lib")
    link_directories("${PADDLE_DIR}/third_party/install/snappy/lib")
endif()
if(EXISTS "${PADDLE_DIR}/third_party/install/snappystream/lib")
    link_directories("${PADDLE_DIR}/third_party/install/snappystream/lib")
endif()

link_directories("${PADDLE_DIR}/third_party/install/protobuf/lib")
link_directories("${PADDLE_DIR}/third_party/install/glog/lib")
link_directories("${PADDLE_DIR}/third_party/install/gflags/lib")
link_directories("${PADDLE_DIR}/third_party/install/xxhash/lib")
link_directories("${PADDLE_DIR}/third_party/install/paddle2onnx/lib")
link_directories("${PADDLE_DIR}/third_party/install/onnxruntime/lib")
link_directories("${PADDLE_DIR}/paddle/lib/")
link_directories("${CMAKE_CURRENT_BINARY_DIR}")



if (WIN32)
  include_directories("${PADDLE_DIR}/paddle/fluid/inference")
  include_directories("${PADDLE_DIR}/paddle/include")
  link_directories("${PADDLE_DIR}/paddle/fluid/inference")
  find_package(OpenCV REQUIRED PATHS ${OPENCV_DIR}/build/ NO_DEFAULT_PATH)

else ()
  find_package(OpenCV REQUIRED PATHS ${OPENCV_DIR}/share/OpenCV NO_DEFAULT_PATH)
  include_directories("${PADDLE_DIR}/paddle/include")
  link_directories("${PADDLE_DIR}/paddle/lib")
endif ()
include_directories(${OpenCV_INCLUDE_DIRS})

if (WIN32)
    add_definitions("/DGOOGLE_GLOG_DLL_DECL=")
    set(CMAKE_C_FLAGS_DEBUG   "${CMAKE_C_FLAGS_DEBUG} /bigobj /MTd")
    set(CMAKE_C_FLAGS_RELEASE  "${CMAKE_C_FLAGS_RELEASE} /bigobj /MT")
    set(CMAKE_CXX_FLAGS_DEBUG  "${CMAKE_CXX_FLAGS_DEBUG} /bigobj /MTd")
    set(CMAKE_CXX_FLAGS_RELEASE   "${CMAKE_CXX_FLAGS_RELEASE} /bigobj /MT")
else()
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -o2 -fopenmp -std=c++11")
    set(CMAKE_STATIC_LIBRARY_PREFIX "")
endif()

# TODO let users define cuda lib path
if (WITH_GPU)
    if (NOT DEFINED CUDA_LIB OR ${CUDA_LIB} STREQUAL "")
        message(FATAL_ERROR "please set CUDA_LIB with -DCUDA_LIB=/path/cuda-8.0/lib64")
    endif()
    if (NOT WIN32)
        if (NOT DEFINED CUDNN_LIB)
            message(FATAL_ERROR "please set CUDNN_LIB with -DCUDNN_LIB=/path/cudnn_v7.4/cuda/lib64")
        endif()
    endif(NOT WIN32)
endif()


if (NOT WIN32)
  if (WITH_TENSORRT AND WITH_GPU)
	  include_directories("${TENSORRT_INC_DIR}/")
	  link_directories("${TENSORRT_LIB_DIR}/")
  endif()
endif(NOT WIN32)

if (NOT WIN32)
    set(NGRAPH_PATH "${PADDLE_DIR}/third_party/install/ngraph")
    if(EXISTS ${NGRAPH_PATH})
        include(GNUInstallDirs)
        include_directories("${NGRAPH_PATH}/include")
        link_directories("${NGRAPH_PATH}/${CMAKE_INSTALL_LIBDIR}")
        set(NGRAPH_LIB ${NGRAPH_PATH}/${CMAKE_INSTALL_LIBDIR}/libngraph${CMAKE_SHARED_LIBRARY_SUFFIX})
    endif()
endif()

if(WITH_MKL)
  include_directories("${PADDLE_DIR}/third_party/install/mklml/include")
  if (WIN32)
    set(MATH_LIB ${PADDLE_DIR}/third_party/install/mklml/lib/mklml.lib
            ${PADDLE_DIR}/third_party/install/mklml/lib/libiomp5md.lib)
  else ()
    set(MATH_LIB ${PADDLE_DIR}/third_party/install/mklml/lib/libmklml_intel${CMAKE_SHARED_LIBRARY_SUFFIX}
            ${PADDLE_DIR}/third_party/install/mklml/lib/libiomp5${CMAKE_SHARED_LIBRARY_SUFFIX})
    execute_process(COMMAND cp -r ${PADDLE_DIR}/third_party/install/mklml/lib/libmklml_intel${CMAKE_SHARED_LIBRARY_SUFFIX} /usr/lib)
  endif ()
  set(MKLDNN_PATH "${PADDLE_DIR}/third_party/install/mkldnn")
  if(EXISTS ${MKLDNN_PATH})
    include_directories("${MKLDNN_PATH}/include")
    if (WIN32)
      set(MKLDNN_LIB ${MKLDNN_PATH}/lib/mkldnn.lib)
    else ()
      set(MKLDNN_LIB ${MKLDNN_PATH}/lib/libmkldnn.so.0)
    endif ()
  endif()
else()
  set(MATH_LIB ${PADDLE_DIR}/third_party/install/openblas/lib/libopenblas${CMAKE_STATIC_LIBRARY_SUFFIX})
endif()


if (WIN32)
    if(EXISTS "${PADDLE_DIR}/paddle/fluid/inference/${PADDLE_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}")
        set(DEPS
            ${PADDLE_DIR}/paddle/fluid/inference/${PADDLE_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
    else()
        set(DEPS
            ${PADDLE_DIR}/paddle/lib/${PADDLE_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
    endif()
endif()


if (WIN32)
    set(DEPS ${PADDLE_DIR}/paddle/lib/${PADDLE_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
else()
    set(DEPS ${PADDLE_DIR}/paddle/lib/${PADDLE_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()

message("PADDLE_LIB_NAME:" ${PADDLE_LIB_NAME})
message("DEPS:" $DEPS)

if (NOT WIN32)
    set(DEPS ${DEPS}
        ${MATH_LIB} ${MKLDNN_LIB}
        glog gflags protobuf z xxhash yaml-cpp
        )
    if(EXISTS "${PADDLE_DIR}/third_party/install/snappystream/lib")
        set(DEPS ${DEPS} snappystream)
    endif()
    if (EXISTS "${PADDLE_DIR}/third_party/install/snappy/lib")
        set(DEPS ${DEPS} snappy)
    endif()
else()
    set(DEPS ${DEPS}
        ${MATH_LIB} ${MKLDNN_LIB}
        glog gflags_static libprotobuf xxhash libyaml-cppmt)
    set(DEPS ${DEPS} libcmt shlwapi)
    if (EXISTS "${PADDLE_DIR}/third_party/install/snappy/lib")
        set(DEPS ${DEPS} snappy)
    endif()
    if(EXISTS "${PADDLE_DIR}/third_party/install/snappystream/lib")
        set(DEPS ${DEPS} snappystream)
    endif()
endif(NOT WIN32)

if(WITH_GPU)
  if(NOT WIN32)
    if (WITH_TENSORRT)
	    set(DEPS ${DEPS} ${TENSORRT_LIB_DIR}/libnvinfer${CMAKE_SHARED_LIBRARY_SUFFIX})
	    set(DEPS ${DEPS} ${TENSORRT_LIB_DIR}/libnvinfer_plugin${CMAKE_SHARED_LIBRARY_SUFFIX})
    endif()
    set(DEPS ${DEPS} ${CUDA_LIB}/libcudart${CMAKE_SHARED_LIBRARY_SUFFIX})
    set(DEPS ${DEPS} ${CUDNN_LIB}/libcudnn${CMAKE_SHARED_LIBRARY_SUFFIX})
  else()
    set(DEPS ${DEPS} ${CUDA_LIB}/cudart${CMAKE_STATIC_LIBRARY_SUFFIX} )
    set(DEPS ${DEPS} ${CUDA_LIB}/cublas${CMAKE_STATIC_LIBRARY_SUFFIX} )
    set(DEPS ${DEPS} ${CUDNN_LIB}/cudnn${CMAKE_STATIC_LIBRARY_SUFFIX})
  endif()
endif()

if (NOT WIN32)
    set(EXTERNAL_LIB "-ldl -lrt -lgomp -lz -lm -lpthread")
    set(DEPS ${DEPS} ${EXTERNAL_LIB})
endif()

set(DEPS ${DEPS} ${OpenCV_LIBS})
add_executable(main ${SRCS})
ADD_DEPENDENCIES(main ext-yaml-cpp)
message("DEPS:" $DEPS)
target_link_libraries(main ${DEPS})

if (WIN32 AND WITH_MKL)
    add_custom_command(TARGET main POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/mklml/lib/mklml.dll ./mklml.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/mklml/lib/libiomp5md.dll ./libiomp5md.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/mkldnn/lib/mkldnn.dll ./mkldnn.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/mklml/lib/mklml.dll ./release/mklml.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/mklml/lib/libiomp5md.dll ./release/libiomp5md.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/mkldnn/lib/mkldnn.dll ./release/mkldnn.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/paddle/lib/${PADDLE_LIB_NAME}.dll ./release/${PADDLE_LIB_NAME}.dll
    )
endif()

if (WIN32 AND NOT WITH_MKL)
    add_custom_command(TARGET main POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/openblas/lib/openblas.dll ./openblas.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/openblas/lib/openblas.dll ./release/openblas.dll
    )
endif()

if (WIN32)
    add_custom_command(TARGET main POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/onnxruntime/lib/onnxruntime.dll ./onnxruntime.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/paddle2onnx/lib/paddle2onnx.dll ./paddle2onnx.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/onnxruntime/lib/onnxruntime.dll ./release/onnxruntime.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/paddle2onnx/lib/paddle2onnx.dll ./release/paddle2onnx.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/paddle/lib/${PADDLE_LIB_NAME}.dll ./release/${PADDLE_LIB_NAME}.dll
    )
endif()

project()

項(xiàng)目名CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists),paddle,c++

option(

variable 選項(xiàng)名
help_text 描述、解釋、備注
value 選項(xiàng)初始化值(除ON而外全為OFF))
CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists),paddle,c++

SET()

這個(gè)大寫的SET其實(shí)和小寫的set是一樣的,CMake中的命令不區(qū)分大小寫,CMake中的變量區(qū)分大小寫
CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists),paddle,c++

官方手冊

Set a normal, cache, or environment variable to a given value.
See the :ref:`cmake-language(7) variables <CMake Language Variables>`
documentation for the scopes and interaction of normal variables
and cache entries.

Signatures of this command that specify a ``<value>...`` placeholder
expect zero or more arguments.  Multiple arguments will be joined as
a :ref:`semicolon-separated list <CMake Language Lists>` to form the actual variable
value to be set.  Zero arguments will cause normal variables to be
unset.  See the ``unset()`` command to unset variables explicitly.

Set Normal Variable
^^^^^^^^^^^^^^^^^^^

 set(<variable> <value>... [PARENT_SCOPE])

Sets the given ``<variable>`` in the current function or directory scope.
  • 比較好的案例博客https://blog.csdn.net/Calvin_zhou/article/details/104060927

CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists),paddle,c++
CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists),paddle,c++
CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists),paddle,c++

include(cmake/yaml-cpp.cmake)

加載cmake文件的

Load and run CMake code from a file or module.

 include(<file|module> [OPTIONAL] [RESULT_VARIABLE <var>]
                       [NO_POLICY_SCOPE])

Loads and runs CMake code from the file given.  Variable reads and
writes access the scope of the caller (dynamic scoping).  If ``OPTIONAL``
is present, then no error is raised if the file does not exist.  If
``RESULT_VARIABLE`` is given the variable ``<var>`` will be set to the
full filename which has been included or ``NOTFOUND`` if it failed.

If a module is specified instead of a file, the file with name
``<modulename>.cmake`` is searched first in ``CMAKE_MODULE_PATH``,
then in the CMake module directory.  There is one exception to this: if
the file which calls ``include()`` is located itself in the CMake builtin
module directory, then first the CMake builtin module directory is searched and
``CMAKE_MODULE_PATH`` afterwards.  See also policy ``CMP0017``.

include_directories(“${CMAKE_SOURCE_DIR}/”)

加載頭文件文件夾

Add include directories to the build.

 include_directories([AFTER|BEFORE] [SYSTEM] dir1 [dir2 ...])

Add the given directories to those the compiler uses to search for
include files.  Relative paths are interpreted as relative to the
current source directory.

The include directories are added to the ``INCLUDE_DIRECTORIES``
directory property for the current ``CMakeLists`` file.  They are also
added to the ``INCLUDE_DIRECTORIES`` target property for each
target in the current ``CMakeLists`` file.  The target property values
are the ones used by the generators.

By default the directories specified are appended onto the current list of
directories.  This default behavior can be changed by setting
``CMAKE_INCLUDE_DIRECTORIES_BEFORE`` to ``ON``.  By using

link_directories()

加載庫文件夾地址

Add directories in which the linker will look for libraries.

 link_directories([AFTER|BEFORE] directory1 [directory2 ...])

Adds the paths in which the linker should search for libraries.
Relative paths given to this command are interpreted as relative to
the current source directory, see ``CMP0015``.

The command will apply only to targets created after it is called.

.. versionadded:: 3.13
  The directories are added to the ``LINK_DIRECTORIES`` directory
  property for the current ``CMakeLists.txt`` file, converting relative
  paths to absolute as needed.  See the ``cmake-buildsystem(7)``
  manual for more on defining buildsystem properties.

.. versionadded:: 3.13

macro(safe_set_static_flag)函數(shù)

內(nèi)容
**endmacro**()

這個(gè)函數(shù)屬于宏定義,簡單的說就是出現(xiàn)宏的地方進(jìn)行代碼替換,
解析的很清楚的博文:
https://blog.csdn.net/qq_21438461/article/details/129729530
CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists),paddle,c++
官方文檔:

Start recording a macro for later invocation as a command

 macro(<name> [<arg1> ...])
   <commands>
 endmacro()

Defines a macro named ``<name>`` that takes arguments named
``<arg1>``, ... Commands listed after macro, but before the
matching ``endmacro()``, are not executed until the macro
is invoked.

Per legacy, the ``endmacro()`` command admits an optional
``<name>`` argument. If used, it must be a verbatim repeat of the
argument of the opening ``macro`` command.

See the ``cmake_policy()`` command documentation for the behavior
of policies inside macros.

foreach(參數(shù),循環(huán)列表)函數(shù)

用于循環(huán)列表中的每一項(xiàng)

CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists),paddle,c++
https://blog.csdn.net/wzj_110/article/details/116110014

Evaluate a group of commands for each value in a list.

 foreach(<loop_var> <items>)
   <commands>
 endforeach()

where ``<items>`` is a list of items that are separated by
semicolon or whitespace.
All commands between ``foreach`` and the matching ``endforeach`` are recorded
without being invoked.  Once the ``endforeach`` is evaluated, the recorded
list of commands is invoked once for each item in ``<items>``.
At the beginning of each iteration the variable ``<loop_var>`` will be set
to the value of the current item.

The scope of ``<loop_var>`` is restricted to the loop scope. See policy
``CMP0124`` for details.

MATCHES關(guān)鍵字

條件判斷
https://blog.csdn.net/steptoward/article/details/128848733
可用于正則表達(dá)式
CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists),paddle,c++

  • string(REGEX REPLACE 查找值 替換值 輸出 輸入)
    REGEX REPLACE指正則替換
    https://blog.csdn.net/weixin_41923935/article/details/122155064
    https://blog.csdn.net/m0_57845572/article/details/118520561
    CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists),paddle,c++
String operations.

Synopsis
^^^^^^^^

 Search and Replace
   string(FIND <string> <substring> <out-var> [...])
   string(REPLACE <match-string> <replace-string> <out-var> <input>...)
   string(REGEX MATCH <match-regex> <out-var> <input>...)
   string(REGEX MATCHALL <match-regex> <out-var> <input>...)
   string(REGEX REPLACE <match-regex> <replace-expr> <out-var> <input>...)

 Manipulation
   string(APPEND <string-var> [<input>...])
   string(PREPEND <string-var> [<input>...])
   string(CONCAT <out-var> [<input>...])
   string(JOIN <glue> <out-var> [<input>...])

“/MD” “/MT”

CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists),paddle,c++

ADD_DEFINITIONS(-DUSE_MKL)

這種可以在我們更改別人代碼做實(shí)驗(yàn)時(shí)使用,既不對其源碼進(jìn)行破壞,又可以添加自己的功能。有了這個(gè)后可以直接在編譯的時(shí)候進(jìn)行選擇。具體的,在工程CMakeLists.txt 中,使用add_definitions()函數(shù)控制代碼的開啟和關(guān)閉:
CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists),paddle,c++
https://blog.csdn.net/fb_941219/article/details/107376017
CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists),paddle,c++

Add -D define flags to the compilation of source files.

 add_definitions(-DFOO -DBAR ...)

Adds definitions to the compiler command line for targets in the current
directory, whether added before or after this command is invoked, and for
the ones in sub-directories added after. This command can be used to add any
flags, but it is intended to add preprocessor definitions.

.. note::

  This command has been superseded by alternatives:

  * Use ``add_compile_definitions()`` to add preprocessor definitions.
  * Use ``include_directories()`` to add include directories.
  * Use ``add_compile_options()`` to add other options.

cmake關(guān)系操作符號(hào)

CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists),paddle,c++

find_package(OpenCV REQUIRED PATHS ${OPENCV_DIR}/build/ NO_DEFAULT_PATH)函數(shù)

簡單的說就是用這個(gè)如果找到了.cmake文件,就不用專門寫link_directories,include_directories等函數(shù)來找頭文件和庫文件

Find a package (usually provided by something external to the project),
and load its package-specific details.

Search Modes
^^^^^^^^^^^^

The command has two very distinct ways of conducting the search:

**Module mode**
  In this mode, CMake searches for a file called ``Find<PackageName>.cmake``,
  looking first in the locations listed in the ``CMAKE_MODULE_PATH``,
  then among the :ref:`Find Modules` provided by the CMake installation.
  If the file is found, it is read and processed by CMake.  It is responsible
  for finding the package, checking the version, and producing any needed
  messages.  Some Find modules provide limited or no support for versioning;
  check the Find module's documentation.

寫的最好的關(guān)于find_package的博文
https://blog.csdn.net/zhanghm1995/article/details/105466372
CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists),paddle,c++

CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists),paddle,c++

${CMAKE_SHARED_LIBRARY_SUFFIX}關(guān)鍵字

${CMAKE_STATIC_LIBRARY_SUFFIX}關(guān)鍵字

這個(gè)關(guān)鍵字能根據(jù)平臺(tái)不同,自動(dòng)為動(dòng)態(tài)庫靜態(tài)庫安排后綴,比如windows端的動(dòng)態(tài)庫后綴為dll,靜態(tài)庫為.lib,linux端的動(dòng)態(tài)庫后綴為.so,靜態(tài)庫后綴為.a
CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists),paddle,c++

The suffix for shared libraries that you link to.

The suffix to use for the end of a shared library filename, ``.dll`` on
Windows.

add_dependencies()

大致意思是在同時(shí)生成可執(zhí)行文件a和庫b時(shí),恰好可執(zhí)行文件a的生成需要依賴b這個(gè)庫時(shí)需要用這個(gè)函數(shù)來指定先生成庫b再生成可執(zhí)行文件a,如果不指定會(huì)報(bào)錯(cuò)找不到b依賴庫
CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists),paddle,c++

有案例的博文http://t.csdn.cn/FZdWN

Add a dependency between top-level targets.

 add_dependencies(<target> [<target-dependency>]...)

Makes a top-level ``<target>`` depend on other top-level targets to
ensure that they build before ``<target>`` does.  A top-level target
is one created by one of the ``add_executable()``,
``add_library()``, or ``add_custom_target()`` commands
(but not targets generated by CMake like ``install``).

Dependencies added to an :ref:`imported target <Imported Targets>`
or an :ref:`interface library <Interface Libraries>` are followed
transitively in its place since the target itself does not build.

.. versionadded:: 3.3
  Allow adding dependencies to interface libraries.

target_link_libraries

后面加具體依賴庫的庫名字,不需要加后綴
CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists),paddle,c++

Specify libraries or flags to use when linking a given target and/or
its dependents.  :ref:`Usage requirements <Target Usage Requirements>`
from linked library targets will be propagated.  Usage requirements
of a target's dependencies affect compilation of its own sources.

Overview
^^^^^^^^

This command has several signatures as detailed in subsections below.
All of them have the general form

 target_link_libraries(<target> ... <item>... ...)

The named ``<target>`` must have been created by a command such as
``add_executable()`` or ``add_library()`` and must not be an
:ref:`ALIAS target <Alias Targets>`.  If policy ``CMP0079`` is not
set to ``NEW`` then the target must have been created in the current

add_custom_command

CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists),paddle,c++
CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists),paddle,c++

Add a custom build rule to the generated build system.

There are two main signatures for ``add_custom_command``.

Generating Files
^^^^^^^^^^^^^^^^

The first signature is for adding a custom command to produce an output:

 add_custom_command(OUTPUT output1 [output2 ...]
                    COMMAND command1 [ARGS] [args1...]
                    [COMMAND command2 [ARGS] [args2...] ...]
                    [MAIN_DEPENDENCY depend]
                    [DEPENDS [depends...]]
                    [BYPRODUCTS [files...]]
                    [IMPLICIT_DEPENDS <lang1> depend1
                                     [<lang2> depend2] ...]

相關(guān)博文:
https://www.jianshu.com/p/47370c584356
https://blog.csdn.net/weixin_39766005/article/details/122866375
CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists),paddle,c++文章來源地址http://www.zghlxwxcb.cn/news/detail-701935.html

到了這里,關(guān)于CMake高級(jí)用法實(shí)例分析(學(xué)習(xí)paddle官方的CMakeLists)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Webshell實(shí)例分析解析

    Webshell實(shí)例分析解析

    LD_PRELOAD 是 Linux/Unix 系統(tǒng)的一個(gè)環(huán)境變量,它影響程序的運(yùn)行時(shí)的鏈接(Runtime linker),它允許在程序運(yùn)行前定義優(yōu)先加載的動(dòng)態(tài)鏈接庫。這個(gè)功能主要就是用來有選擇性的載入不同動(dòng)態(tài)鏈接庫中的相同函數(shù)。通過這個(gè)環(huán)境變量,我們可以在主程序和其動(dòng)態(tài)鏈接庫的中間加載別

    2024年02月12日
    瀏覽(15)
  • python實(shí)例分析

    Python是一種高級(jí)編程語言,具有簡單易學(xué)、可讀性強(qiáng)和易用性等特點(diǎn),因此在Web開發(fā)、科學(xué)計(jì)算、數(shù)據(jù)分析、人工智能等領(lǐng)域被廣泛使用。Python的語法簡單明了,易于閱讀和理解,使得開發(fā)者可以更快地編寫代碼,而不用花費(fèi)過多的時(shí)間和精力去學(xué)習(xí)語言本身的復(fù)雜性。 與其

    2023年04月08日
    瀏覽(23)
  • FlinkSQL【分組聚合-多維分析-性能調(diào)優(yōu)】應(yīng)用實(shí)例分析

    FlinkSQL【分組聚合-多維分析-性能調(diào)優(yōu)】應(yīng)用實(shí)例分析

    FlinkSQL處理如下實(shí)時(shí)數(shù)據(jù)需求: 實(shí)時(shí)聚合不同 類型/賬號(hào)/發(fā)布時(shí)間 的各個(gè)指標(biāo)數(shù)據(jù),比如: 初始化/初始化后刪除/初始化后取消/推送/成功/失敗 的指標(biāo)數(shù)據(jù)。要求實(shí)時(shí)產(chǎn)出指標(biāo)數(shù)據(jù),數(shù)據(jù)源是mysql cdc binlog數(shù)據(jù)。 其他配置 flink集群參數(shù) 檢查點(diǎn)配置 job運(yùn)行資源 管理節(jié)點(diǎn)(JM)

    2024年01月17日
    瀏覽(21)
  • PID算法詳解及實(shí)例分析

    PID算法算是控制領(lǐng)域最經(jīng)典,最重要,也是最實(shí)用的算法了。所謂的PID,指的是proportion,integration,differentiation,比例,積分,微分。 因此,PID是結(jié)合了比例積分微分三個(gè)模塊于一身的控制算法。 先看公式: u ( t ) = K p ( e ( t ) + 1 T i ∫ 0 t e ( t ) d t + T d d e ( t ) d t ) u(t) = K_p

    2024年01月21日
    瀏覽(16)
  • LLVM(5)ORC實(shí)例分析

    LLVM(5)ORC實(shí)例分析

    總結(jié) 因?yàn)锳PI茫茫多,邏輯上的一些概念需要搞清,編碼時(shí)會(huì)容易很多。 JIT的運(yùn)行實(shí)體使用LLVMOrcCreateLLJIT可以創(chuàng)建出來,邏輯上的JIT實(shí)例。 JIT實(shí)例需要加入運(yùn)行庫(依賴庫)和用戶定義的context(運(yùn)行內(nèi)容)才能運(yùn)行,LLVMOrcLLJITAddLLVMIRModule函數(shù)負(fù)責(zé)將運(yùn)行庫和ctx加入JIT實(shí)例。

    2024年02月07日
    瀏覽(21)
  • 音頻信號(hào)的頻譜分析實(shí)例

    音頻信號(hào)的頻譜分析實(shí)例

    在前面的文章 信號(hào)頻譜分析與功率譜密度 中,我們初步探討了信號(hào)頻譜分析的概念,并介紹了其數(shù)學(xué)工具。本篇文章將結(jié)合實(shí)例,進(jìn)一步探討頻譜分析在音頻信號(hào)處理中的應(yīng)用。 音頻信號(hào)的頻譜分析是一種將時(shí)域中的音頻信號(hào)轉(zhuǎn)換為頻域表示的過程,從而可以觀察信號(hào)在不

    2024年04月16日
    瀏覽(23)
  • layui表格事件分析實(shí)例

    在 layui 的表格組件中,區(qū)分表頭事件和行內(nèi)事件是通過事件類型(toolbar 和 tool)以及 lay-filter 值來實(shí)現(xiàn)的。 我們有一個(gè)表格,其中有一個(gè)工具欄按鈕和操作按鈕。我們將使用 layui 的 table 組件來處理這些事件。 HTML 結(jié)構(gòu): JavaScript 代碼: 通過在按鈕的 HTML 模板中使用 lay-e

    2024年02月11日
    瀏覽(25)
  • 適合中小企業(yè)的組網(wǎng)實(shí)例分析

    我國中小企業(yè)擁有60%的國民經(jīng)濟(jì)產(chǎn)值,為社會(huì)提供70%以上的就業(yè)機(jī)會(huì),但是許多中小企業(yè)的信息化程度還很低,本文就向中小企業(yè)介紹幾種實(shí)用的企業(yè)信息化方案。企業(yè)信息化的表現(xiàn)有多種多樣,從簡單的文件共享、辦公自動(dòng)化到復(fù)雜的電子商務(wù)、ERP,形形色色,千差萬別。

    2024年02月07日
    瀏覽(22)
  • AAC 音頻數(shù)據(jù)結(jié)構(gòu)實(shí)例分析:

    AAC 音頻數(shù)據(jù)結(jié)構(gòu)實(shí)例分析:

    AAC 音頻數(shù)據(jù)結(jié)構(gòu)實(shí)例分析: AAC 有兩種數(shù)據(jù)交換格式:ADTS 和 ADIF ADIF: Audio Data Interchange Format, 一個(gè)文件只有一個(gè)頭,可類比dvd中使用的ps流。 ADTS:Audio Data Transport Stream, 每個(gè)frame中都有這個(gè)同步頭, 可類比dvb中的ts流. 本博客只介紹 ADTS 格式AAC 基本構(gòu)成是7bytes 頭部+原始數(shù)據(jù). 循

    2024年02月02日
    瀏覽(23)
  • TCP/IP詳解與實(shí)例分析

    TCP/IP詳解與實(shí)例分析

    TCP/IP并不是一個(gè)具體的協(xié)議,而是指一個(gè)由FTP、SMTP、TCP、UDP、IP等協(xié)議構(gòu)成的協(xié)議簇,只是因?yàn)樵赥CP/IP協(xié)議中TCP協(xié)議和IP協(xié)議最具代表性,所以被稱為TCP/IP協(xié)議。 TCP/IP協(xié)議在一定程度上參考了OSI的體系結(jié)構(gòu),在TCP/IP協(xié)議中,它們被簡化為了四個(gè)層次。 OSI七層模型 TCP/IP概念層

    2024年02月08日
    瀏覽(22)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包