CMake 打包可安装程序
可以在各种平台上提供二进制和源代码发行版。 InstallRequiredSystemLibraries CPack 一、需要在顶层 CMakeLists.txt 文件的底部添加几行代码 # 设置CMake版本最低要求 cmake_minimum_required(VERSION 3.10)# 设置项目名称和版本 project(Tutorial VERSION 3.1)# 指定 C++ 标准 set(CMAKE_CXX_STANDARD 11)set(CMAKE_CXX_STANDARD_REQUIRED True)# 设置编译选项 option(USE_MYMATH "Use tutorial provided math implementation" ON)# 生成一个头文件,传递 CMake 的一些设置到源代码 configure_file(TutorialConfig.h.in TutorialConfig.h)# 添加 MathFunctions library # add_subdirectory(MathFunctions) if(USE_MYMATH) add_subdirectory(MathFunctions) list(APPEND EXTRA_LIBS MathFunctions)endif()# 添加源码文件和生成的目标文件的名称 add_executable(Tutorial main.cpp)# target_link_libraries(Tutorial PUBLIC MathFunctions) target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS})# 添加头文件查找路径 # target_include_directories(Tutorial PUBLIC # "${PROJECT_BINARY_DIR}" # "${PROJECT_SOURCE_DIR}/MathFunctions" # ) target_include_directories(Tutorial PUBLIC "${PROJECT_BINARY_DIR}" )## 安装 install(TARGETS Tutorial DESTINATION bin)install(FILES "${PROJECT_BINARY_DIR}/TutorialConfig....