cmake-generator-expressions.7.rst 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262
  1. .. cmake-manual-description: CMake Generator Expressions
  2. cmake-generator-expressions(7)
  3. ******************************
  4. .. only:: html
  5. .. contents::
  6. Introduction
  7. ============
  8. Generator expressions are evaluated during build system generation to produce
  9. information specific to each build configuration.
  10. Generator expressions are allowed in the context of many target properties,
  11. such as :prop_tgt:`LINK_LIBRARIES`, :prop_tgt:`INCLUDE_DIRECTORIES`,
  12. :prop_tgt:`COMPILE_DEFINITIONS` and others. They may also be used when using
  13. commands to populate those properties, such as :command:`target_link_libraries`,
  14. :command:`target_include_directories`, :command:`target_compile_definitions`
  15. and others.
  16. They enable conditional linking, conditional definitions used when compiling,
  17. conditional include directories, and more. The conditions may be based on
  18. the build configuration, target properties, platform information or any other
  19. queryable information.
  20. Generator expressions have the form ``$<...>``. To avoid confusion, this page
  21. deviates from most of the CMake documentation in that it omits angular brackets
  22. ``<...>`` around placeholders like ``condition``, ``string``, ``target``,
  23. among others.
  24. Generator expressions can be nested, as shown in most of the examples below.
  25. .. _`Boolean Generator Expressions`:
  26. Boolean Generator Expressions
  27. =============================
  28. Boolean expressions evaluate to either ``0`` or ``1``.
  29. They are typically used to construct the condition in a :ref:`conditional
  30. generator expression<Conditional Generator Expressions>`.
  31. Available boolean expressions are:
  32. Logical Operators
  33. -----------------
  34. .. genex:: $<BOOL:string>
  35. Converts ``string`` to ``0`` or ``1``. Evaluates to ``0`` if any of the
  36. following is true:
  37. * ``string`` is empty,
  38. * ``string`` is a case-insensitive equal of
  39. ``0``, ``FALSE``, ``OFF``, ``N``, ``NO``, ``IGNORE``, or ``NOTFOUND``, or
  40. * ``string`` ends in the suffix ``-NOTFOUND`` (case-sensitive).
  41. Otherwise evaluates to ``1``.
  42. .. genex:: $<AND:conditions>
  43. where ``conditions`` is a comma-separated list of boolean expressions.
  44. Evaluates to ``1`` if all conditions are ``1``.
  45. Otherwise evaluates to ``0``.
  46. .. genex:: $<OR:conditions>
  47. where ``conditions`` is a comma-separated list of boolean expressions.
  48. Evaluates to ``1`` if at least one of the conditions is ``1``.
  49. Otherwise evaluates to ``0``.
  50. .. genex:: $<NOT:condition>
  51. ``0`` if ``condition`` is ``1``, else ``1``.
  52. String Comparisons
  53. ------------------
  54. .. genex:: $<STREQUAL:string1,string2>
  55. ``1`` if ``string1`` and ``string2`` are equal, else ``0``.
  56. The comparison is case-sensitive. For a case-insensitive comparison,
  57. combine with a :ref:`string transforming generator expression
  58. <String Transforming Generator Expressions>`,
  59. .. code-block:: cmake
  60. $<STREQUAL:$<UPPER_CASE:${foo}>,"BAR"> # "1" if ${foo} is any of "BAR", "Bar", "bar", ...
  61. .. genex:: $<EQUAL:value1,value2>
  62. ``1`` if ``value1`` and ``value2`` are numerically equal, else ``0``.
  63. .. genex:: $<IN_LIST:string,list>
  64. .. versionadded:: 3.12
  65. ``1`` if ``string`` is member of the semicolon-separated ``list``, else ``0``.
  66. Uses case-sensitive comparisons.
  67. .. genex:: $<VERSION_LESS:v1,v2>
  68. ``1`` if ``v1`` is a version less than ``v2``, else ``0``.
  69. .. genex:: $<VERSION_GREATER:v1,v2>
  70. ``1`` if ``v1`` is a version greater than ``v2``, else ``0``.
  71. .. genex:: $<VERSION_EQUAL:v1,v2>
  72. ``1`` if ``v1`` is the same version as ``v2``, else ``0``.
  73. .. genex:: $<VERSION_LESS_EQUAL:v1,v2>
  74. .. versionadded:: 3.7
  75. ``1`` if ``v1`` is a version less than or equal to ``v2``, else ``0``.
  76. .. genex:: $<VERSION_GREATER_EQUAL:v1,v2>
  77. .. versionadded:: 3.7
  78. ``1`` if ``v1`` is a version greater than or equal to ``v2``, else ``0``.
  79. Variable Queries
  80. ----------------
  81. .. genex:: $<TARGET_EXISTS:target>
  82. .. versionadded:: 3.12
  83. ``1`` if ``target`` exists, else ``0``.
  84. .. genex:: $<CONFIG:cfgs>
  85. ``1`` if config is any one of the entries in comma-separated list
  86. ``cfgs``, else ``0``. This is a case-insensitive comparison. The mapping in
  87. :prop_tgt:`MAP_IMPORTED_CONFIG_<CONFIG>` is also considered by this
  88. expression when it is evaluated on a property on an :prop_tgt:`IMPORTED`
  89. target.
  90. .. genex:: $<PLATFORM_ID:platform_ids>
  91. where ``platform_ids`` is a comma-separated list.
  92. ``1`` if the CMake's platform id matches any one of the entries in
  93. ``platform_ids``, otherwise ``0``.
  94. See also the :variable:`CMAKE_SYSTEM_NAME` variable.
  95. .. genex:: $<C_COMPILER_ID:compiler_ids>
  96. where ``compiler_ids`` is a comma-separated list.
  97. ``1`` if the CMake's compiler id of the C compiler matches any one
  98. of the entries in ``compiler_ids``, otherwise ``0``.
  99. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
  100. .. genex:: $<CXX_COMPILER_ID:compiler_ids>
  101. where ``compiler_ids`` is a comma-separated list.
  102. ``1`` if the CMake's compiler id of the CXX compiler matches any one
  103. of the entries in ``compiler_ids``, otherwise ``0``.
  104. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
  105. .. genex:: $<CUDA_COMPILER_ID:compiler_ids>
  106. .. versionadded:: 3.15
  107. where ``compiler_ids`` is a comma-separated list.
  108. ``1`` if the CMake's compiler id of the CUDA compiler matches any one
  109. of the entries in ``compiler_ids``, otherwise ``0``.
  110. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
  111. .. genex:: $<OBJC_COMPILER_ID:compiler_ids>
  112. .. versionadded:: 3.16
  113. where ``compiler_ids`` is a comma-separated list.
  114. ``1`` if the CMake's compiler id of the Objective-C compiler matches any one
  115. of the entries in ``compiler_ids``, otherwise ``0``.
  116. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
  117. .. genex:: $<OBJCXX_COMPILER_ID:compiler_ids>
  118. .. versionadded:: 3.16
  119. where ``compiler_ids`` is a comma-separated list.
  120. ``1`` if the CMake's compiler id of the Objective-C++ compiler matches any one
  121. of the entries in ``compiler_ids``, otherwise ``0``.
  122. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
  123. .. genex:: $<Fortran_COMPILER_ID:compiler_ids>
  124. where ``compiler_ids`` is a comma-separated list.
  125. ``1`` if the CMake's compiler id of the Fortran compiler matches any one
  126. of the entries in ``compiler_ids``, otherwise ``0``.
  127. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
  128. .. genex:: $<HIP_COMPILER_ID:compiler_ids>
  129. where ``compiler_ids`` is a comma-separated list.
  130. ``1`` if the CMake's compiler id of the HIP compiler matches any one
  131. of the entries in ``compiler_ids``, otherwise ``0``.
  132. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
  133. .. genex:: $<ISPC_COMPILER_ID:compiler_ids>
  134. .. versionadded:: 3.19
  135. where ``compiler_ids`` is a comma-separated list.
  136. ``1`` if the CMake's compiler id of the ISPC compiler matches any one
  137. of the entries in ``compiler_ids``, otherwise ``0``.
  138. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
  139. .. genex:: $<C_COMPILER_VERSION:version>
  140. ``1`` if the version of the C compiler matches ``version``, otherwise ``0``.
  141. See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
  142. .. genex:: $<CXX_COMPILER_VERSION:version>
  143. ``1`` if the version of the CXX compiler matches ``version``, otherwise ``0``.
  144. See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
  145. .. genex:: $<CUDA_COMPILER_VERSION:version>
  146. .. versionadded:: 3.15
  147. ``1`` if the version of the CXX compiler matches ``version``, otherwise ``0``.
  148. See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
  149. .. genex:: $<OBJC_COMPILER_VERSION:version>
  150. .. versionadded:: 3.16
  151. ``1`` if the version of the OBJC compiler matches ``version``, otherwise ``0``.
  152. See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
  153. .. genex:: $<OBJCXX_COMPILER_VERSION:version>
  154. .. versionadded:: 3.16
  155. ``1`` if the version of the OBJCXX compiler matches ``version``, otherwise ``0``.
  156. See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
  157. .. genex:: $<Fortran_COMPILER_VERSION:version>
  158. ``1`` if the version of the Fortran compiler matches ``version``, otherwise ``0``.
  159. See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
  160. .. genex:: $<HIP_COMPILER_VERSION:version>
  161. ``1`` if the version of the HIP compiler matches ``version``, otherwise ``0``.
  162. See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
  163. .. genex:: $<ISPC_COMPILER_VERSION:version>
  164. .. versionadded:: 3.19
  165. ``1`` if the version of the ISPC compiler matches ``version``, otherwise ``0``.
  166. See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
  167. .. genex:: $<TARGET_POLICY:policy>
  168. ``1`` if the ``policy`` was NEW when the 'head' target was created,
  169. else ``0``. If the ``policy`` was not set, the warning message for the policy
  170. will be emitted. This generator expression only works for a subset of
  171. policies.
  172. .. genex:: $<COMPILE_FEATURES:features>
  173. .. versionadded:: 3.1
  174. where ``features`` is a comma-spearated list.
  175. Evaluates to ``1`` if all of the ``features`` are available for the 'head'
  176. target, and ``0`` otherwise. If this expression is used while evaluating
  177. the link implementation of a target and if any dependency transitively
  178. increases the required :prop_tgt:`C_STANDARD` or :prop_tgt:`CXX_STANDARD`
  179. for the 'head' target, an error is reported. See the
  180. :manual:`cmake-compile-features(7)` manual for information on
  181. compile features and a list of supported compilers.
  182. .. _`Boolean COMPILE_LANGUAGE Generator Expression`:
  183. .. genex:: $<COMPILE_LANG_AND_ID:language,compiler_ids>
  184. .. versionadded:: 3.15
  185. ``1`` when the language used for compilation unit matches ``language`` and
  186. the CMake's compiler id of the language compiler matches any one of the
  187. entries in ``compiler_ids``, otherwise ``0``. This expression is a short form
  188. for the combination of ``$<COMPILE_LANGUAGE:language>`` and
  189. ``$<LANG_COMPILER_ID:compiler_ids>``. This expression may be used to specify
  190. compile options, compile definitions, and include directories for source files of a
  191. particular language and compiler combination in a target. For example:
  192. .. code-block:: cmake
  193. add_executable(myapp main.cpp foo.c bar.cpp zot.cu)
  194. target_compile_definitions(myapp
  195. PRIVATE $<$<COMPILE_LANG_AND_ID:CXX,AppleClang,Clang>:COMPILING_CXX_WITH_CLANG>
  196. $<$<COMPILE_LANG_AND_ID:CXX,Intel>:COMPILING_CXX_WITH_INTEL>
  197. $<$<COMPILE_LANG_AND_ID:C,Clang>:COMPILING_C_WITH_CLANG>
  198. )
  199. This specifies the use of different compile definitions based on both
  200. the compiler id and compilation language. This example will have a
  201. ``COMPILING_CXX_WITH_CLANG`` compile definition when Clang is the CXX
  202. compiler, and ``COMPILING_CXX_WITH_INTEL`` when Intel is the CXX compiler.
  203. Likewise when the C compiler is Clang it will only see the ``COMPILING_C_WITH_CLANG``
  204. definition.
  205. Without the ``COMPILE_LANG_AND_ID`` generator expression the same logic
  206. would be expressed as:
  207. .. code-block:: cmake
  208. target_compile_definitions(myapp
  209. PRIVATE $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:AppleClang,Clang>>:COMPILING_CXX_WITH_CLANG>
  210. $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:Intel>>:COMPILING_CXX_WITH_INTEL>
  211. $<$<AND:$<COMPILE_LANGUAGE:C>,$<C_COMPILER_ID:Clang>>:COMPILING_C_WITH_CLANG>
  212. )
  213. .. genex:: $<COMPILE_LANGUAGE:languages>
  214. .. versionadded:: 3.3
  215. ``1`` when the language used for compilation unit matches any of the entries
  216. in ``languages``, otherwise ``0``. This expression may be used to specify
  217. compile options, compile definitions, and include directories for source files of a
  218. particular language in a target. For example:
  219. .. code-block:: cmake
  220. add_executable(myapp main.cpp foo.c bar.cpp zot.cu)
  221. target_compile_options(myapp
  222. PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
  223. )
  224. target_compile_definitions(myapp
  225. PRIVATE $<$<COMPILE_LANGUAGE:CXX>:COMPILING_CXX>
  226. $<$<COMPILE_LANGUAGE:CUDA>:COMPILING_CUDA>
  227. )
  228. target_include_directories(myapp
  229. PRIVATE $<$<COMPILE_LANGUAGE:CXX,CUDA>:/opt/foo/headers>
  230. )
  231. This specifies the use of the ``-fno-exceptions`` compile option,
  232. ``COMPILING_CXX`` compile definition, and ``cxx_headers`` include
  233. directory for C++ only (compiler id checks elided). It also specifies
  234. a ``COMPILING_CUDA`` compile definition for CUDA.
  235. Note that with :ref:`Visual Studio Generators` and :generator:`Xcode` there
  236. is no way to represent target-wide compile definitions or include directories
  237. separately for ``C`` and ``CXX`` languages.
  238. Also, with :ref:`Visual Studio Generators` there is no way to represent
  239. target-wide flags separately for ``C`` and ``CXX`` languages. Under these
  240. generators, expressions for both C and C++ sources will be evaluated
  241. using ``CXX`` if there are any C++ sources and otherwise using ``C``.
  242. A workaround is to create separate libraries for each source file language
  243. instead:
  244. .. code-block:: cmake
  245. add_library(myapp_c foo.c)
  246. add_library(myapp_cxx bar.cpp)
  247. target_compile_options(myapp_cxx PUBLIC -fno-exceptions)
  248. add_executable(myapp main.cpp)
  249. target_link_libraries(myapp myapp_c myapp_cxx)
  250. .. _`Boolean LINK_LANGUAGE Generator Expression`:
  251. .. genex:: $<LINK_LANG_AND_ID:language,compiler_ids>
  252. .. versionadded:: 3.18
  253. ``1`` when the language used for link step matches ``language`` and the
  254. CMake's compiler id of the language linker matches any one of the entries
  255. in ``compiler_ids``, otherwise ``0``. This expression is a short form for the
  256. combination of ``$<LINK_LANGUAGE:language>`` and
  257. ``$<LANG_COMPILER_ID:compiler_ids>``. This expression may be used to specify
  258. link libraries, link options, link directories and link dependencies of a
  259. particular language and linker combination in a target. For example:
  260. .. code-block:: cmake
  261. add_library(libC_Clang ...)
  262. add_library(libCXX_Clang ...)
  263. add_library(libC_Intel ...)
  264. add_library(libCXX_Intel ...)
  265. add_executable(myapp main.c)
  266. if (CXX_CONFIG)
  267. target_sources(myapp PRIVATE file.cxx)
  268. endif()
  269. target_link_libraries(myapp
  270. PRIVATE $<$<LINK_LANG_AND_ID:CXX,Clang,AppleClang>:libCXX_Clang>
  271. $<$<LINK_LANG_AND_ID:C,Clang,AppleClang>:libC_Clang>
  272. $<$<LINK_LANG_AND_ID:CXX,Intel>:libCXX_Intel>
  273. $<$<LINK_LANG_AND_ID:C,Intel>:libC_Intel>)
  274. This specifies the use of different link libraries based on both the
  275. compiler id and link language. This example will have target ``libCXX_Clang``
  276. as link dependency when ``Clang`` or ``AppleClang`` is the ``CXX``
  277. linker, and ``libCXX_Intel`` when ``Intel`` is the ``CXX`` linker.
  278. Likewise when the ``C`` linker is ``Clang`` or ``AppleClang``, target
  279. ``libC_Clang`` will be added as link dependency and ``libC_Intel`` when
  280. ``Intel`` is the ``C`` linker.
  281. See :ref:`the note related to
  282. <Constraints LINK_LANGUAGE Generator Expression>`
  283. ``$<LINK_LANGUAGE:language>`` for constraints about the usage of this
  284. generator expression.
  285. .. genex:: $<LINK_LANGUAGE:languages>
  286. .. versionadded:: 3.18
  287. ``1`` when the language used for link step matches any of the entries
  288. in ``languages``, otherwise ``0``. This expression may be used to specify
  289. link libraries, link options, link directories and link dependencies of a
  290. particular language in a target. For example:
  291. .. code-block:: cmake
  292. add_library(api_C ...)
  293. add_library(api_CXX ...)
  294. add_library(api INTERFACE)
  295. target_link_options(api INTERFACE $<$<LINK_LANGUAGE:C>:-opt_c>
  296. $<$<LINK_LANGUAGE:CXX>:-opt_cxx>)
  297. target_link_libraries(api INTERFACE $<$<LINK_LANGUAGE:C>:api_C>
  298. $<$<LINK_LANGUAGE:CXX>:api_CXX>)
  299. add_executable(myapp1 main.c)
  300. target_link_options(myapp1 PRIVATE api)
  301. add_executable(myapp2 main.cpp)
  302. target_link_options(myapp2 PRIVATE api)
  303. This specifies to use the ``api`` target for linking targets ``myapp1`` and
  304. ``myapp2``. In practice, ``myapp1`` will link with target ``api_C`` and
  305. option ``-opt_c`` because it will use ``C`` as link language. And ``myapp2``
  306. will link with ``api_CXX`` and option ``-opt_cxx`` because ``CXX`` will be
  307. the link language.
  308. .. _`Constraints LINK_LANGUAGE Generator Expression`:
  309. .. note::
  310. To determine the link language of a target, it is required to collect,
  311. transitively, all the targets which will be linked to it. So, for link
  312. libraries properties, a double evaluation will be done. During the first
  313. evaluation, ``$<LINK_LANGUAGE:..>`` expressions will always return ``0``.
  314. The link language computed after this first pass will be used to do the
  315. second pass. To avoid inconsistency, it is required that the second pass
  316. do not change the link language. Moreover, to avoid unexpected
  317. side-effects, it is required to specify complete entities as part of the
  318. ``$<LINK_LANGUAGE:..>`` expression. For example:
  319. .. code-block:: cmake
  320. add_library(lib STATIC file.cxx)
  321. add_library(libother STATIC file.c)
  322. # bad usage
  323. add_executable(myapp1 main.c)
  324. target_link_libraries(myapp1 PRIVATE lib$<$<LINK_LANGUAGE:C>:other>)
  325. # correct usage
  326. add_executable(myapp2 main.c)
  327. target_link_libraries(myapp2 PRIVATE $<$<LINK_LANGUAGE:C>:libother>)
  328. In this example, for ``myapp1``, the first pass will, unexpectedly,
  329. determine that the link language is ``CXX`` because the evaluation of the
  330. generator expression will be an empty string so ``myapp1`` will depends on
  331. target ``lib`` which is ``C++``. On the contrary, for ``myapp2``, the first
  332. evaluation will give ``C`` as link language, so the second pass will
  333. correctly add target ``libother`` as link dependency.
  334. .. genex:: $<DEVICE_LINK:list>
  335. .. versionadded:: 3.18
  336. Returns the list if it is the device link step, an empty list otherwise.
  337. The device link step is controlled by :prop_tgt:`CUDA_SEPARABLE_COMPILATION`
  338. and :prop_tgt:`CUDA_RESOLVE_DEVICE_SYMBOLS` properties and
  339. policy :policy:`CMP0105`. This expression can only be used to specify link
  340. options.
  341. .. genex:: $<HOST_LINK:list>
  342. .. versionadded:: 3.18
  343. Returns the list if it is the normal link step, an empty list otherwise.
  344. This expression is mainly useful when a device link step is also involved
  345. (see ``$<DEVICE_LINK:list>`` generator expression). This expression can only
  346. be used to specify link options.
  347. String-Valued Generator Expressions
  348. ===================================
  349. These expressions expand to some string.
  350. For example,
  351. .. code-block:: cmake
  352. include_directories(/usr/include/$<CXX_COMPILER_ID>/)
  353. expands to ``/usr/include/GNU/`` or ``/usr/include/Clang/`` etc, depending on
  354. the compiler identifier.
  355. String-valued expressions may also be combined with other expressions.
  356. Here an example for a string-valued expression within a boolean expressions
  357. within a conditional expression:
  358. .. code-block:: cmake
  359. $<$<VERSION_LESS:$<CXX_COMPILER_VERSION>,4.2.0>:OLD_COMPILER>
  360. expands to ``OLD_COMPILER`` if the
  361. :variable:`CMAKE_CXX_COMPILER_VERSION <CMAKE_<LANG>_COMPILER_VERSION>` is less
  362. than 4.2.0.
  363. And here two nested string-valued expressions:
  364. .. code-block:: cmake
  365. -I$<JOIN:$<TARGET_PROPERTY:INCLUDE_DIRECTORIES>, -I>
  366. generates a string of the entries in the :prop_tgt:`INCLUDE_DIRECTORIES` target
  367. property with each entry preceded by ``-I``.
  368. Expanding on the previous example, if one first wants to check if the
  369. ``INCLUDE_DIRECTORIES`` property is non-empty, then it is advisable to
  370. introduce a helper variable to keep the code readable:
  371. .. code-block:: cmake
  372. set(prop "$<TARGET_PROPERTY:INCLUDE_DIRECTORIES>") # helper variable
  373. $<$<BOOL:${prop}>:-I$<JOIN:${prop}, -I>>
  374. The following string-valued generator expressions are available:
  375. Escaped Characters
  376. ------------------
  377. String literals to escape the special meaning a character would otherwise have:
  378. .. genex:: $<ANGLE-R>
  379. A literal ``>``. Used for example to compare strings that contain a ``>``.
  380. .. genex:: $<COMMA>
  381. A literal ``,``. Used for example to compare strings which contain a ``,``.
  382. .. genex:: $<SEMICOLON>
  383. A literal ``;``. Used to prevent list expansion on an argument with ``;``.
  384. .. _`Conditional Generator Expressions`:
  385. Conditional Expressions
  386. -----------------------
  387. Conditional generator expressions depend on a boolean condition
  388. that must be ``0`` or ``1``.
  389. .. genex:: $<condition:true_string>
  390. Evaluates to ``true_string`` if ``condition`` is ``1``.
  391. Otherwise evaluates to the empty string.
  392. .. genex:: $<IF:condition,true_string,false_string>
  393. .. versionadded:: 3.8
  394. Evaluates to ``true_string`` if ``condition`` is ``1``.
  395. Otherwise evaluates to ``false_string``.
  396. Typically, the ``condition`` is a :ref:`boolean generator expression
  397. <Boolean Generator Expressions>`. For instance,
  398. .. code-block:: cmake
  399. $<$<CONFIG:Debug>:DEBUG_MODE>
  400. expands to ``DEBUG_MODE`` when the ``Debug`` configuration is used, and
  401. otherwise expands to the empty string.
  402. .. _`String Transforming Generator Expressions`:
  403. String Transformations
  404. ----------------------
  405. .. genex:: $<JOIN:list,string>
  406. Joins the list with the content of ``string``.
  407. .. genex:: $<REMOVE_DUPLICATES:list>
  408. .. versionadded:: 3.15
  409. Removes duplicated items in the given ``list``.
  410. .. genex:: $<FILTER:list,INCLUDE|EXCLUDE,regex>
  411. .. versionadded:: 3.15
  412. Includes or removes items from ``list`` that match the regular expression ``regex``.
  413. .. genex:: $<LOWER_CASE:string>
  414. Content of ``string`` converted to lower case.
  415. .. genex:: $<UPPER_CASE:string>
  416. Content of ``string`` converted to upper case.
  417. .. genex:: $<GENEX_EVAL:expr>
  418. .. versionadded:: 3.12
  419. Content of ``expr`` evaluated as a generator expression in the current
  420. context. This enables consumption of generator expressions whose
  421. evaluation results itself in generator expressions.
  422. .. genex:: $<TARGET_GENEX_EVAL:tgt,expr>
  423. .. versionadded:: 3.12
  424. Content of ``expr`` evaluated as a generator expression in the context of
  425. ``tgt`` target. This enables consumption of custom target properties that
  426. themselves contain generator expressions.
  427. Having the capability to evaluate generator expressions is very useful when
  428. you want to manage custom properties supporting generator expressions.
  429. For example:
  430. .. code-block:: cmake
  431. add_library(foo ...)
  432. set_property(TARGET foo PROPERTY
  433. CUSTOM_KEYS $<$<CONFIG:DEBUG>:FOO_EXTRA_THINGS>
  434. )
  435. add_custom_target(printFooKeys
  436. COMMAND ${CMAKE_COMMAND} -E echo $<TARGET_PROPERTY:foo,CUSTOM_KEYS>
  437. )
  438. This naive implementation of the ``printFooKeys`` custom command is wrong
  439. because ``CUSTOM_KEYS`` target property is not evaluated and the content
  440. is passed as is (i.e. ``$<$<CONFIG:DEBUG>:FOO_EXTRA_THINGS>``).
  441. To have the expected result (i.e. ``FOO_EXTRA_THINGS`` if config is
  442. ``Debug``), it is required to evaluate the output of
  443. ``$<TARGET_PROPERTY:foo,CUSTOM_KEYS>``:
  444. .. code-block:: cmake
  445. add_custom_target(printFooKeys
  446. COMMAND ${CMAKE_COMMAND} -E
  447. echo $<TARGET_GENEX_EVAL:foo,$<TARGET_PROPERTY:foo,CUSTOM_KEYS>>
  448. )
  449. Variable Queries
  450. ----------------
  451. .. genex:: $<CONFIG>
  452. Configuration name.
  453. .. genex:: $<CONFIGURATION>
  454. Configuration name. Deprecated since CMake 3.0. Use ``CONFIG`` instead.
  455. .. genex:: $<PLATFORM_ID>
  456. The current system's CMake platform id.
  457. See also the :variable:`CMAKE_SYSTEM_NAME` variable.
  458. .. genex:: $<C_COMPILER_ID>
  459. The CMake's compiler id of the C compiler used.
  460. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
  461. .. genex:: $<CXX_COMPILER_ID>
  462. The CMake's compiler id of the CXX compiler used.
  463. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
  464. .. genex:: $<CUDA_COMPILER_ID>
  465. The CMake's compiler id of the CUDA compiler used.
  466. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
  467. .. genex:: $<OBJC_COMPILER_ID>
  468. .. versionadded:: 3.16
  469. The CMake's compiler id of the OBJC compiler used.
  470. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
  471. .. genex:: $<OBJCXX_COMPILER_ID>
  472. .. versionadded:: 3.16
  473. The CMake's compiler id of the OBJCXX compiler used.
  474. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
  475. .. genex:: $<Fortran_COMPILER_ID>
  476. The CMake's compiler id of the Fortran compiler used.
  477. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
  478. .. genex:: $<HIP_COMPILER_ID>
  479. The CMake's compiler id of the HIP compiler used.
  480. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
  481. .. genex:: $<ISPC_COMPILER_ID>
  482. .. versionadded:: 3.19
  483. The CMake's compiler id of the ISPC compiler used.
  484. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
  485. .. genex:: $<C_COMPILER_VERSION>
  486. The version of the C compiler used.
  487. See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
  488. .. genex:: $<CXX_COMPILER_VERSION>
  489. The version of the CXX compiler used.
  490. See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
  491. .. genex:: $<CUDA_COMPILER_VERSION>
  492. The version of the CUDA compiler used.
  493. See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
  494. .. genex:: $<OBJC_COMPILER_VERSION>
  495. .. versionadded:: 3.16
  496. The version of the OBJC compiler used.
  497. See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
  498. .. genex:: $<OBJCXX_COMPILER_VERSION>
  499. .. versionadded:: 3.16
  500. The version of the OBJCXX compiler used.
  501. See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
  502. .. genex:: $<Fortran_COMPILER_VERSION>
  503. The version of the Fortran compiler used.
  504. See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
  505. .. genex:: $<HIP_COMPILER_VERSION>
  506. The version of the HIP compiler used.
  507. See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
  508. .. genex:: $<ISPC_COMPILER_VERSION>
  509. .. versionadded:: 3.19
  510. The version of the ISPC compiler used.
  511. See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
  512. .. genex:: $<COMPILE_LANGUAGE>
  513. .. versionadded:: 3.3
  514. The compile language of source files when evaluating compile options.
  515. See :ref:`the related boolean expression
  516. <Boolean COMPILE_LANGUAGE Generator Expression>`
  517. ``$<COMPILE_LANGUAGE:language>``
  518. for notes about the portability of this generator expression.
  519. .. genex:: $<LINK_LANGUAGE>
  520. .. versionadded:: 3.18
  521. The link language of target when evaluating link options.
  522. See :ref:`the related boolean expression
  523. <Boolean LINK_LANGUAGE Generator Expression>` ``$<LINK_LANGUAGE:language>``
  524. for notes about the portability of this generator expression.
  525. .. note::
  526. This generator expression is not supported by the link libraries
  527. properties to avoid side-effects due to the double evaluation of
  528. these properties.
  529. .. _`Target-Dependent Queries`:
  530. Target-Dependent Queries
  531. ------------------------
  532. These queries refer to a target ``tgt``. This can be any runtime artifact,
  533. namely:
  534. * an executable target created by :command:`add_executable`
  535. * a shared library target (``.so``, ``.dll`` but not their ``.lib`` import library)
  536. created by :command:`add_library`
  537. * a static library target created by :command:`add_library`
  538. In the following, "the ``tgt`` filename" means the name of the ``tgt``
  539. binary file. This has to be distinguished from "the target name",
  540. which is just the string ``tgt``.
  541. .. genex:: $<TARGET_NAME_IF_EXISTS:tgt>
  542. .. versionadded:: 3.12
  543. The target name ``tgt`` if the target exists, an empty string otherwise.
  544. Note that ``tgt`` is not added as a dependency of the target this
  545. expression is evaluated on.
  546. .. genex:: $<TARGET_FILE:tgt>
  547. Full path to the ``tgt`` binary file.
  548. .. genex:: $<TARGET_FILE_BASE_NAME:tgt>
  549. .. versionadded:: 3.15
  550. Base name of ``tgt``, i.e. ``$<TARGET_FILE_NAME:tgt>`` without prefix and
  551. suffix.
  552. For example, if the ``tgt`` filename is ``libbase.so``, the base name is ``base``.
  553. See also the :prop_tgt:`OUTPUT_NAME`, :prop_tgt:`ARCHIVE_OUTPUT_NAME`,
  554. :prop_tgt:`LIBRARY_OUTPUT_NAME` and :prop_tgt:`RUNTIME_OUTPUT_NAME`
  555. target properties and their configuration specific variants
  556. :prop_tgt:`OUTPUT_NAME_<CONFIG>`, :prop_tgt:`ARCHIVE_OUTPUT_NAME_<CONFIG>`,
  557. :prop_tgt:`LIBRARY_OUTPUT_NAME_<CONFIG>` and
  558. :prop_tgt:`RUNTIME_OUTPUT_NAME_<CONFIG>`.
  559. The :prop_tgt:`<CONFIG>_POSTFIX` and :prop_tgt:`DEBUG_POSTFIX` target
  560. properties can also be considered.
  561. Note that ``tgt`` is not added as a dependency of the target this
  562. expression is evaluated on.
  563. .. genex:: $<TARGET_FILE_PREFIX:tgt>
  564. .. versionadded:: 3.15
  565. Prefix of the ``tgt`` filename (such as ``lib``).
  566. See also the :prop_tgt:`PREFIX` target property.
  567. Note that ``tgt`` is not added as a dependency of the target this
  568. expression is evaluated on.
  569. .. genex:: $<TARGET_FILE_SUFFIX:tgt>
  570. .. versionadded:: 3.15
  571. Suffix of the ``tgt`` filename (extension such as ``.so`` or ``.exe``).
  572. See also the :prop_tgt:`SUFFIX` target property.
  573. Note that ``tgt`` is not added as a dependency of the target this
  574. expression is evaluated on.
  575. .. genex:: $<TARGET_FILE_NAME:tgt>
  576. The ``tgt`` filename.
  577. Note that ``tgt`` is not added as a dependency of the target this
  578. expression is evaluated on (see policy :policy:`CMP0112`).
  579. .. genex:: $<TARGET_FILE_DIR:tgt>
  580. Directory of the ``tgt`` binary file.
  581. Note that ``tgt`` is not added as a dependency of the target this
  582. expression is evaluated on (see policy :policy:`CMP0112`).
  583. .. genex:: $<TARGET_LINKER_FILE:tgt>
  584. File used when linking to the ``tgt`` target. This will usually
  585. be the library that ``tgt`` represents (``.a``, ``.lib``, ``.so``),
  586. but for a shared library on DLL platforms, it would be the ``.lib``
  587. import library associated with the DLL.
  588. .. genex:: $<TARGET_LINKER_FILE_BASE_NAME:tgt>
  589. .. versionadded:: 3.15
  590. Base name of file used to link the target ``tgt``, i.e.
  591. ``$<TARGET_LINKER_FILE_NAME:tgt>`` without prefix and suffix. For example,
  592. if target file name is ``libbase.a``, the base name is ``base``.
  593. See also the :prop_tgt:`OUTPUT_NAME`, :prop_tgt:`ARCHIVE_OUTPUT_NAME`,
  594. and :prop_tgt:`LIBRARY_OUTPUT_NAME` target properties and their configuration
  595. specific variants :prop_tgt:`OUTPUT_NAME_<CONFIG>`,
  596. :prop_tgt:`ARCHIVE_OUTPUT_NAME_<CONFIG>` and
  597. :prop_tgt:`LIBRARY_OUTPUT_NAME_<CONFIG>`.
  598. The :prop_tgt:`<CONFIG>_POSTFIX` and :prop_tgt:`DEBUG_POSTFIX` target
  599. properties can also be considered.
  600. Note that ``tgt`` is not added as a dependency of the target this
  601. expression is evaluated on.
  602. .. genex:: $<TARGET_LINKER_FILE_PREFIX:tgt>
  603. .. versionadded:: 3.15
  604. Prefix of file used to link target ``tgt``.
  605. See also the :prop_tgt:`PREFIX` and :prop_tgt:`IMPORT_PREFIX` target
  606. properties.
  607. Note that ``tgt`` is not added as a dependency of the target this
  608. expression is evaluated on.
  609. .. genex:: $<TARGET_LINKER_FILE_SUFFIX:tgt>
  610. .. versionadded:: 3.15
  611. Suffix of file used to link where ``tgt`` is the name of a target.
  612. The suffix corresponds to the file extension (such as ".so" or ".lib").
  613. See also the :prop_tgt:`SUFFIX` and :prop_tgt:`IMPORT_SUFFIX` target
  614. properties.
  615. Note that ``tgt`` is not added as a dependency of the target this
  616. expression is evaluated on.
  617. .. genex:: $<TARGET_LINKER_FILE_NAME:tgt>
  618. Name of file used to link target ``tgt``.
  619. Note that ``tgt`` is not added as a dependency of the target this
  620. expression is evaluated on (see policy :policy:`CMP0112`).
  621. .. genex:: $<TARGET_LINKER_FILE_DIR:tgt>
  622. Directory of file used to link target ``tgt``.
  623. Note that ``tgt`` is not added as a dependency of the target this
  624. expression is evaluated on (see policy :policy:`CMP0112`).
  625. .. genex:: $<TARGET_SONAME_FILE:tgt>
  626. File with soname (``.so.3``) where ``tgt`` is the name of a target.
  627. .. genex:: $<TARGET_SONAME_FILE_NAME:tgt>
  628. Name of file with soname (``.so.3``).
  629. Note that ``tgt`` is not added as a dependency of the target this
  630. expression is evaluated on (see policy :policy:`CMP0112`).
  631. .. genex:: $<TARGET_SONAME_FILE_DIR:tgt>
  632. Directory of with soname (``.so.3``).
  633. Note that ``tgt`` is not added as a dependency of the target this
  634. expression is evaluated on (see policy :policy:`CMP0112`).
  635. .. genex:: $<TARGET_PDB_FILE:tgt>
  636. .. versionadded:: 3.1
  637. Full path to the linker generated program database file (.pdb)
  638. where ``tgt`` is the name of a target.
  639. See also the :prop_tgt:`PDB_NAME` and :prop_tgt:`PDB_OUTPUT_DIRECTORY`
  640. target properties and their configuration specific variants
  641. :prop_tgt:`PDB_NAME_<CONFIG>` and :prop_tgt:`PDB_OUTPUT_DIRECTORY_<CONFIG>`.
  642. .. genex:: $<TARGET_PDB_FILE_BASE_NAME:tgt>
  643. .. versionadded:: 3.15
  644. Base name of the linker generated program database file (.pdb)
  645. where ``tgt`` is the name of a target.
  646. The base name corresponds to the target PDB file name (see
  647. ``$<TARGET_PDB_FILE_NAME:tgt>``) without prefix and suffix. For example,
  648. if target file name is ``base.pdb``, the base name is ``base``.
  649. See also the :prop_tgt:`PDB_NAME` target property and its configuration
  650. specific variant :prop_tgt:`PDB_NAME_<CONFIG>`.
  651. The :prop_tgt:`<CONFIG>_POSTFIX` and :prop_tgt:`DEBUG_POSTFIX` target
  652. properties can also be considered.
  653. Note that ``tgt`` is not added as a dependency of the target this
  654. expression is evaluated on.
  655. .. genex:: $<TARGET_PDB_FILE_NAME:tgt>
  656. .. versionadded:: 3.1
  657. Name of the linker generated program database file (.pdb).
  658. Note that ``tgt`` is not added as a dependency of the target this
  659. expression is evaluated on (see policy :policy:`CMP0112`).
  660. .. genex:: $<TARGET_PDB_FILE_DIR:tgt>
  661. .. versionadded:: 3.1
  662. Directory of the linker generated program database file (.pdb).
  663. Note that ``tgt`` is not added as a dependency of the target this
  664. expression is evaluated on (see policy :policy:`CMP0112`).
  665. .. genex:: $<TARGET_BUNDLE_DIR:tgt>
  666. .. versionadded:: 3.9
  667. Full path to the bundle directory (``my.app``, ``my.framework``, or
  668. ``my.bundle``) where ``tgt`` is the name of a target.
  669. Note that ``tgt`` is not added as a dependency of the target this
  670. expression is evaluated on (see policy :policy:`CMP0112`).
  671. .. genex:: $<TARGET_BUNDLE_CONTENT_DIR:tgt>
  672. .. versionadded:: 3.9
  673. Full path to the bundle content directory where ``tgt`` is the name of a
  674. target. For the macOS SDK it leads to ``my.app/Contents``, ``my.framework``,
  675. or ``my.bundle/Contents``. For all other SDKs (e.g. iOS) it leads to
  676. ``my.app``, ``my.framework``, or ``my.bundle`` due to the flat bundle
  677. structure.
  678. Note that ``tgt`` is not added as a dependency of the target this
  679. expression is evaluated on (see policy :policy:`CMP0112`).
  680. .. genex:: $<TARGET_PROPERTY:tgt,prop>
  681. Value of the property ``prop`` on the target ``tgt``.
  682. Note that ``tgt`` is not added as a dependency of the target this
  683. expression is evaluated on.
  684. .. genex:: $<TARGET_PROPERTY:prop>
  685. Value of the property ``prop`` on the target for which the expression
  686. is being evaluated. Note that for generator expressions in
  687. :ref:`Target Usage Requirements` this is the consuming target rather
  688. than the target specifying the requirement.
  689. .. genex:: $<TARGET_RUNTIME_DLLS:tgt>
  690. .. versionadded:: 3.21
  691. List of DLLs that the target depends on at runtime. This is determined by
  692. the locations of all the ``SHARED`` and ``MODULE`` targets in the target's
  693. transitive dependencies. Using this generator expression on targets other
  694. than executables, ``SHARED`` libraries, and ``MODULE`` libraries is an error.
  695. On non-DLL platforms, it evaluates to an empty string.
  696. This generator expression can be used to copy all of the DLLs that a target
  697. depends on into its output directory in a ``POST_BUILD`` custom command. For
  698. example:
  699. .. code-block:: cmake
  700. find_package(foo CONFIG REQUIRED) # package generated by install(EXPORT)
  701. add_executable(exe main.c)
  702. target_link_libraries(exe PRIVATE foo::foo foo::bar)
  703. add_custom_command(TARGET exe POST_BUILD
  704. COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:exe> $<TARGET_FILE_DIR:exe>
  705. COMMAND_EXPAND_LISTS
  706. )
  707. .. note::
  708. :ref:`Imported Targets` are supported only if they know the location
  709. of their ``.dll`` files. An imported ``SHARED`` or ``MODULE`` library
  710. must have :prop_tgt:`IMPORTED_LOCATION` set to its ``.dll`` file. See
  711. the :ref:`add_library imported libraries <add_library imported libraries>`
  712. section for details. Many :ref:`Find Modules` produce imported targets
  713. with the ``UNKNOWN`` type and therefore will be ignored.
  714. .. genex:: $<INSTALL_PREFIX>
  715. Content of the install prefix when the target is exported via
  716. :command:`install(EXPORT)`, or when evaluated in the
  717. :prop_tgt:`INSTALL_NAME_DIR` property or the ``INSTALL_NAME_DIR`` argument of
  718. :command:`install(RUNTIME_DEPENDENCY_SET)`, and empty otherwise.
  719. Output-Related Expressions
  720. --------------------------
  721. .. genex:: $<TARGET_NAME:...>
  722. Marks ``...`` as being the name of a target. This is required if exporting
  723. targets to multiple dependent export sets. The ``...`` must be a literal
  724. name of a target- it may not contain generator expressions.
  725. .. genex:: $<LINK_ONLY:...>
  726. .. versionadded:: 3.1
  727. Content of ``...`` except when evaluated in a link interface while
  728. propagating :ref:`Target Usage Requirements`, in which case it is the
  729. empty string.
  730. Intended for use only in an :prop_tgt:`INTERFACE_LINK_LIBRARIES` target
  731. property, perhaps via the :command:`target_link_libraries` command,
  732. to specify private link dependencies without other usage requirements.
  733. .. genex:: $<LINK_LIBRARY:feature,library-list>
  734. .. versionadded:: 3.24
  735. Manage how libraries are specified during the link step.
  736. This expression may be used to specify how to link libraries in a target.
  737. For example:
  738. .. code-block:: cmake
  739. add_library(lib1 STATIC ...)
  740. add_library(lib2 ...)
  741. target_link_libraries(lib2 PRIVATE $<LINK_LIBRARY:whole_archive,lib1>)
  742. This specify to use the ``lib1`` target with feature ``whole_archive`` for
  743. linking target ``lib2``. The feature must have be defined by
  744. :variable:`CMAKE_<LANG>_LINK_USING_<FEATURE>` variable or, if
  745. :variable:`CMAKE_<LANG>_LINK_USING_<FEATURE>_SUPPORTED` is false,
  746. by :variable:`CMAKE_LINK_USING_<FEATURE>` variable.
  747. .. note::
  748. The evaluation of this generator expression will use, for the following
  749. variables, the values defined at the level of the creation of the target:
  750. * :variable:`CMAKE_<LANG>_LINK_USING_<FEATURE>_SUPPORTED`
  751. * :variable:`CMAKE_<LANG>_LINK_USING_<FEATURE>`
  752. * :variable:`CMAKE_LINK_USING_<FEATURE>_SUPPORTED`
  753. * :variable:`CMAKE_LINK_USING_<FEATURE>`
  754. This expression can only be used to specify link libraries (i.e. part of
  755. :command:`link_libraries` or :command:`target_link_libraries` commands and
  756. :prop_tgt:`LINK_LIBRARIES` or :prop_tgt:`INTERFACE_LINK_LIBRARIES` target
  757. properties).
  758. .. note::
  759. If this expression appears in the :prop_tgt:`INTERFACE_LINK_LIBRARIES`
  760. property of a target, it will be included in the imported target generated
  761. by :command:`install(EXPORT)` command. It is the responsibility of the
  762. environment consuming this import to define the link feature used by this
  763. expression.
  764. The ``library-list`` argument can hold CMake targets or external libraries.
  765. Any ``CMake`` target of type :ref:`OBJECT <Object Libraries>` or
  766. :ref:`INTERFACE <Interface Libraries>` will be ignored by this expression and
  767. will be handled in the standard way.
  768. Each target or external library involved in the link step must have only one
  769. kind of feature (the absence of feature is also incompatible with any
  770. feature). For example:
  771. .. code-block:: cmake
  772. add_library(lib1 ...)
  773. add_library(lib2 ...)
  774. target_link_libraries(lib2 PUBLIC $<LINK_LIBRARY:feature1,lib1>)
  775. add_library(lib3 ...)
  776. target_link_libraries(lib3 PRIVATE lib1 lib2)
  777. # an error will be raised here because lib1 has two different features
  778. .. note::
  779. This expression does not guarantee that the list of specified libraries
  780. will be kept grouped. So, constructs like ``start-group`` and
  781. ``end-group``, as supported by ``GNU ld``, cannot be used.
  782. .. genex:: $<INSTALL_INTERFACE:...>
  783. Content of ``...`` when the property is exported using :command:`install(EXPORT)`,
  784. and empty otherwise.
  785. .. genex:: $<BUILD_INTERFACE:...>
  786. Content of ``...`` when the property is exported using :command:`export`, or
  787. when the target is used by another target in the same buildsystem. Expands to
  788. the empty string otherwise.
  789. .. genex:: $<MAKE_C_IDENTIFIER:...>
  790. Content of ``...`` converted to a C identifier. The conversion follows the
  791. same behavior as :command:`string(MAKE_C_IDENTIFIER)`.
  792. .. genex:: $<TARGET_OBJECTS:objLib>
  793. .. versionadded:: 3.1
  794. List of objects resulting from build of ``objLib``.
  795. .. genex:: $<SHELL_PATH:...>
  796. .. versionadded:: 3.4
  797. Content of ``...`` converted to shell path style. For example, slashes are
  798. converted to backslashes in Windows shells and drive letters are converted
  799. to posix paths in MSYS shells. The ``...`` must be an absolute path.
  800. .. versionadded:: 3.14
  801. The ``...`` may be a :ref:`semicolon-separated list <CMake Language Lists>`
  802. of paths, in which case each path is converted individually and a result
  803. list is generated using the shell path separator (``:`` on POSIX and
  804. ``;`` on Windows). Be sure to enclose the argument containing this genex
  805. in double quotes in CMake source code so that ``;`` does not split arguments.
  806. .. genex:: $<OUTPUT_CONFIG:...>
  807. .. versionadded:: 3.20
  808. Only valid in :command:`add_custom_command` and :command:`add_custom_target`
  809. as the outer-most generator expression in an argument.
  810. With the :generator:`Ninja Multi-Config` generator, generator expressions
  811. in ``...`` are evaluated using the custom command's "output config".
  812. With other generators, the content of ``...`` is evaluated normally.
  813. .. genex:: $<COMMAND_CONFIG:...>
  814. .. versionadded:: 3.20
  815. Only valid in :command:`add_custom_command` and :command:`add_custom_target`
  816. as the outer-most generator expression in an argument.
  817. With the :generator:`Ninja Multi-Config` generator, generator expressions
  818. in ``...`` are evaluated using the custom command's "command config".
  819. With other generators, the content of ``...`` is evaluated normally.
  820. Debugging
  821. =========
  822. Since generator expressions are evaluated during generation of the buildsystem,
  823. and not during processing of ``CMakeLists.txt`` files, it is not possible to
  824. inspect their result with the :command:`message()` command.
  825. One possible way to generate debug messages is to add a custom target,
  826. .. code-block:: cmake
  827. add_custom_target(genexdebug COMMAND ${CMAKE_COMMAND} -E echo "$<...>")
  828. The shell command ``make genexdebug`` (invoked after execution of ``cmake``)
  829. would then print the result of ``$<...>``.
  830. Another way is to write debug messages to a file:
  831. .. code-block:: cmake
  832. file(GENERATE OUTPUT filename CONTENT "$<...>")