1.设置库名字
#target名字和生成库的名字可以不一样
set_target_properties(TARGET_NAME PROPERTIES OUTPUT_NAME LIB_OUTPUT_NAME)
2.判断位数
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
#是64位
else()
#是32位
endif()
3.设置库文件生成路径
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
4.linux 设置打印gcc编译命令
set(CMAKE_VERBOSE_MAKEFILE ON)
5.linux 执行shell命令
#执行uname -a 命令,并将返回结果保存在UNAME_OUTPUT
execute_process(COMMAND uname -a
OUTPUT_VARIABLE UNAME_OUTPUT)
6.windows debug 模式加上后缀D
set_target_properties(TARGET_NAME PROPERTIES DEBUG_POSTFIX D)
7.windows下编译release版本,设置生成pdb文件
if(WIN32)
set(CMAKE_CXX_FLAGS_RELEASE "{CMAKE_CXX_FLAGS_RELEASE} /Zi")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
endif()
8.windows 链接库区分debug release
TARGET_LINK_LIBRARIES(${LIB_SHARED_NAME}
debug GSFoundation_staticD.lib optimized GSFoundation_static.lib
debug NetLib_staticD.lib optimized NetLib_static.lib
debug GSUdpLib_staticD.lib optimized GSUdpLib_static.lib
)
9.windows 区分VS版本
#MSVC++ 5.0 _MSC_VER == 1100
#MSVC++ 6.0 _MSC_VER == 1200
#MSVC++ 7.0 _MSC_VER == 1300
#MSVC++ 7.1 _MSC_VER == 1310 (Visual Studio 2003)
#MSVC++ 8.0 _MSC_VER == 1400 (Visual Studio 2005)
#MSVC++ 9.0 _MSC_VER == 1500 (Visual Studio 2008)
#MSVC++ 10.0 _MSC_VER == 1600 (Visual Studio 2010)
#MSVC++ 11.0 _MSC_VER == 1700 (Visual Studio 2012)
#MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013)
#MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015)
#MSVC++ 14.1 _MSC_VER == 1911 (Visual Studio 2017)
if(MSVC)
if(MSVC_VERSION EQUAL 1400)
set(_RUNTIME vc8)
elseif(MSVC_VERSION EQUAL 1500)
set(_RUNTIME vc9)
elseif(MSVC_VERSION EQUAL 1600)
set(_RUNTIME vc10)
elseif(MSVC_VERSION EQUAL 1700)
set(_RUNTIME vc11)
elseif(MSVC_VERSION EQUAL 1800)
set(OpenCV_RUNTIME vc12)
elseif(MSVC_VERSION EQUAL 1900)
set(_RUNTIME vc14)
endif()
10.windows dll 打上版本号
#在add_library的时候吧.rc文件包含进去就可以了
ADD_LIBRARY(example_target SHARED ${SRC_LIST} example_target.rc )