一、CMake
二、CMake 的一些用法
1、指定 utf8 编码
// 1 add_compile_options("/source-charset:utf-8") add_compile_options("/execution-charset:utf-8") // 2 add_compile_options(-utf-8) // 3 add_compile_options(/utf-8) // 4 add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>") add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>") add_executable(t1 hello.cpp) // 5 target_compile_options(t1 PUBLIC -utf-8) target_compile_options(t1 PUBLIC /utf-8) target_compile_options(t1 PUBLIC /execution-charset:utf-8)
2、cmake rpath
set(CMAKE_SKIP_BUILD_RPATH FALSE) set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;./") // ; 进行分割 // set_target_properties(目标文件 PROPERTIES INSTALL_RPATH 路径列表)
Linux -L, -l, -rpath, -rpath-link, LD_LIBRARY_PATH和RUNPATH使用说明
解释Linux中的共享库路径(RPATH和RUNPATH)的区别和用途
Linux平台关于可执行程序的动态库加载路径(rpath)的查看与修改
查看RPATH:
readelf -d libxx.so | grep path 0x000000000000000f (RPATH) Library rpath: [/home/3rdParty/lib_linux:/usr/local/lib]
3、cmake 编译Release版本
# windows: cmake --build . --config Release # linux: cmake .. -DCMAKE_BUILD_TYPE=Release
4、cmake重新编译
删除文件夹下的文件 rm CMakeCache.txt 重新编译即可
5、cmake 不优化
if (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") list(APPEND DisableOptimization -Od) endif () add_compile_options(${DisableOptimization}) // target_compile_options(t1 PUBLIC -utf-8)
6、cmake 设置定义
add_compile_definitions(INFERENCE_MNN) // target_compile_definitions(t1 PUBLIC INFERENCE_MNN)
7、cmake 生成动态库
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
8、cuda
project(ft C CXX) if (INFERENCE_TensorRT) enable_language(CUDA) if (NOT DEFINED CMAKE_CUDA_ARCHITECTURES) set(CMAKE_CUDA_ARCHITECTURES 70 75 80) endif (NOT DEFINED CMAKE_CUDA_ARCHITECTURES) endif () add_library(cuLib OBJECT ${CU_SRCS}) if (INFERENCE_TensorRT) set_target_properties(sdk PROPERTIES CUDA_SEPARABLE_COMPILATION ON) endif ()
project(ft C CXX CUDA) 与 enable_language(CUDA) 同样效果
或者
find_package(CUDA REQUIRED) // set(CUDA_MIN_VERSION "8.0") // find_package(CUDA ${CUDA_MIN_VERSION}) cuda_add_library(cuLib STATIC ${CU_SRCS})
find_package( [version] [EXACT] [QUIET] [MODULE]
[REQUIRED] [[COMPONENTS] [components…]]
[OPTIONAL_COMPONENTS components…]
[NO_POLICY_SCOPE])cs