.. cmake-manual-description: CMake Buildsystem Reference
cmake-buildsystem(7)
********************
.. only:: html
.. contents::
Introduction
============
A CMake-based buildsystem is organized as a set of high-level logical
targets. Each target corresponds to an executable or library, or
is a custom target containing custom commands. Dependencies between the
targets are expressed in the buildsystem to determine the build order
and the rules for regeneration in response to change.
Binary Targets
==============
Executables and libraries are defined using the :command:`add_executable`
and :command:`add_library` commands. The resulting binary files have
appropriate prefixes, suffixes and extensions for the platform targeted.
Dependencies between binary targets are expressed using the
:command:`target_link_libraries` command:
.. code-block:: cmake
add_library(archive archive.cpp zip.cpp lzma.cpp)
add_executable(zipapp zipapp.cpp)
target_link_libraries(zipapp archive)
``archive`` is defined as a static library -- an archive containing objects
compiled from ``archive.cpp``, ``zip.cpp``, and ``lzma.cpp``. ``zipapp``
is defined as an executable formed by compiling and linking ``zipapp.cpp``.
When linking the ``zipapp`` executable, the ``archive`` static library is
linked in.
Binary Executables
------------------
The :command:`add_executable` command defines an executable target:
.. code-block:: cmake
add_executable(mytool mytool.cpp)
Commands such as :command:`add_custom_command`, which generates rules to be
run at build time can transparently use an :prop_tgt:`EXECUTABLE <TYPE>`
target as a ``COMMAND`` executable. The buildsystem rules will ensure that
the executable is built before attempting to run the command.
Binary Library Types
--------------------
.. _`Normal Libraries`:
Normal Libraries
^^^^^^^^^^^^^^^^
By default, the :command:`add_library` command defines a static library,
unless a type is specified. A type may be specified when using the command:
.. code-block:: cmake
add_library(archive SHARED archive.cpp zip.cpp lzma.cpp)
.. code-block:: cmake
add_library(archive STATIC archive.cpp zip.cpp lzma.cpp)
The :variable:`BUILD_SHARED_LIBS` variable may be enabled to change the
behavior of :command:`add_library` to build shared libraries by default.
In the context of the buildsystem definition as a whole, it is largely
irrelevant whether particular libraries are ``SHARED`` or ``STATIC`` --
the commands, dependency specifications and other APIs work similarly
regardless of the library type. The ``MODULE`` library type is
dissimilar in that it is generally not linked to -- it is not used in
the right-hand-side of the :command:`target_link_libraries` command.
It is a type which is loaded as a plugin using runtime techniques.
If the library does not export any unmanaged symbols (e.g. Windows
resource DLL, C++/CLI DLL), it is required that the library not be a
``SHARED`` library because CMake expects ``SHARED`` libraries to export
at least one symbol.
.. code-block:: cmake
add_library(archive MODULE 7z.cpp)
.. _`Apple Frameworks`:
Apple Frameworks
""""""""""""""""
A ``SHARED`` library may be marked with the :prop_tgt:`FRAMEWORK`
target property to create an OS X or iOS Framework Bundle.
The ``MACOSX_FRAMEWORK_IDENTIFIER`` sets ``CFBundleIdentifier`` key
and it uniquely identifies the bundle.
.. code-block:: cmake
add_library(MyFramework SHARED MyFramework.cpp)
set_target_properties(MyFramework PROPERTIES
FRAMEWORK TRUE
FRAMEWORK_VERSION A
MACOSX_FRAMEWORK_IDENTIFIER org.cmake.MyFramework
)
.. _`Object Libraries`:
Object Libraries
^^^^^^^^^^^^^^^^
The ``OBJECT`` library type is also not linked to. It defines a non-archival
collection of object files resulting from compiling the given source files.
The object files collection can be used as source inputs to other targets:
.. code-block:: cmake
add_library(archive OBJECT archive.cpp zip.cpp lzma.cpp)
add_library(archiveExtras STATIC $<TARGET_OBJECTS:archive> extras.cpp)
add_executable(test_exe $<TARGET_OBJECTS:archive> test.cpp)
``OBJECT`` libraries may not be used in the right hand side of
:command:`target_link_libraries`. They also may not be used as the ``TARGET``
in a use of the :command:`add_custom_command(TARGET)` command signature. They
may be installed, and will be exported as an INTERFACE library.
Although object libraries may not be named directly in calls to
the :command:`target_link_libraries` command, they can be "linked"
indirectly by using an :ref:`Interface Library <Interface Libraries>`
whose :prop_tgt:`INTERFACE_SOURCES` target property is set to name
``$<TARGET_OBJECTS:objlib>``.
Although object libraries may not be used as the ``TARGET``
in a use of the :command:`add_custom_command(TARGET)` command signature,
the list of objects can be used by :command:`add_custom_command(OUTPUT)` or
:command:`file(GENERATE)` by using ``$<TARGET_OBJECTS:objlib>``.
Build Specification and Usage Requirements
==========================================
The :command:`target_include_directories`, :command:`target_compile_definitions`
and :command:`target_compile_options` commands specify the build specifications
and the usage requirements of binary targets. The commands populate the
:prop_tgt:`INCLUDE_DIRECTORIES`, :prop_tgt:`COMPILE_DEFINITIONS` and
:prop_tgt:`COMPILE_OPTIONS` target properties respectively, and/or the
:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES`, :prop_tgt:`INTERFACE_COMPILE_DEFINITIONS`
and :prop_tgt:`INTERFACE_COMPILE_OPTIONS` target properties.
Each of the commands has a ``PRIVATE``, ``PUBLIC`` and ``INTERFACE`` mode. The
``PRIVATE`` mode populates only the non-``INTERFACE_`` variant of the target
property and the ``INTERFACE`` mode populates only the ``INTERFACE_`` variants.
The ``PUBLIC`` mode populates both variants of the respective target property.
Each command may be invoked with multiple uses of each keyword:
.. code-block:: cmake
target_compile_definitions(archive
PRIVATE BUILDING_WITH_LZMA
INTERFACE USING_ARCHIVE_LIB
)
Note that usage requirements are not designed as a way to make downstreams
use particular :prop_tgt:`COMPILE_OPTIONS` or
:prop_tgt:`COMPILE_DEFINITIONS` etc for convenience only. The contents of
the properties must be **requirements**, not merely recommendations or
convenience.
See the :ref:`Creating Relocatable Packages` section of the
:manual:`cmake-packages(7)` manual for discussion of additional care
that must be taken when specifying usage requirements while creating
packages for redistribution.
Target Properties
-----------------
The contents of the :prop_tgt:`INCLUDE_DIRECTORIES`,
:prop_tgt:`COMPILE_DEFINITIONS` and :prop_tgt:`COMPILE_OPTIONS` target
properties are used appropriately when compiling the source files of a
binary target.
Entries in the :prop_tgt:`INCLUDE_DIRECTORIES` are added to the compile line
with ``-I`` or ``-isystem`` prefixes and in the order of appearance in the
property value.
Entries in the :prop_tgt:`COMPILE_DEFINITIONS` are prefixed with ``-D`` or
``/D`` and added to the compile line in an unspecified order. The
:prop_tgt:`DEFINE_SYMBOL` target property is also added as a compile
definition as a special convenience case for ``SHARED`` and ``MODULE``
library targets.
Entries in the :prop_tgt:`COMPILE_OPTIONS` are escaped for the shell and added
in the order of appearance in the property value. Several compile options have
special separate handling, such as :prop_tgt:`POSITION_INDEPENDENT_CODE`.
The contents of the :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES`,
:prop_tgt:`INTERFACE_COMPILE_DEFINITIONS` and
:prop_tgt:`INTERFACE_COMPILE_OPTIONS` target properties are
*Usage Requirements* -- they specify content which consumers
must use to correctly compile and link with the target they appear on.
For any binary target, the contents of each ``INTERFACE_`` property on
each target specified in a :command:`target_link_libraries`
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
CMake-3.9.0 (4922个子文件)
ctest.1 44KB
cmake.1 22KB
ccmake.1 11KB
cpack.1 9KB
cmake-gui.1 7KB
cmake-modules.7 536KB
cmake-commands.7 273KB
cmake-properties.7 191KB
cmake-variables.7 156KB
cmake-policies.7 96KB
cmake-buildsystem.7 39KB
cmake-developer.7 35KB
cmake-packages.7 28KB
cmake-server.7 22KB
cmake-toolchains.7 20KB
cmake-language.7 19KB
cmake-generators.7 19KB
cmake-compile-features.7 14KB
cmake-generator-expressions.7 13KB
cmake-qt.7 9KB
Squish4RunTestCase.bat 629B
SquishRunTestCase.bat 219B
CheckForPthreads.c 747B
CheckFunctionExists.c 449B
CMakeCCompilerABI.c 435B
CheckVariableExists.c 398B
main.c 261B
CMakeTestGNU.c 184B
VerifyC.c 70B
main.c 49B
foo.c 33B
my_module_.c 29B
mymodule_.c 28B
MY_MODULE.c 28B
MYMODULE.c 27B
CPackRPM.cmake 108KB
ExternalProject.cmake 90KB
FindBoost.cmake 88KB
FindCUDA.cmake 83KB
FindQt4.cmake 54KB
FindMatlab.cmake 50KB
UseJava.cmake 49KB
ExternalData.cmake 43KB
BundleUtilities.cmake 41KB
FindwxWidgets.cmake 41KB
CPackDeb.cmake 40KB
FindDoxygen.cmake 37KB
FindGTK2.cmake 37KB
FindHDF5.cmake 36KB
CPackIFW.cmake 34KB
GetPrerequisites.cmake 34KB
FindMPI.cmake 32KB
CMakeDetermineCompilerId.cmake 30KB
FeatureSummary.cmake 29KB
CPack.cmake 26KB
FindPkgConfig.cmake 25KB
WriteCompilerDetectionHeader.cmake 25KB
FindwxWindows.cmake 24KB
FindIce.cmake 22KB
InstallRequiredSystemLibraries.cmake 22KB
CPackComponent.cmake 21KB
FindX11.cmake 20KB
FindBLAS.cmake 20KB
FindProtobuf.cmake 19KB
Qt4Macros.cmake 18KB
FindOpenMP.cmake 18KB
FindPackageHandleStandardArgs.cmake 15KB
GNUInstallDirs.cmake 15KB
FindOpenSSL.cmake 15KB
Android-Determine.cmake 15KB
DeployQt4.cmake 15KB
GenerateExportHeader.cmake 14KB
FortranCInterface.cmake 14KB
UseSWIG.cmake 14KB
Windows-MSVC.cmake 13KB
FindSDL_sound.cmake 13KB
FindPythonLibs.cmake 13KB
KDE3Macros.cmake 13KB
CMakePackageConfigHelpers.cmake 13KB
FindICU.cmake 13KB
Determine-Compiler-NDK.cmake 12KB
run_nvcc.cmake 12KB
FindJNI.cmake 12KB
CMakeDetermineFortranCompiler.cmake 11KB
FindImageMagick.cmake 11KB
CSharpUtilities.cmake 11KB
FindRuby.cmake 11KB
FindDCMTK.cmake 11KB
FindKDE3.cmake 10KB
CMakeCXXInformation.cmake 10KB
FindLAPACK.cmake 10KB
FindJava.cmake 10KB
CTestCoverageCollectGCOV.cmake 10KB
CPackWIX.cmake 10KB
FindSquish.cmake 10KB
UseEcos.cmake 10KB
FindFLTK.cmake 10KB
Windows-GNU.cmake 10KB
CMakeIOSInstallCombined.cmake 10KB
CMakeFortranInformation.cmake 10KB
共 4922 条
- 1
- 2
- 3
- 4
- 5
- 6
- 50
资源评论
- yanghayang2018-02-27可以编译opengl
- victorsow2017-09-01经测试可使用
- 知来者逆2021-12-14没有啥用,用不了
- 李启昂dl2017-09-25是x86的,不是x64的
laodadetou
- 粉丝: 3
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于Python的图像阴影检测与去除源码(高分期末大作业项目).zip
- 基于C++/Qt实现的井字棋游戏
- 基于 Python 编程语言的 Web 框架Django
- Python和Flask实现的基于体检数据的城市公共健康可视分析系统源码+使用说明.zip
- 基于python实现的华为智慧工地-安全帽检测
- buck-boost_2023-12-16_12-12-13.eprj
- 后端开发关于数据库和API开发的介绍
- 机器学习和数据挖掘课程设计-米其林餐厅数据挖掘管理系统源码+使用文档说明.zip
- html html html展示我与ai的对化
- 数据结构课程设计-全国交通出行咨询模拟系统C语言实现源码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功