set_target_properties.rst 5.3 KB

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