1CMAKE-BUILDSYSTEM(7)                 CMake                CMAKE-BUILDSYSTEM(7)
2
3
4

NAME

6       cmake-buildsystem - CMake Buildsystem Reference
7

INTRODUCTION

9       A  CMake-based  buildsystem is organized as a set of high-level logical
10       targets.  Each target corresponds to an executable or library, or is  a
11       custom  target  containing  custom  commands.  Dependencies between the
12       targets are expressed in the buildsystem to determine the  build  order
13       and the rules for regeneration in response to change.
14

BINARY TARGETS

16       Executables  and  libraries  are defined using the add_executable() and
17       add_library() commands.  The resulting binary  files  have  appropriate
18       prefixes, suffixes and extensions for the platform targeted.  Dependen‐
19       cies  between   binary   targets   are   expressed   using   the   tar‐
20       get_link_libraries() command:
21
22          add_library(archive archive.cpp zip.cpp lzma.cpp)
23          add_executable(zipapp zipapp.cpp)
24          target_link_libraries(zipapp archive)
25
26       archive  is defined as a static library – an archive containing objects
27       compiled from archive.cpp, zip.cpp, and lzma.cpp.  zipapp is defined as
28       an executable formed by compiling and linking zipapp.cpp.  When linking
29       the zipapp executable, the archive static library is linked in.
30
31   Binary Executables
32       The add_executable() command defines an executable target:
33
34          add_executable(mytool mytool.cpp)
35
36       Commands such as add_custom_command(), which generates rules to be  run
37       at  build  time can transparently use an EXECUTABLE target as a COMMAND
38       executable.  The buildsystem rules will ensure that the  executable  is
39       built before attempting to run the command.
40
41   Binary Library Types
42   Normal Libraries
43       By  default, the add_library() command defines a static library, unless
44       a type is specified.  A type may be specified when using the command:
45
46          add_library(archive SHARED archive.cpp zip.cpp lzma.cpp)
47
48          add_library(archive STATIC archive.cpp zip.cpp lzma.cpp)
49
50       The BUILD_SHARED_LIBS variable may be enabled to change the behavior of
51       add_library() to build shared libraries by default.
52
53       In  the context of the buildsystem definition as a whole, it is largely
54       irrelevant whether particular libraries are SHARED or STATIC – the com‐
55       mands,  dependency specifications and other APIs work similarly regard‐
56       less of the library type.  The MODULE library  type  is  dissimilar  in
57       that  it  is  generally  not  linked  to  –  it  is  not  used  in  the
58       right-hand-side of the target_link_libraries() command.  It is  a  type
59       which  is  loaded as a plugin using runtime techniques.  If the library
60       does not export any  unmanaged  symbols  (e.g.  Windows  resource  DLL,
61       C++/CLI  DLL),  it is required that the library not be a SHARED library
62       because CMake expects SHARED libraries to export at least one symbol.
63
64          add_library(archive MODULE 7z.cpp)
65
66