CMake 教程2:https://developer.aliyun.com/article/1597129
target_link_options
target_link_options — CMake 3.24.0-rc3 Documentation
# 为可执行文件、共享库或模块库目标的链接步骤添加选项。 target_link_options(<target> [BEFORE] <INTERFACE|PUBLIC|PRIVATE> [items1...] [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
target_precompile_headers
target_precompile_headers — CMake 3.24.0-rc3 Documentation
# 添加要预编译的头文件列表。 # 预编译头文件可以通过创建一些头文件的部分处理版本,然后在编译期间使用该版本而不是重复解析原始头文件来加速编译。 # 主要用法 Main Form target_precompile_headers(<target> <INTERFACE|PUBLIC|PRIVATE> [header1...] [<INTERFACE|PUBLIC|PRIVATE> [header2...] ...]) # 重用预编译头 Reusing Precompile Headers # 该命令还支持第二个签名,可用于指定一个目标重用来自另一个目标的预编译头文件工件,而不是生成自己的: target_precompile_headers(<target> REUSE_FROM <other_target>)
target_sources
target_sources — CMake 3.24.0-rc3 Documentation
# 将源代码添加到目标。 target_sources(<target> <INTERFACE|PUBLIC|PRIVATE> [items1...] [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...]) # 文件集 target_sources(<target> [<INTERFACE|PUBLIC|PRIVATE> [FILE_SET <set> [TYPE <type>] [BASE_DIRS <dirs>...] [FILES <files>...]]... ]...)
try_compile
try_run
CTest 命令(CTest Commands)
ctest_build
ctest_configure
ctest_coverage
ctest_empty_binary_directory
ctest_memcheck
ctest_read_custom_files
ctest_run_script
ctest_sleep
ctest_start
ctest_submit
ctest_test
ctest_update
ctest_upload
cmake-env-variables
cmake 环境变量
改变行为的环境变量
控制构建的环境变量
- ADSP_ROOT
- CMAKE_APPLE_SILICON_PROCESSOR
- CMAKE_BUILD_PARALLEL_LEVEL
- CMAKE_BUILD_TYPE
- CMAKE_COLOR_DIAGNOSTICS
- CMAKE_CONFIGURATION_TYPES
- CMAKE_CONFIG_TYPE
- CMAKE_EXPORT_COMPILE_COMMANDS
- CMAKE_GENERATOR
- CMAKE_GENERATOR_INSTANCE
- CMAKE_GENERATOR_PLATFORM
- CMAKE_GENERATOR_TOOLSET
- CMAKE_INSTALL_MODE
- CMAKE_<LANG>_COMPILER_LAUNCHER
- CMAKE_<LANG>_LINKER_LAUNCHER
- CMAKE_MSVCIDE_RUN_PATH
- CMAKE_NO_VERBOSE
- CMAKE_OSX_ARCHITECTURES
- CMAKE_TOOLCHAIN_FILE
- DESTDIR
- LDFLAGS
- MACOSX_DEPLOYMENT_TARGET
- <PackageName>_ROOT
- VERBOSE
语言环境变量
- ASM<DIALECT>
- ASM<DIALECT>FLAGS
- CC
- CFLAGS
- CSFLAGS
- CUDAARCHS
- CUDACXX
- CUDAFLAGS
- CUDAHOSTCXX
- CXX
- CXXFLAGS
- FC
- FFLAGS
- HIPCXX
- HIPFLAGS
- ISPC
- ISPCFLAGS
- OBJC
- OBJCXX
- RC
- RCFLAGS
CTest 的环境变量
CMake curses 接口的环境变量
cmake-generator-expressions
在构建系统生成期间使用生成器评估表达式以生成特定于每个构建配置的信息
$<BOOL:string> $<AND:conditions> $<OR:conditions> $<NOT:condition>
cmake-generators
生成原生系统的编辑文件,如windows的vcxproj,linux的makefile
命令行构建工具生成器
Makefile Generators
Ninja Generators
Ninja首页、文档和下载 - 小而快的构建系统 - OSCHINA - 中文开源技术交流社区
Ninja 是 Google 的一名程序员推出的注重速度的构建工具,一般在 Unix/Linux 上的程序通过 make/makefile 来构建编译,而 Ninja 通过将编译任务并行组织,大大提高了构建速度。Ninja 的目标是成为汇编程序。
IDE 构建工具生成器
Visual Studio Generators
- Visual Studio 6
- Visual Studio 7
- Visual Studio 7 .NET 2003
- Visual Studio 8 2005
- Visual Studio 9 2008
- Visual Studio 10 2010
- Visual Studio 11 2012
- Visual Studio 12 2013
- Visual Studio 14 2015
- Visual Studio 15 2017
Other Generators
额外的生成器
cmake-language
cmake 语言。讲述其组织、目录结构、脚本、模块、语法、编码、命令调用等
cmake-modules
此处列出的模块是 CMake 发行版的一部分。项目可能提供更多模块,它们的位置可以由CMAKE_MODULE_PATH指定。
实用模块
这些模块使用include()命令进行加载
- AndroidTestUtilities
- BundleUtilities
- CheckCCompilerFlag
- CheckCompilerFlag
- CheckCSourceCompiles
- CheckCSourceRuns
- CheckCXXCompilerFlag
- CheckCXXSourceCompiles
- CheckCXXSourceRuns
- CheckCXXSymbolExists
- CheckFortranCompilerFlag
- CheckFortranFunctionExists
- CheckFortranSourceCompiles
- CheckFortranSourceRuns
- CheckFunctionExists
- CheckIncludeFileCXX
- CheckIncludeFile
- CheckIncludeFiles
- CheckIPOSupported
- CheckLanguage
- CheckLibraryExists
- CheckLinkerFlag
- CheckOBJCCompilerFlag
- CheckOBJCSourceCompiles
- CheckOBJCSourceRuns
- CheckOBJCXXCompilerFlag
- CheckOBJCXXSourceCompiles
- CheckOBJCXXSourceRuns
- CheckPIESupported
- CheckPrototypeDefinition
- CheckSourceCompiles
- CheckSourceRuns
- CheckStructHasMember
- CheckSymbolExists
- CheckTypeSize
- CheckVariableExists
- CMakeAddFortranSubdirectory
- CMakeBackwardCompatibilityCXX
- CMakeDependentOption
- CMakeFindDependencyMacro
- CMakeFindFrameworks
- CMakeFindPackageMode
- CMakeGraphVizOptions
- CMakePackageConfigHelpers
- CMakePrintHelpers
- CMakePrintSystemInformation
- CMakePushCheckState
- CMakeVerifyManifest
- CPack
- CPackComponent
- CPackIFW
- CPackIFWConfigureFile
- CSharpUtilities
- CTest
- CTestCoverageCollectGCOV
- CTestScriptMode
- CTestUseLaunchers
- Dart
- DeployQt4
- ExternalData
- ExternalProject
- FeatureSummary
- FetchContent
- FindPackageHandleStandardArgs
- FindPackageMessage
- FortranCInterface
- GenerateExportHeader
- GetPrerequisites
- GNUInstallDirs
- GoogleTest
- InstallRequiredSystemLibraries
- ProcessorCount
- SelectLibraryConfigurations
- SquishTestScript
- TestBigEndian
- TestForANSIForScope
- TestForANSIStreamHeaders
- TestForSSTREAM
- TestForSTDNamespace
- UseEcos
查找模块
这些模块用来搜索第三方软件。它们通常通过find_package()命令进行使用
- FindALSA
- FindArmadillo
- FindASPELL
- FindAVIFile
- FindBacktrace
- FindBISON
- FindBLAS
- FindBoost
- FindBullet
- FindBZip2
- FindCABLE
- FindCoin3D
- FindCUDAToolkit
- FindCups
- FindCURL
- FindCurses
- FindCVS
- FindCxxTest
- FindCygwin
- FindDart
- FindDCMTK
- FindDevIL
- FindDoxygen
- FindEnvModules
- FindEXPAT
- FindFLEX
- FindFLTK
- FindFLTK2
- FindFontconfig
- FindFreetype
- FindGCCXML
- FindGDAL
- FindGettext
- FindGIF
- FindGit
- FindGLEW
- FindGLUT
- FindGnuplot
- FindGnuTLS
- FindGSL
- FindGTest
- FindGTK
- FindGTK2
- FindHDF5
- FindHg
- FindHSPELL
- FindHTMLHelp
- FindIce
- FindIconv
- FindIcotool
- FindICU
- FindImageMagick
- FindIntl
- FindITK
- FindJasper
- FindJava
- FindJNI
- FindJPEG
- FindKDE3
- FindKDE4
- FindLAPACK
- FindLATEX
- FindLibArchive
- FindLibinput
- FindLibLZMA
- FindLibXml2
- FindLibXslt
- FindLTTngUST
- FindLua
- FindLua50
- FindLua51
- FindMatlab
- FindMFC
- FindMotif
- FindMPEG
- FindMPEG2
- FindMPI
- FindMsys
- FindODBC
- FindOpenACC
- FindOpenAL
- FindOpenCL
- FindOpenGL
- FindOpenMP
- FindOpenSceneGraph
- FindOpenSSL
- FindOpenThreads
- Findosg
- Findosg_functions
- FindosgAnimation
- FindosgDB
- FindosgFX
- FindosgGA
- FindosgIntrospection
- FindosgManipulator
- FindosgParticle
- FindosgPresentation
- FindosgProducer
- FindosgQt
- FindosgShadow
- FindosgSim
- FindosgTerrain
- FindosgText
- FindosgUtil
- FindosgViewer
- FindosgVolume
- FindosgWidget
- FindPatch
- FindPerl
- FindPerlLibs
- FindPHP4
- FindPhysFS
- FindPike
- FindPkgConfig
- FindPNG
- FindPostgreSQL
- FindProducer
- FindProtobuf
- FindPython
- FindPython2
- FindPython3
- FindQt3
- FindQt4
- FindQuickTime
- FindRTI
- FindRuby
- FindSDL
- FindSDL_image
- FindSDL_mixer
- FindSDL_net
- FindSDL_sound
- FindSDL_ttf
- FindSelfPackers
- FindSquish
- FindSQLite3
- FindSubversion
- FindSWIG
- FindTCL
- FindTclsh
- FindTclStub
- FindThreads
- FindTIFF
- FindUnixCommands
- FindVTK
- FindVulkan
- FindWget
- FindWish
- FindwxWidgets
- FindX11
- FindXalanC
cmake-packages
find_package(Qt4 4.7.0 REQUIRED) # CMake provides a Qt4 find-module find_package(Qt5Core 5.1.0 REQUIRED) # Qt provides a Qt5 package config file. find_package(LibXml2 REQUIRED) # Use pkg-config via the LibXml2 find-module
cmake-presets 与人共享
cmake-qt qt cmake
cmake-toolchains
cmake-toolchains(7) — CMake 3.24.0-rc3 Documentation
设置编译工具链
# 一个典型的 Linux 交叉编译工具链包含以下内容: set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR arm) set(CMAKE_SYSROOT /home/devel/rasp-pi-rootfs) set(CMAKE_STAGING_PREFIX /home/devel/stage) set(tools /home/devel/gcc-4.7-linaro-rpi-gnueabihf) set(CMAKE_C_COMPILER ${tools}/bin/arm-linux-gnueabihf-gcc) set(CMAKE_CXX_COMPILER ${tools}/bin/arm-linux-gnueabihf-g++) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
cmake-variables
cmake-variables(7) — CMake 3.24.0-rc3 Documentation