set_target_properties.rst 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. set_target_properties
  2. ---------------------
  3. Targets can have properties that affect how they are built.
  4. ::
  5. set_target_properties(target1 target2 ...
  6. PROPERTIES prop1 value1
  7. prop2 value2 ...)
  8. Set properties on a target. The syntax for the command is to list all
  9. the files you want to change, and then provide the values you want to
  10. set next. You can use any prop value pair you want and extract it
  11. later with the :command:`get_target_property` command.
  12. Properties that affect the name of a target's output file are as
  13. follows. The :prop_tgt:`PREFIX` and :prop_tgt:`SUFFIX` properties
  14. override the default target name prefix (such as "lib") and suffix
  15. (such as ".so"). :prop_tgt:`IMPORT_PREFIX` and
  16. :prop_tgt:`IMPORT_SUFFIX` are the equivalent properties for the import
  17. library corresponding to a DLL (for SHARED library targets).
  18. :prop_tgt:`OUTPUT_NAME` sets the real name of a target when it is built
  19. and can be used to help create two targets of the same name even though
  20. CMake requires unique logical target names. There is also a
  21. :prop_tgt:`<CONFIG>_OUTPUT_NAME` that can set the output name on a
  22. per-configuration basis. :prop_tgt:`<CONFIG>_POSTFIX` sets a postfix for
  23. the real name of the target when it is built under the configuration named
  24. by ``<CONFIG>`` (in upper-case, such as "DEBUG_POSTFIX"). The value of this
  25. property is initialized when the target is created to the value of the
  26. variable :variable:`CMAKE_<CONFIG>_POSTFIX`
  27. (except for executable targets because earlier CMake versions which
  28. did not use this variable for executables).
  29. The :prop_tgt:`LINK_FLAGS` property can be used to add extra flags to the
  30. link step of a target. :prop_tgt:`LINK_FLAGS_<CONFIG>` will add to the
  31. configuration ``<CONFIG>``, for example, ``DEBUG``, ``RELEASE``,
  32. ``MINSIZEREL``,``RELWITHDEBINFO``. :prop_tgt:`DEFINE_SYMBOL` sets the name
  33. of the preprocessor symbol defined when compiling sources in a shared
  34. library. If not set here then it is set to target_EXPORTS by default
  35. (with some substitutions if the target is not a valid C identifier). This
  36. is useful for headers to know whether they are being included from inside
  37. their library or outside to properly setup dllexport/dllimport
  38. decorations. The :prop_tgt:`COMPILE_FLAGS` property sets additional
  39. compiler flags used to build sources within the target. It may also be
  40. used to pass additional preprocessor definitions.
  41. The :prop_tgt:`LINKER_LANGUAGE` property is used to change the tool used
  42. to link an executable or shared library. The default is set the language to
  43. match the files in the library. ``CXX`` and ``C`` are common values for this
  44. property.
  45. For shared libraries :prop_tgt:`VERSION` and :prop_tgt:`SOVERSION` can be
  46. used to specify the build version and API version respectively. When
  47. building or installing appropriate symlinks are created if the platform
  48. supports symlinks and the linker supports so-names. If only one of both is
  49. specified the missing is assumed to have the same version number. For
  50. executables :prop_tgt:`VERSION` can be used to specify the build
  51. version. When building or installing appropriate symlinks are created if
  52. the platform supports symlinks. For shared libraries and executables on
  53. Windows the :prop_tgt:`VERSION` attribute is parsed to extract a
  54. "major.minor" version number. These numbers are used as the image
  55. version of the binary.
  56. There are a few properties used to specify RPATH rules.
  57. :prop_tgt:`INSTALL_RPATH` is a semicolon-separated list specifying the
  58. rpath to use in installed targets (for platforms that support it).
  59. :prop_tgt:`INSTALL_RPATH_USE_LINK_PATH` is a boolean that if set to true
  60. will append directories in the linker search path and outside the project
  61. to the :prop_tgt:`INSTALL_RPATH`. :prop_tgt:`SKIP_BUILD_RPATH` is a boolean
  62. specifying whether to skip automatic generation of an rpath allowing the
  63. target to run from the build tree. :prop_tgt:`BUILD_WITH_INSTALL_RPATH` is
  64. a boolean specifying whether to link the target in the build tree with the
  65. :prop_tgt:`INSTALL_RPATH`. This takes precedence over
  66. :prop_tgt:`SKIP_BUILD_RPATH` and avoids the need for relinking before
  67. installation. :prop_tgt:`INSTALL_NAME_DIR` is a string specifying the
  68. directory portion of the "install_name" field of shared libraries on
  69. Mac OSX to use in the installed targets. When the target is created
  70. the values of the variables :variable:`CMAKE_INSTALL_RPATH`,
  71. :variable:`CMAKE_INSTALL_RPATH_USE_LINK_PATH`,
  72. :variable:`CMAKE_SKIP_BUILD_RPATH`,
  73. :variable:`CMAKE_BUILD_WITH_INSTALL_RPATH`, and
  74. :variable:`CMAKE_INSTALL_NAME_DIR` are used to initialize these properties.
  75. :prop_tgt:`PROJECT_LABEL` can be used to change the name of the target in
  76. an IDE like visual studio. :prop_tgt:`VS_KEYWORD` can be set to change
  77. the visual studio keyword, for example Qt integration works better if this
  78. is set to ``Qt4VSv1.0``.
  79. :prop_tgt:`VS_SCC_PROJECTNAME`, :prop_tgt:`VS_SCC_LOCALPATH`,
  80. :prop_tgt:`VS_SCC_PROVIDER` and :prop_tgt:`VS_SCC_AUXPATH` can be set to
  81. add support for source control bindings in a Visual Studio project file.
  82. :prop_tgt:`VS_GLOBAL_<variable>` can be set to add a Visual Studio
  83. project-specific global variable. Qt integration works better if
  84. ``VS_GLOBAL_QtVersion`` is set to the Qt version :module:`FindQt4`
  85. found. For example, "4.7.3"
  86. The :prop_tgt:`PRE_INSTALL_SCRIPT` and :prop_tgt:`POST_INSTALL_SCRIPT`
  87. properties are the old way to specify CMake scripts to run before and
  88. after installing a target. They are used only when the old
  89. :command:`install_targets` command is used to install the target. Use the
  90. :command:`install` command instead.
  91. The :prop_tgt:`EXCLUDE_FROM_DEFAULT_BUILD` property is used by the visual
  92. studio generators. If it is set to 1 the target will not be part of the
  93. default build when you select "Build Solution". This can also be set
  94. on a per-configuration basis using
  95. :prop_tgt:`EXCLUDE_FROM_DEFAULT_BUILD_<CONFIG>`.