cmake-generator-expressions.7.rst 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392
  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. They have the form
  10. ``$<...>``. For example:
  11. .. code-block:: cmake
  12. target_include_directories(tgt PRIVATE /opt/include/$<CXX_COMPILER_ID>)
  13. This would expand to ``/opt/include/GNU``, ``/opt/include/Clang``, etc.
  14. depending on the C++ compiler used.
  15. Generator expressions are allowed in the context of many target properties,
  16. such as :prop_tgt:`LINK_LIBRARIES`, :prop_tgt:`INCLUDE_DIRECTORIES`,
  17. :prop_tgt:`COMPILE_DEFINITIONS` and others. They may also be used when using
  18. commands to populate those properties, such as :command:`target_link_libraries`,
  19. :command:`target_include_directories`, :command:`target_compile_definitions`
  20. and others. They enable conditional linking, conditional definitions used when
  21. compiling, conditional include directories, and more. The conditions may be
  22. based on the build configuration, target properties, platform information,
  23. or any other queryable information.
  24. Generator expressions can be nested:
  25. .. code-block:: cmake
  26. target_compile_definitions(tgt PRIVATE
  27. $<$<VERSION_LESS:$<CXX_COMPILER_VERSION>,4.2.0>:OLD_COMPILER>
  28. )
  29. The above would expand to ``OLD_COMPILER`` if the
  30. :variable:`CMAKE_CXX_COMPILER_VERSION <CMAKE_<LANG>_COMPILER_VERSION>` is less
  31. than 4.2.0.
  32. Whitespace And Quoting
  33. ======================
  34. Generator expressions are typically parsed after command arguments.
  35. If a generator expression contains spaces, new lines, semicolons or
  36. other characters that may be interpreted as command argument separators,
  37. the whole expression should be surrounded by quotes when passed to a
  38. command. Failure to do so may result in the expression being split and
  39. it may no longer be recognized as a generator expression.
  40. When using :command:`add_custom_command` or :command:`add_custom_target`,
  41. use the ``VERBATIM`` and ``COMMAND_EXPAND_LISTS`` options to obtain robust
  42. argument splitting and quoting.
  43. .. code-block:: cmake
  44. # WRONG: Embedded space will be treated as an argument separator.
  45. # This ends up not being seen as a generator expression at all.
  46. add_custom_target(run_some_tool
  47. COMMAND some_tool -I$<JOIN:$<TARGET_PROPERTY:tgt,INCLUDE_DIRECTORIES>, -I>
  48. VERBATIM
  49. )
  50. .. code-block:: cmake
  51. # Better, but still not robust. Quotes prevent the space from splitting the
  52. # expression. However, the tool will receive the expanded value as a single
  53. # argument.
  54. add_custom_target(run_some_tool
  55. COMMAND some_tool "-I$<JOIN:$<TARGET_PROPERTY:tgt,INCLUDE_DIRECTORIES>, -I>"
  56. VERBATIM
  57. )
  58. .. code-block:: cmake
  59. # Nearly correct. Using a semicolon to separate arguments and adding the
  60. # COMMAND_EXPAND_LISTS option means that paths with spaces will be handled
  61. # correctly. Quoting the whole expression ensures it is seen as a generator
  62. # expression. But if the target property is empty, we will get a bare -I
  63. # with nothing after it.
  64. add_custom_target(run_some_tool
  65. COMMAND some_tool "-I$<JOIN:$<TARGET_PROPERTY:tgt,INCLUDE_DIRECTORIES>,;-I>"
  66. COMMAND_EXPAND_LISTS
  67. VERBATIM
  68. )
  69. Using variables to build up a more complex generator expression is also a
  70. good way to reduce errors and improve readability. The above example can be
  71. improved further like so:
  72. .. code-block:: cmake
  73. # The $<BOOL:...> check prevents adding anything if the property is empty,
  74. # assuming the property value cannot be one of CMake's false constants.
  75. set(prop "$<TARGET_PROPERTY:tgt,INCLUDE_DIRECTORIES>")
  76. add_custom_target(run_some_tool
  77. COMMAND some_tool "$<$<BOOL:${prop}>:-I$<JOIN:${prop},;-I>>"
  78. COMMAND_EXPAND_LISTS
  79. VERBATIM
  80. )
  81. Finally, the above example can be expressed in a more simple and robust way
  82. using an alternate generator expression:
  83. .. code-block:: cmake
  84. add_custom_target(run_some_tool
  85. COMMAND some_tool "$<LIST:TRANSFORM,$<TARGET_PROPERTY:tgt,INCLUDE_DIRECTORIES>,PREPEND,-I>"
  86. COMMAND_EXPAND_LISTS
  87. VERBATIM
  88. )
  89. A common mistake is to try to split a generator expression across multiple
  90. lines with indenting:
  91. .. code-block:: cmake
  92. # WRONG: New lines and spaces all treated as argument separators, so the
  93. # generator expression is split and not recognized correctly.
  94. target_compile_definitions(tgt PRIVATE
  95. $<$<AND:
  96. $<CXX_COMPILER_ID:GNU>,
  97. $<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,5>
  98. >:HAVE_5_OR_LATER>
  99. )
  100. Again, use helper variables with well-chosen names to build up a readable
  101. expression instead:
  102. .. code-block:: cmake
  103. set(is_gnu "$<CXX_COMPILER_ID:GNU>")
  104. set(v5_or_later "$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,5>")
  105. set(meet_requirements "$<AND:${is_gnu},${v5_or_later}>")
  106. target_compile_definitions(tgt PRIVATE
  107. "$<${meet_requirements}:HAVE_5_OR_LATER>"
  108. )
  109. Debugging
  110. =========
  111. Since generator expressions are evaluated during generation of the buildsystem,
  112. and not during processing of ``CMakeLists.txt`` files, it is not possible to
  113. inspect their result with the :command:`message()` command. One possible way
  114. to generate debug messages is to add a custom target:
  115. .. code-block:: cmake
  116. add_custom_target(genexdebug COMMAND ${CMAKE_COMMAND} -E echo "$<...>")
  117. After running :program:`cmake`, you can then build the ``genexdebug`` target to print
  118. the result of the ``$<...>`` expression (i.e. run the command
  119. :option:`cmake --build ... --target genexdebug <cmake--build --target>`).
  120. Another way is to write debug messages to a file with :command:`file(GENERATE)`:
  121. .. code-block:: cmake
  122. file(GENERATE OUTPUT filename CONTENT "$<...>")
  123. Generator Expression Reference
  124. ==============================
  125. .. note::
  126. This reference deviates from most of the CMake documentation in that it
  127. omits angular brackets ``<...>`` around placeholders like ``condition``,
  128. ``string``, ``target``, etc. This is to prevent an opportunity for those
  129. placeholders to be misinterpreted as generator expressions.
  130. .. _`Conditional Generator Expressions`:
  131. Conditional Expressions
  132. -----------------------
  133. A fundamental category of generator expressions relates to conditional logic.
  134. Two forms of conditional generator expressions are supported:
  135. .. genex:: $<condition:true_string>
  136. Evaluates to ``true_string`` if ``condition`` is ``1``, or an empty string
  137. if ``condition`` evaluates to ``0``. Any other value for ``condition``
  138. results in an error.
  139. .. genex:: $<IF:condition,true_string,false_string>
  140. .. versionadded:: 3.8
  141. Evaluates to ``true_string`` if ``condition`` is ``1``, or ``false_string``
  142. if ``condition`` is ``0``. Any other value for ``condition`` results in an
  143. error.
  144. Typically, the ``condition`` is itself a generator expression. For instance,
  145. the following expression expands to ``DEBUG_MODE`` when the ``Debug``
  146. configuration is used, and the empty string for all other configurations:
  147. .. code-block:: cmake
  148. $<$<CONFIG:Debug>:DEBUG_MODE>
  149. Boolean-like ``condition`` values other than ``1`` or ``0`` can be handled
  150. by wrapping them with the ``$<BOOL:...>`` generator expression:
  151. .. genex:: $<BOOL:string>
  152. Converts ``string`` to ``0`` or ``1``. Evaluates to ``0`` if any of the
  153. following is true:
  154. * ``string`` is empty,
  155. * ``string`` is a case-insensitive equal of
  156. ``0``, ``FALSE``, ``OFF``, ``N``, ``NO``, ``IGNORE``, or ``NOTFOUND``, or
  157. * ``string`` ends in the suffix ``-NOTFOUND`` (case-sensitive).
  158. Otherwise evaluates to ``1``.
  159. The ``$<BOOL:...>`` generator expression is often used when a ``condition``
  160. is provided by a CMake variable:
  161. .. code-block:: cmake
  162. $<$<BOOL:${HAVE_SOME_FEATURE}>:-DENABLE_SOME_FEATURE>
  163. .. _`Boolean Generator Expressions`:
  164. Logical Operators
  165. -----------------
  166. The common boolean logic operators are supported:
  167. .. genex:: $<AND:conditions>
  168. where ``conditions`` is a comma-separated list of boolean expressions,
  169. all of which must evaluate to either ``1`` or ``0``. The whole expression
  170. evaluates to ``1`` if all conditions are ``1``. If any condition is ``0``,
  171. the whole expression evaluates to ``0``.
  172. .. genex:: $<OR:conditions>
  173. where ``conditions`` is a comma-separated list of boolean expressions.
  174. all of which must evaluate to either ``1`` or ``0``. The whole expression
  175. evaluates to ``1`` if at least one of the ``conditions`` is ``1``. If all
  176. ``conditions`` evaluate to ``0``, the whole expression evaluates to ``0``.
  177. .. genex:: $<NOT:condition>
  178. ``condition`` must be ``0`` or ``1``. The result of the expression is
  179. ``0`` if ``condition`` is ``1``, else ``1``.
  180. .. _`Comparison Expressions`:
  181. Primary Comparison Expressions
  182. ------------------------------
  183. CMake supports a variety of generator expressions that compare things.
  184. This section covers the primary and most widely used comparison types.
  185. Other more specific comparison types are documented in their own separate
  186. sections further below.
  187. String Comparisons
  188. ^^^^^^^^^^^^^^^^^^
  189. .. genex:: $<STREQUAL:string1,string2>
  190. ``1`` if ``string1`` and ``string2`` are equal, else ``0``.
  191. The comparison is case-sensitive. For a case-insensitive comparison,
  192. combine with a :ref:`string transforming generator expression
  193. <String Transforming Generator Expressions>`. For example, the following
  194. evaluates to ``1`` if ``${foo}`` is any of ``BAR``, ``Bar``, ``bar``, etc.
  195. .. code-block:: cmake
  196. $<STREQUAL:$<UPPER_CASE:${foo}>,BAR>
  197. .. genex:: $<EQUAL:value1,value2>
  198. ``1`` if ``value1`` and ``value2`` are numerically equal, else ``0``.
  199. Version Comparisons
  200. ^^^^^^^^^^^^^^^^^^^
  201. .. genex:: $<VERSION_LESS:v1,v2>
  202. ``1`` if ``v1`` is a version less than ``v2``, else ``0``.
  203. .. genex:: $<VERSION_GREATER:v1,v2>
  204. ``1`` if ``v1`` is a version greater than ``v2``, else ``0``.
  205. .. genex:: $<VERSION_EQUAL:v1,v2>
  206. ``1`` if ``v1`` is the same version as ``v2``, else ``0``.
  207. .. genex:: $<VERSION_LESS_EQUAL:v1,v2>
  208. .. versionadded:: 3.7
  209. ``1`` if ``v1`` is a version less than or equal to ``v2``, else ``0``.
  210. .. genex:: $<VERSION_GREATER_EQUAL:v1,v2>
  211. .. versionadded:: 3.7
  212. ``1`` if ``v1`` is a version greater than or equal to ``v2``, else ``0``.
  213. .. _`String Transforming Generator Expressions`:
  214. String Transformations
  215. ----------------------
  216. .. genex:: $<LOWER_CASE:string>
  217. Content of ``string`` converted to lower case.
  218. .. genex:: $<UPPER_CASE:string>
  219. Content of ``string`` converted to upper case.
  220. .. genex:: $<MAKE_C_IDENTIFIER:...>
  221. Content of ``...`` converted to a C identifier. The conversion follows the
  222. same behavior as :command:`string(MAKE_C_IDENTIFIER)`.
  223. List Expressions
  224. ----------------
  225. Most of the expressions in this section are closely associated with the
  226. :command:`list` command, providing the same capabilities, but in
  227. the form of a generator expression.
  228. In each of the following list-related generator expressions, the ``list``
  229. must not contain any commas if that generator expression expects something to
  230. be provided after the ``list``. For example, the expression
  231. ``$<LIST:FIND,list,value>`` requires a ``value`` after the ``list``.
  232. Since a comma is used to separate the ``list`` and the ``value``, the ``list``
  233. cannot itself contain a comma. This restriction does not apply to the
  234. :command:`list` command, it is specific to the list-handling generator
  235. expressions only.
  236. .. _GenEx List Comparisons:
  237. List Comparisons
  238. ^^^^^^^^^^^^^^^^
  239. .. genex:: $<IN_LIST:string,list>
  240. .. versionadded:: 3.12
  241. ``1`` if ``string`` is an item in the semicolon-separated ``list``, else ``0``.
  242. It uses case-sensitive comparisons.
  243. .. _GenEx List Queries:
  244. List Queries
  245. ^^^^^^^^^^^^
  246. .. genex:: $<LIST:LENGTH,list>
  247. .. versionadded:: 3.27
  248. The number of items in the ``list``.
  249. .. genex:: $<LIST:GET,list,index,...>
  250. .. versionadded:: 3.27
  251. Expands to the list of items specified by indices from the ``list``.
  252. .. genex:: $<LIST:SUBLIST,list,begin,length>
  253. .. versionadded:: 3.27
  254. A sublist of the given ``list``. If ``length`` is 0, an empty list
  255. will be returned. If ``length`` is -1 or the list is smaller than
  256. ``begin + length``, the remaining items of the list starting at
  257. ``begin`` will be returned.
  258. .. genex:: $<LIST:FIND,list,value>
  259. .. versionadded:: 3.27
  260. The index of the first item in ``list`` with the specified ``value``,
  261. or -1 if ``value`` is not in the ``list``.
  262. .. _GenEx List Transformations:
  263. List Transformations
  264. ^^^^^^^^^^^^^^^^^^^^
  265. .. _GenEx LIST-JOIN:
  266. .. genex:: $<LIST:JOIN,list,glue>
  267. .. versionadded:: 3.27
  268. Converts ``list`` to a single string with the content of the ``glue`` string
  269. inserted between each item. This is conceptually the same operation as
  270. :genex:`$<JOIN:list,glue>`, but the two have different behavior with regard
  271. to empty items. ``$<LIST:JOIN,list,glue>`` preserves all empty items,
  272. whereas :genex:`$<JOIN:list,glue>` drops all empty items from the list.
  273. .. genex:: $<LIST:APPEND,list,item,...>
  274. .. versionadded:: 3.27
  275. The ``list`` with each ``item`` appended. Multiple items should be
  276. separated by commas.
  277. .. genex:: $<LIST:PREPEND,list,item,...>
  278. .. versionadded:: 3.27
  279. The ``list`` with each ``item`` inserted at the beginning. If there are
  280. multiple items, they should be separated by commas, and the order of the
  281. prepended items will be preserved.
  282. .. genex:: $<LIST:INSERT,list,index,item,...>
  283. .. versionadded:: 3.27
  284. The ``list`` with the ``item`` (or multiple items) inserted at the specified
  285. ``index``. Multiple items should be separated by commas.
  286. It is an error to specify an out-of-range ``index``. Valid indexes are 0 to N,
  287. where N is the length of the list, inclusive. An empty list has length 0.
  288. .. genex:: $<LIST:POP_BACK,list>
  289. .. versionadded:: 3.27
  290. The ``list`` with the last item removed.
  291. .. genex:: $<LIST:POP_FRONT,list>
  292. .. versionadded:: 3.27
  293. The ``list`` with the first item removed.
  294. .. genex:: $<LIST:REMOVE_ITEM,list,value,...>
  295. .. versionadded:: 3.27
  296. The ``list`` with all instances of the given ``value`` (or values) removed.
  297. If multiple values are given, they should be separated by commas.
  298. .. genex:: $<LIST:REMOVE_AT,list,index,...>
  299. .. versionadded:: 3.27
  300. The ``list`` with the item at each given ``index`` removed.
  301. .. _GenEx LIST-REMOVE_DUPLICATES:
  302. .. genex:: $<LIST:REMOVE_DUPLICATES,list>
  303. .. versionadded:: 3.27
  304. The ``list`` with all duplicated items removed. The relative order of
  305. items is preserved, but if duplicates are encountered, only the first
  306. instance is preserved. The result is the same as
  307. :genex:`$<REMOVE_DUPLICATES:list>`.
  308. .. _GenEx LIST-FILTER:
  309. .. genex:: $<LIST:FILTER,list,INCLUDE|EXCLUDE,regex>
  310. .. versionadded:: 3.27
  311. A list of items from the ``list`` which match (``INCLUDE``) or do not match
  312. (``EXCLUDE``) the regular expression ``regex``. The result is the same as
  313. :genex:`$<FILTER:list,INCLUDE|EXCLUDE,regex>`.
  314. .. genex:: $<LIST:TRANSFORM,list,ACTION[,SELECTOR]>
  315. .. versionadded:: 3.27
  316. The ``list`` transformed by applying an ``ACTION`` to all or, by
  317. specifying a ``SELECTOR``, to the selected list items.
  318. .. note::
  319. The ``TRANSFORM`` sub-command does not change the number of items in the
  320. list. If a ``SELECTOR`` is specified, only some items will be changed,
  321. the other ones will remain the same as before the transformation.
  322. ``ACTION`` specifies the action to apply to the items of the list.
  323. The actions have exactly the same semantics as for the
  324. :command:`list(TRANSFORM)` command. ``ACTION`` must be one of the following:
  325. :command:`APPEND <list(TRANSFORM_APPEND)>`, :command:`PREPEND <list(TRANSFORM_APPEND)>`
  326. Append, prepend specified value to each item of the list.
  327. .. code-block:: cmake
  328. $<LIST:TRANSFORM,list,(APPEND|PREPEND),value[,SELECTOR]>
  329. :command:`TOLOWER <list(TRANSFORM_TOLOWER)>`, :command:`TOUPPER <list(TRANSFORM_TOLOWER)>`
  330. Convert each item of the list to lower, upper characters.
  331. .. code-block:: cmake
  332. $<LIST:TRANSFORM,list,(TOLOWER|TOUPPER)[,SELECTOR]>
  333. :command:`STRIP <list(TRANSFORM_STRIP)>`
  334. Remove leading and trailing spaces from each item of the list.
  335. .. code-block:: cmake
  336. $<LIST:TRANSFORM,list,STRIP[,SELECTOR]>
  337. :command:`REPLACE <list(TRANSFORM_REPLACE)>`:
  338. Match the regular expression as many times as possible and substitute
  339. the replacement expression for the match for each item of the list.
  340. .. code-block:: cmake
  341. $<LIST:TRANSFORM,list,REPLACE,regular_expression,replace_expression[,SELECTOR]>
  342. ``SELECTOR`` determines which items of the list will be transformed.
  343. Only one type of selector can be specified at a time. When given,
  344. ``SELECTOR`` must be one of the following:
  345. ``AT``
  346. Specify a list of indexes.
  347. .. code-block:: cmake
  348. $<LIST:TRANSFORM,list,ACTION,AT,index[,index...]>
  349. ``FOR``
  350. Specify a range with, optionally, an increment used to iterate over the
  351. range.
  352. .. code-block:: cmake
  353. $<LIST:TRANSFORM,list,ACTION,FOR,start,stop[,step]>
  354. ``REGEX``
  355. Specify a regular expression.
  356. Only items matching the regular expression will be transformed.
  357. .. code-block:: cmake
  358. $<LIST:TRANSFORM,list,ACTION,REGEX,regular_expression>
  359. .. genex:: $<JOIN:list,glue>
  360. Joins the ``list`` with the content of the ``glue`` string inserted between
  361. each item. This is conceptually the same operation as
  362. :ref:`$\<LIST:JOIN,list,glue\> <GenEx LIST-JOIN>`, but the two have
  363. different behavior with regard to empty items.
  364. :ref:`$\<LIST:JOIN,list,glue\> <GenEx LIST-JOIN>` preserves all empty items,
  365. whereas ``$<JOIN,list,glue>`` drops all empty items from the list.
  366. .. genex:: $<REMOVE_DUPLICATES:list>
  367. .. versionadded:: 3.15
  368. Removes duplicated items in the given ``list``. The relative order of items
  369. is preserved, and if duplicates are encountered, only the first instance is
  370. retained. The result is the same as
  371. :ref:`$\<LIST:REMOVE_DUPLICATES,list\> <GenEx LIST-REMOVE_DUPLICATES>`.
  372. .. genex:: $<FILTER:list,INCLUDE|EXCLUDE,regex>
  373. .. versionadded:: 3.15
  374. Includes or removes items from ``list`` that match the regular expression
  375. ``regex``. The result is the same as
  376. :ref:`$\<LIST:FILTER,list,INCLUDE|EXCLUDE,regex\> <GenEx LIST-FILTER>`.
  377. .. _GenEx List Ordering:
  378. List Ordering
  379. ^^^^^^^^^^^^^
  380. .. genex:: $<LIST:REVERSE,list>
  381. .. versionadded:: 3.27
  382. The ``list`` with the items in reverse order.
  383. .. genex:: $<LIST:SORT,list[,(COMPARE:option|CASE:option|ORDER:option)]...>
  384. .. versionadded:: 3.27
  385. The ``list`` sorted according to the specified options.
  386. Use one of the ``COMPARE`` options to select the comparison method
  387. for sorting:
  388. ``STRING``
  389. Sorts a list of strings alphabetically.
  390. This is the default behavior if the ``COMPARE`` option is not given.
  391. ``FILE_BASENAME``
  392. Sorts a list of file paths by their basenames.
  393. ``NATURAL``
  394. Sorts a list of strings using natural order (see the man page for
  395. ``strverscmp(3)``), such that contiguous digits are compared as whole
  396. numbers. For example, the following list ``10.0 1.1 2.1 8.0 2.0 3.1``
  397. will be sorted as ``1.1 2.0 2.1 3.1 8.0 10.0`` if the ``NATURAL``
  398. comparison is selected, whereas it will be sorted as
  399. ``1.1 10.0 2.0 2.1 3.1 8.0`` with the ``STRING`` comparison.
  400. Use one of the ``CASE`` options to select a case-sensitive or
  401. case-insensitive sort mode:
  402. ``SENSITIVE``
  403. List items are sorted in a case-sensitive manner.
  404. This is the default behavior if the ``CASE`` option is not given.
  405. ``INSENSITIVE``
  406. List items are sorted in a case-insensitive manner. The order of
  407. items which differ only by upper/lowercase is not specified.
  408. To control the sort order, one of the ``ORDER`` options can be given:
  409. ``ASCENDING``
  410. Sorts the list in ascending order.
  411. This is the default behavior when the ``ORDER`` option is not given.
  412. ``DESCENDING``
  413. Sorts the list in descending order.
  414. Options can be specified in any order, but it is an error to specify the
  415. same option multiple times.
  416. .. code-block:: cmake
  417. $<LIST:SORT,list,CASE:SENSITIVE,COMPARE:STRING,ORDER:DESCENDING>
  418. Path Expressions
  419. ----------------
  420. Most of the expressions in this section are closely associated with the
  421. :command:`cmake_path` command, providing the same capabilities, but in
  422. the form of a generator expression.
  423. For all generator expressions in this section, paths are expected to be in
  424. cmake-style format. The :ref:`$\<PATH:CMAKE_PATH\> <GenEx PATH-CMAKE_PATH>`
  425. generator expression can be used to convert a native path to a cmake-style
  426. one.
  427. .. _GenEx Path Comparisons:
  428. Path Comparisons
  429. ^^^^^^^^^^^^^^^^
  430. .. genex:: $<PATH_EQUAL:path1,path2>
  431. .. versionadded:: 3.24
  432. Compares the lexical representations of two paths. No normalization is
  433. performed on either path. Returns ``1`` if the paths are equal, ``0``
  434. otherwise.
  435. See :ref:`cmake_path(COMPARE) <Path COMPARE>` for more details.
  436. .. _GenEx Path Queries:
  437. Path Queries
  438. ^^^^^^^^^^^^
  439. These expressions provide the generation-time capabilities equivalent to the
  440. :ref:`Query <Path Query>` options of the :command:`cmake_path` command.
  441. All paths are expected to be in cmake-style format.
  442. .. genex:: $<PATH:HAS_*,path>
  443. .. versionadded:: 3.24
  444. The following operations return ``1`` if the particular path component is
  445. present, ``0`` otherwise. See :ref:`Path Structure And Terminology` for the
  446. meaning of each path component.
  447. ::
  448. $<PATH:HAS_ROOT_NAME,path>
  449. $<PATH:HAS_ROOT_DIRECTORY,path>
  450. $<PATH:HAS_ROOT_PATH,path>
  451. $<PATH:HAS_FILENAME,path>
  452. $<PATH:HAS_EXTENSION,path>
  453. $<PATH:HAS_STEM,path>
  454. $<PATH:HAS_RELATIVE_PART,path>
  455. $<PATH:HAS_PARENT_PATH,path>
  456. Note the following special cases:
  457. * For ``HAS_ROOT_PATH``, a true result will only be returned if at least one
  458. of ``root-name`` or ``root-directory`` is non-empty.
  459. * For ``HAS_PARENT_PATH``, the root directory is also considered to have a
  460. parent, which will be itself. The result is true except if the path
  461. consists of just a :ref:`filename <FILENAME_DEF>`.
  462. .. genex:: $<PATH:IS_ABSOLUTE,path>
  463. .. versionadded:: 3.24
  464. Returns ``1`` if the path is :ref:`absolute <IS_ABSOLUTE>`, ``0`` otherwise.
  465. .. genex:: $<PATH:IS_RELATIVE,path>
  466. .. versionadded:: 3.24
  467. This will return the opposite of ``IS_ABSOLUTE``.
  468. .. genex:: $<PATH:IS_PREFIX[,NORMALIZE],path,input>
  469. .. versionadded:: 3.24
  470. Returns ``1`` if ``path`` is the prefix of ``input``, ``0`` otherwise.
  471. When the ``NORMALIZE`` option is specified, ``path`` and ``input`` are
  472. :ref:`normalized <Normalization>` before the check.
  473. .. _GenEx Path Decomposition:
  474. Path Decomposition
  475. ^^^^^^^^^^^^^^^^^^
  476. These expressions provide the generation-time capabilities equivalent to the
  477. :ref:`Decomposition <Path Decomposition>` options of the :command:`cmake_path`
  478. command. All paths are expected to be in cmake-style format.
  479. .. genex:: $<PATH:GET_*,...>
  480. .. versionadded:: 3.24
  481. The following operations retrieve a different component or group of
  482. components from a path. See :ref:`Path Structure And Terminology` for the
  483. meaning of each path component.
  484. .. versionchanged:: 3.27
  485. All operations now accept a list of paths as argument. When a list of paths
  486. is specified, the operation will be applied to each path.
  487. ::
  488. $<PATH:GET_ROOT_NAME,path...>
  489. $<PATH:GET_ROOT_DIRECTORY,path...>
  490. $<PATH:GET_ROOT_PATH,path...>
  491. $<PATH:GET_FILENAME,path...>
  492. $<PATH:GET_EXTENSION[,LAST_ONLY],path...>
  493. $<PATH:GET_STEM[,LAST_ONLY],path...>
  494. $<PATH:GET_RELATIVE_PART,path...>
  495. $<PATH:GET_PARENT_PATH,path...>
  496. If a requested component is not present in the path, an empty string is
  497. returned.
  498. .. _GenEx Path Transformations:
  499. Path Transformations
  500. ^^^^^^^^^^^^^^^^^^^^
  501. These expressions provide the generation-time capabilities equivalent to the
  502. :ref:`Modification <Path Modification>` and :ref:`Generation <Path Generation>`
  503. options of the :command:`cmake_path` command. All paths are expected to be
  504. in cmake-style format.
  505. .. versionchanged:: 3.27
  506. All operations now accept a list of paths as argument. When a list of paths
  507. is specified, the operation will be applied to each path.
  508. .. _GenEx PATH-CMAKE_PATH:
  509. .. genex:: $<PATH:CMAKE_PATH[,NORMALIZE],path...>
  510. .. versionadded:: 3.24
  511. Returns ``path``. If ``path`` is a native path, it is converted into a
  512. cmake-style path with forward-slashes (``/``). On Windows, the long filename
  513. marker is taken into account.
  514. When the ``NORMALIZE`` option is specified, the path is :ref:`normalized
  515. <Normalization>` after the conversion.
  516. .. genex:: $<PATH:APPEND,path...,input,...>
  517. .. versionadded:: 3.24
  518. Returns all the ``input`` arguments appended to ``path`` using ``/`` as the
  519. ``directory-separator``. Depending on the ``input``, the value of ``path``
  520. may be discarded.
  521. See :ref:`cmake_path(APPEND) <APPEND>` for more details.
  522. .. genex:: $<PATH:REMOVE_FILENAME,path...>
  523. .. versionadded:: 3.24
  524. Returns ``path`` with filename component (as returned by
  525. ``$<PATH:GET_FILENAME>``) removed. After removal, any trailing
  526. ``directory-separator`` is left alone, if present.
  527. See :ref:`cmake_path(REMOVE_FILENAME) <REMOVE_FILENAME>` for more details.
  528. .. genex:: $<PATH:REPLACE_FILENAME,path...,input>
  529. .. versionadded:: 3.24
  530. Returns ``path`` with the filename component replaced by ``input``. If
  531. ``path`` has no filename component (i.e. ``$<PATH:HAS_FILENAME>`` returns
  532. ``0``), ``path`` is unchanged.
  533. See :ref:`cmake_path(REPLACE_FILENAME) <REPLACE_FILENAME>` for more details.
  534. .. genex:: $<PATH:REMOVE_EXTENSION[,LAST_ONLY],path...>
  535. .. versionadded:: 3.24
  536. Returns ``path`` with the :ref:`extension <EXTENSION_DEF>` removed, if any.
  537. See :ref:`cmake_path(REMOVE_EXTENSION) <REMOVE_EXTENSION>` for more details.
  538. .. genex:: $<PATH:REPLACE_EXTENSION[,LAST_ONLY],path...,input>
  539. .. versionadded:: 3.24
  540. Returns ``path`` with the :ref:`extension <EXTENSION_DEF>` replaced by
  541. ``input``, if any.
  542. See :ref:`cmake_path(REPLACE_EXTENSION) <REPLACE_EXTENSION>` for more details.
  543. .. genex:: $<PATH:NORMAL_PATH,path...>
  544. .. versionadded:: 3.24
  545. Returns ``path`` normalized according to the steps described in
  546. :ref:`Normalization`.
  547. .. genex:: $<PATH:RELATIVE_PATH,path...,base_directory>
  548. .. versionadded:: 3.24
  549. Returns ``path``, modified to make it relative to the ``base_directory``
  550. argument.
  551. See :ref:`cmake_path(RELATIVE_PATH) <cmake_path-RELATIVE_PATH>` for more
  552. details.
  553. .. genex:: $<PATH:ABSOLUTE_PATH[,NORMALIZE],path...,base_directory>
  554. .. versionadded:: 3.24
  555. Returns ``path`` as absolute. If ``path`` is a relative path
  556. (``$<PATH:IS_RELATIVE>`` returns ``1``), it is evaluated relative to the
  557. given base directory specified by ``base_directory`` argument.
  558. When the ``NORMALIZE`` option is specified, the path is
  559. :ref:`normalized <Normalization>` after the path computation.
  560. See :ref:`cmake_path(ABSOLUTE_PATH) <ABSOLUTE_PATH>` for more details.
  561. Shell Paths
  562. ^^^^^^^^^^^
  563. .. genex:: $<SHELL_PATH:...>
  564. .. versionadded:: 3.4
  565. Content of ``...`` converted to shell path style. For example, slashes are
  566. converted to backslashes in Windows shells and drive letters are converted
  567. to posix paths in MSYS shells. The ``...`` must be an absolute path.
  568. .. versionadded:: 3.14
  569. The ``...`` may be a :ref:`semicolon-separated list <CMake Language Lists>`
  570. of paths, in which case each path is converted individually and a result
  571. list is generated using the shell path separator (``:`` on POSIX and
  572. ``;`` on Windows). Be sure to enclose the argument containing this genex
  573. in double quotes in CMake source code so that ``;`` does not split arguments.
  574. Configuration Expressions
  575. -------------------------
  576. .. genex:: $<CONFIG>
  577. Configuration name. Use this instead of the deprecated :genex:`CONFIGURATION`
  578. generator expression.
  579. .. genex:: $<CONFIG:cfgs>
  580. ``1`` if config is any one of the entries in comma-separated list
  581. ``cfgs``, else ``0``. This is a case-insensitive comparison. The mapping in
  582. :prop_tgt:`MAP_IMPORTED_CONFIG_<CONFIG>` is also considered by this
  583. expression when it is evaluated on a property of an :prop_tgt:`IMPORTED`
  584. target.
  585. .. versionchanged:: 3.19
  586. Multiple configurations can be specified for ``cfgs``.
  587. CMake 3.18 and earlier only accepted a single configuration.
  588. .. genex:: $<OUTPUT_CONFIG:...>
  589. .. versionadded:: 3.20
  590. Only valid in :command:`add_custom_command` and :command:`add_custom_target`
  591. as the outer-most generator expression in an argument.
  592. With the :generator:`Ninja Multi-Config` generator, generator expressions
  593. in ``...`` are evaluated using the custom command's "output config".
  594. With other generators, the content of ``...`` is evaluated normally.
  595. .. genex:: $<COMMAND_CONFIG:...>
  596. .. versionadded:: 3.20
  597. Only valid in :command:`add_custom_command` and :command:`add_custom_target`
  598. as the outer-most generator expression in an argument.
  599. With the :generator:`Ninja Multi-Config` generator, generator expressions
  600. in ``...`` are evaluated using the custom command's "command config".
  601. With other generators, the content of ``...`` is evaluated normally.
  602. Toolchain And Language Expressions
  603. ----------------------------------
  604. Platform
  605. ^^^^^^^^
  606. .. genex:: $<PLATFORM_ID>
  607. The current system's CMake platform id.
  608. See also the :variable:`CMAKE_SYSTEM_NAME` variable.
  609. .. genex:: $<PLATFORM_ID:platform_ids>
  610. ``1`` if CMake's platform id matches any one of the entries in
  611. comma-separated list ``platform_ids``, otherwise ``0``.
  612. See also the :variable:`CMAKE_SYSTEM_NAME` variable.
  613. Compiler Version
  614. ^^^^^^^^^^^^^^^^
  615. See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable, which is
  616. closely related to the expressions in this sub-section.
  617. .. genex:: $<C_COMPILER_VERSION>
  618. The version of the C compiler used.
  619. .. genex:: $<C_COMPILER_VERSION:version>
  620. ``1`` if the version of the C compiler matches ``version``, otherwise ``0``.
  621. .. genex:: $<CXX_COMPILER_VERSION>
  622. The version of the CXX compiler used.
  623. .. genex:: $<CXX_COMPILER_VERSION:version>
  624. ``1`` if the version of the CXX compiler matches ``version``, otherwise ``0``.
  625. .. genex:: $<CUDA_COMPILER_VERSION>
  626. .. versionadded:: 3.15
  627. The version of the CUDA compiler used.
  628. .. genex:: $<CUDA_COMPILER_VERSION:version>
  629. .. versionadded:: 3.15
  630. ``1`` if the version of the CXX compiler matches ``version``, otherwise ``0``.
  631. .. genex:: $<OBJC_COMPILER_VERSION>
  632. .. versionadded:: 3.16
  633. The version of the OBJC compiler used.
  634. .. genex:: $<OBJC_COMPILER_VERSION:version>
  635. .. versionadded:: 3.16
  636. ``1`` if the version of the OBJC compiler matches ``version``, otherwise ``0``.
  637. .. genex:: $<OBJCXX_COMPILER_VERSION>
  638. .. versionadded:: 3.16
  639. The version of the OBJCXX compiler used.
  640. .. genex:: $<OBJCXX_COMPILER_VERSION:version>
  641. .. versionadded:: 3.16
  642. ``1`` if the version of the OBJCXX compiler matches ``version``, otherwise ``0``.
  643. .. genex:: $<Fortran_COMPILER_VERSION>
  644. The version of the Fortran compiler used.
  645. .. genex:: $<Fortran_COMPILER_VERSION:version>
  646. ``1`` if the version of the Fortran compiler matches ``version``, otherwise ``0``.
  647. .. genex:: $<HIP_COMPILER_VERSION>
  648. .. versionadded:: 3.21
  649. The version of the HIP compiler used.
  650. .. genex:: $<HIP_COMPILER_VERSION:version>
  651. .. versionadded:: 3.21
  652. ``1`` if the version of the HIP compiler matches ``version``, otherwise ``0``.
  653. .. genex:: $<ISPC_COMPILER_VERSION>
  654. .. versionadded:: 3.19
  655. The version of the ISPC compiler used.
  656. .. genex:: $<ISPC_COMPILER_VERSION:version>
  657. .. versionadded:: 3.19
  658. ``1`` if the version of the ISPC compiler matches ``version``, otherwise ``0``.
  659. Compiler Language And ID
  660. ^^^^^^^^^^^^^^^^^^^^^^^^
  661. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable, which is closely
  662. related to most of the expressions in this sub-section.
  663. .. genex:: $<C_COMPILER_ID>
  664. CMake's compiler id of the C compiler used.
  665. .. genex:: $<C_COMPILER_ID:compiler_ids>
  666. where ``compiler_ids`` is a comma-separated list.
  667. ``1`` if CMake's compiler id of the C compiler matches any one
  668. of the entries in ``compiler_ids``, otherwise ``0``.
  669. .. genex:: $<CXX_COMPILER_ID>
  670. CMake's compiler id of the CXX compiler used.
  671. .. genex:: $<CXX_COMPILER_ID:compiler_ids>
  672. where ``compiler_ids`` is a comma-separated list.
  673. ``1`` if CMake's compiler id of the CXX compiler matches any one
  674. of the entries in ``compiler_ids``, otherwise ``0``.
  675. .. genex:: $<CUDA_COMPILER_ID>
  676. .. versionadded:: 3.15
  677. CMake's compiler id of the CUDA compiler used.
  678. .. genex:: $<CUDA_COMPILER_ID:compiler_ids>
  679. .. versionadded:: 3.15
  680. where ``compiler_ids`` is a comma-separated list.
  681. ``1`` if CMake's compiler id of the CUDA compiler matches any one
  682. of the entries in ``compiler_ids``, otherwise ``0``.
  683. .. genex:: $<OBJC_COMPILER_ID>
  684. .. versionadded:: 3.16
  685. CMake's compiler id of the OBJC compiler used.
  686. .. genex:: $<OBJC_COMPILER_ID:compiler_ids>
  687. .. versionadded:: 3.16
  688. where ``compiler_ids`` is a comma-separated list.
  689. ``1`` if CMake's compiler id of the Objective-C compiler matches any one
  690. of the entries in ``compiler_ids``, otherwise ``0``.
  691. .. genex:: $<OBJCXX_COMPILER_ID>
  692. .. versionadded:: 3.16
  693. CMake's compiler id of the OBJCXX compiler used.
  694. .. genex:: $<OBJCXX_COMPILER_ID:compiler_ids>
  695. .. versionadded:: 3.16
  696. where ``compiler_ids`` is a comma-separated list.
  697. ``1`` if CMake's compiler id of the Objective-C++ compiler matches any one
  698. of the entries in ``compiler_ids``, otherwise ``0``.
  699. .. genex:: $<Fortran_COMPILER_ID>
  700. CMake's compiler id of the Fortran compiler used.
  701. .. genex:: $<Fortran_COMPILER_ID:compiler_ids>
  702. where ``compiler_ids`` is a comma-separated list.
  703. ``1`` if CMake's compiler id of the Fortran compiler matches any one
  704. of the entries in ``compiler_ids``, otherwise ``0``.
  705. .. genex:: $<HIP_COMPILER_ID>
  706. .. versionadded:: 3.21
  707. CMake's compiler id of the HIP compiler used.
  708. .. genex:: $<HIP_COMPILER_ID:compiler_ids>
  709. .. versionadded:: 3.21
  710. where ``compiler_ids`` is a comma-separated list.
  711. ``1`` if CMake's compiler id of the HIP compiler matches any one
  712. of the entries in ``compiler_ids``, otherwise ``0``.
  713. .. genex:: $<ISPC_COMPILER_ID>
  714. .. versionadded:: 3.19
  715. CMake's compiler id of the ISPC compiler used.
  716. .. genex:: $<ISPC_COMPILER_ID:compiler_ids>
  717. .. versionadded:: 3.19
  718. where ``compiler_ids`` is a comma-separated list.
  719. ``1`` if CMake's compiler id of the ISPC compiler matches any one
  720. of the entries in ``compiler_ids``, otherwise ``0``.
  721. .. genex:: $<COMPILE_LANGUAGE>
  722. .. versionadded:: 3.3
  723. The compile language of source files when evaluating compile options.
  724. See :ref:`the related boolean expression
  725. <Boolean COMPILE_LANGUAGE Generator Expression>`
  726. ``$<COMPILE_LANGUAGE:language>``
  727. for notes about the portability of this generator expression.
  728. .. _`Boolean COMPILE_LANGUAGE Generator Expression`:
  729. .. genex:: $<COMPILE_LANGUAGE:languages>
  730. .. versionadded:: 3.3
  731. .. versionchanged:: 3.15
  732. Multiple languages can be specified for ``languages``.
  733. CMake 3.14 and earlier only accepted a single language.
  734. ``1`` when the language used for compilation unit matches any of the
  735. comma-separated entries in ``languages``, otherwise ``0``. This expression
  736. may be used to specify compile options, compile definitions, and include
  737. directories for source files of a particular language in a target. For
  738. example:
  739. .. code-block:: cmake
  740. add_executable(myapp main.cpp foo.c bar.cpp zot.cu)
  741. target_compile_options(myapp
  742. PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
  743. )
  744. target_compile_definitions(myapp
  745. PRIVATE $<$<COMPILE_LANGUAGE:CXX>:COMPILING_CXX>
  746. $<$<COMPILE_LANGUAGE:CUDA>:COMPILING_CUDA>
  747. )
  748. target_include_directories(myapp
  749. PRIVATE $<$<COMPILE_LANGUAGE:CXX,CUDA>:/opt/foo/headers>
  750. )
  751. This specifies the use of the ``-fno-exceptions`` compile option,
  752. ``COMPILING_CXX`` compile definition, and ``cxx_headers`` include
  753. directory for C++ only (compiler id checks elided). It also specifies
  754. a ``COMPILING_CUDA`` compile definition for CUDA.
  755. Note that with :ref:`Visual Studio Generators` and :generator:`Xcode` there
  756. is no way to represent target-wide compile definitions or include directories
  757. separately for ``C`` and ``CXX`` languages.
  758. Also, with :ref:`Visual Studio Generators` there is no way to represent
  759. target-wide flags separately for ``C`` and ``CXX`` languages. Under these
  760. generators, expressions for both C and C++ sources will be evaluated
  761. using ``CXX`` if there are any C++ sources and otherwise using ``C``.
  762. A workaround is to create separate libraries for each source file language
  763. instead:
  764. .. code-block:: cmake
  765. add_library(myapp_c foo.c)
  766. add_library(myapp_cxx bar.cpp)
  767. target_compile_options(myapp_cxx PUBLIC -fno-exceptions)
  768. add_executable(myapp main.cpp)
  769. target_link_libraries(myapp myapp_c myapp_cxx)
  770. .. genex:: $<COMPILE_LANG_AND_ID:language,compiler_ids>
  771. .. versionadded:: 3.15
  772. ``1`` when the language used for compilation unit matches ``language`` and
  773. CMake's compiler id of the ``language`` compiler matches any one of the
  774. comma-separated entries in ``compiler_ids``, otherwise ``0``. This expression
  775. is a short form for the combination of ``$<COMPILE_LANGUAGE:language>`` and
  776. ``$<LANG_COMPILER_ID:compiler_ids>``. This expression may be used to specify
  777. compile options, compile definitions, and include directories for source
  778. files of a particular language and compiler combination in a target.
  779. For example:
  780. .. code-block:: cmake
  781. add_executable(myapp main.cpp foo.c bar.cpp zot.cu)
  782. target_compile_definitions(myapp
  783. PRIVATE $<$<COMPILE_LANG_AND_ID:CXX,AppleClang,Clang>:COMPILING_CXX_WITH_CLANG>
  784. $<$<COMPILE_LANG_AND_ID:CXX,Intel>:COMPILING_CXX_WITH_INTEL>
  785. $<$<COMPILE_LANG_AND_ID:C,Clang>:COMPILING_C_WITH_CLANG>
  786. )
  787. This specifies the use of different compile definitions based on both
  788. the compiler id and compilation language. This example will have a
  789. ``COMPILING_CXX_WITH_CLANG`` compile definition when Clang is the CXX
  790. compiler, and ``COMPILING_CXX_WITH_INTEL`` when Intel is the CXX compiler.
  791. Likewise, when the C compiler is Clang, it will only see the
  792. ``COMPILING_C_WITH_CLANG`` definition.
  793. Without the ``COMPILE_LANG_AND_ID`` generator expression, the same logic
  794. would be expressed as:
  795. .. code-block:: cmake
  796. target_compile_definitions(myapp
  797. PRIVATE $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:AppleClang,Clang>>:COMPILING_CXX_WITH_CLANG>
  798. $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:Intel>>:COMPILING_CXX_WITH_INTEL>
  799. $<$<AND:$<COMPILE_LANGUAGE:C>,$<C_COMPILER_ID:Clang>>:COMPILING_C_WITH_CLANG>
  800. )
  801. Compile Features
  802. ^^^^^^^^^^^^^^^^
  803. .. genex:: $<COMPILE_FEATURES:features>
  804. .. versionadded:: 3.1
  805. where ``features`` is a comma-separated list.
  806. Evaluates to ``1`` if all of the ``features`` are available for the 'head'
  807. target, and ``0`` otherwise. If this expression is used while evaluating
  808. the link implementation of a target and if any dependency transitively
  809. increases the required :prop_tgt:`C_STANDARD` or :prop_tgt:`CXX_STANDARD`
  810. for the 'head' target, an error is reported. See the
  811. :manual:`cmake-compile-features(7)` manual for information on
  812. compile features and a list of supported compilers.
  813. Compile Context
  814. ^^^^^^^^^^^^^^^
  815. .. genex:: $<COMPILE_ONLY:...>
  816. .. versionadded:: 3.27
  817. Content of ``...``, when collecting :ref:`Target Usage Requirements`,
  818. otherwise it is the empty string. This is intended for use in an
  819. :prop_tgt:`INTERFACE_LINK_LIBRARIES` and :prop_tgt:`LINK_LIBRARIES` target
  820. properties, typically populated via the :command:`target_link_libraries` command.
  821. Provides compilation usage requirements without any linking requirements.
  822. Use cases include header-only usage where all usages are known to not have
  823. linking requirements (e.g., all-``inline`` or C++ template libraries).
  824. Note that for proper evaluation of this expression requires policy :policy:`CMP0099`
  825. to be set to `NEW`.
  826. Linker Language And ID
  827. ^^^^^^^^^^^^^^^^^^^^^^
  828. .. genex:: $<LINK_LANGUAGE>
  829. .. versionadded:: 3.18
  830. The link language of the target when evaluating link options.
  831. See :ref:`the related boolean expression
  832. <Boolean LINK_LANGUAGE Generator Expression>` ``$<LINK_LANGUAGE:languages>``
  833. for notes about the portability of this generator expression.
  834. .. note::
  835. This generator expression is not supported by the link libraries
  836. properties to avoid side-effects due to the double evaluation of
  837. these properties.
  838. .. _`Boolean LINK_LANGUAGE Generator Expression`:
  839. .. genex:: $<LINK_LANGUAGE:languages>
  840. .. versionadded:: 3.18
  841. ``1`` when the language used for link step matches any of the comma-separated
  842. entries in ``languages``, otherwise ``0``. This expression may be used to
  843. specify link libraries, link options, link directories and link dependencies
  844. of a particular language in a target. For example:
  845. .. code-block:: cmake
  846. add_library(api_C ...)
  847. add_library(api_CXX ...)
  848. add_library(api INTERFACE)
  849. target_link_options(api INTERFACE $<$<LINK_LANGUAGE:C>:-opt_c>
  850. $<$<LINK_LANGUAGE:CXX>:-opt_cxx>)
  851. target_link_libraries(api INTERFACE $<$<LINK_LANGUAGE:C>:api_C>
  852. $<$<LINK_LANGUAGE:CXX>:api_CXX>)
  853. add_executable(myapp1 main.c)
  854. target_link_options(myapp1 PRIVATE api)
  855. add_executable(myapp2 main.cpp)
  856. target_link_options(myapp2 PRIVATE api)
  857. This specifies to use the ``api`` target for linking targets ``myapp1`` and
  858. ``myapp2``. In practice, ``myapp1`` will link with target ``api_C`` and
  859. option ``-opt_c`` because it will use ``C`` as link language. And ``myapp2``
  860. will link with ``api_CXX`` and option ``-opt_cxx`` because ``CXX`` will be
  861. the link language.
  862. .. _`Constraints LINK_LANGUAGE Generator Expression`:
  863. .. note::
  864. To determine the link language of a target, it is required to collect,
  865. transitively, all the targets which will be linked to it. So, for link
  866. libraries properties, a double evaluation will be done. During the first
  867. evaluation, ``$<LINK_LANGUAGE:..>`` expressions will always return ``0``.
  868. The link language computed after this first pass will be used to do the
  869. second pass. To avoid inconsistency, it is required that the second pass
  870. do not change the link language. Moreover, to avoid unexpected
  871. side-effects, it is required to specify complete entities as part of the
  872. ``$<LINK_LANGUAGE:..>`` expression. For example:
  873. .. code-block:: cmake
  874. add_library(lib STATIC file.cxx)
  875. add_library(libother STATIC file.c)
  876. # bad usage
  877. add_executable(myapp1 main.c)
  878. target_link_libraries(myapp1 PRIVATE lib$<$<LINK_LANGUAGE:C>:other>)
  879. # correct usage
  880. add_executable(myapp2 main.c)
  881. target_link_libraries(myapp2 PRIVATE $<$<LINK_LANGUAGE:C>:libother>)
  882. In this example, for ``myapp1``, the first pass will, unexpectedly,
  883. determine that the link language is ``CXX`` because the evaluation of the
  884. generator expression will be an empty string so ``myapp1`` will depends on
  885. target ``lib`` which is ``C++``. On the contrary, for ``myapp2``, the first
  886. evaluation will give ``C`` as link language, so the second pass will
  887. correctly add target ``libother`` as link dependency.
  888. .. genex:: $<LINK_LANG_AND_ID:language,compiler_ids>
  889. .. versionadded:: 3.18
  890. ``1`` when the language used for link step matches ``language`` and the
  891. CMake's compiler id of the language linker matches any one of the comma-separated
  892. entries in ``compiler_ids``, otherwise ``0``. This expression is a short form
  893. for the combination of ``$<LINK_LANGUAGE:language>`` and
  894. ``$<LANG_COMPILER_ID:compiler_ids>``. This expression may be used to specify
  895. link libraries, link options, link directories and link dependencies of a
  896. particular language and linker combination in a target. For example:
  897. .. code-block:: cmake
  898. add_library(libC_Clang ...)
  899. add_library(libCXX_Clang ...)
  900. add_library(libC_Intel ...)
  901. add_library(libCXX_Intel ...)
  902. add_executable(myapp main.c)
  903. if (CXX_CONFIG)
  904. target_sources(myapp PRIVATE file.cxx)
  905. endif()
  906. target_link_libraries(myapp
  907. PRIVATE $<$<LINK_LANG_AND_ID:CXX,Clang,AppleClang>:libCXX_Clang>
  908. $<$<LINK_LANG_AND_ID:C,Clang,AppleClang>:libC_Clang>
  909. $<$<LINK_LANG_AND_ID:CXX,Intel>:libCXX_Intel>
  910. $<$<LINK_LANG_AND_ID:C,Intel>:libC_Intel>)
  911. This specifies the use of different link libraries based on both the
  912. compiler id and link language. This example will have target ``libCXX_Clang``
  913. as link dependency when ``Clang`` or ``AppleClang`` is the ``CXX``
  914. linker, and ``libCXX_Intel`` when ``Intel`` is the ``CXX`` linker.
  915. Likewise when the ``C`` linker is ``Clang`` or ``AppleClang``, target
  916. ``libC_Clang`` will be added as link dependency and ``libC_Intel`` when
  917. ``Intel`` is the ``C`` linker.
  918. See :ref:`the note related to
  919. <Constraints LINK_LANGUAGE Generator Expression>`
  920. ``$<LINK_LANGUAGE:language>`` for constraints about the usage of this
  921. generator expression.
  922. Link Features
  923. ^^^^^^^^^^^^^
  924. .. genex:: $<LINK_LIBRARY:feature,library-list>
  925. .. versionadded:: 3.24
  926. Specify a set of libraries to link to a target, along with a ``feature``
  927. which provides details about *how* they should be linked. For example:
  928. .. code-block:: cmake
  929. add_library(lib1 STATIC ...)
  930. add_library(lib2 ...)
  931. target_link_libraries(lib2 PRIVATE "$<LINK_LIBRARY:WHOLE_ARCHIVE,lib1>")
  932. This specifies that ``lib2`` should link to ``lib1`` and use the
  933. ``WHOLE_ARCHIVE`` feature when doing so.
  934. Feature names are case-sensitive and may only contain letters, numbers and
  935. underscores. Feature names defined in all uppercase are reserved for CMake's
  936. own built-in features. The pre-defined built-in library features are:
  937. .. include:: ../variable/LINK_LIBRARY_PREDEFINED_FEATURES.txt
  938. Built-in and custom library features are defined in terms of the following
  939. variables:
  940. * :variable:`CMAKE_<LANG>_LINK_LIBRARY_USING_<FEATURE>_SUPPORTED`
  941. * :variable:`CMAKE_<LANG>_LINK_LIBRARY_USING_<FEATURE>`
  942. * :variable:`CMAKE_LINK_LIBRARY_USING_<FEATURE>_SUPPORTED`
  943. * :variable:`CMAKE_LINK_LIBRARY_USING_<FEATURE>`
  944. The value used for each of these variables is the value as set at the end of
  945. the directory scope in which the target was created. The usage is as follows:
  946. 1. If the language-specific
  947. :variable:`CMAKE_<LANG>_LINK_LIBRARY_USING_<FEATURE>_SUPPORTED` variable
  948. is true, the ``feature`` must be defined by the corresponding
  949. :variable:`CMAKE_<LANG>_LINK_LIBRARY_USING_<FEATURE>` variable.
  950. 2. If no language-specific ``feature`` is supported, then the
  951. :variable:`CMAKE_LINK_LIBRARY_USING_<FEATURE>_SUPPORTED` variable must be
  952. true and the ``feature`` must be defined by the corresponding
  953. :variable:`CMAKE_LINK_LIBRARY_USING_<FEATURE>` variable.
  954. The following limitations should be noted:
  955. * The ``library-list`` can specify CMake targets or libraries.
  956. Any CMake target of type :ref:`OBJECT <Object Libraries>`
  957. or :ref:`INTERFACE <Interface Libraries>` will ignore the feature aspect
  958. of the expression and instead be linked in the standard way.
  959. * The ``$<LINK_LIBRARY:...>`` generator expression can only be used to
  960. specify link libraries. In practice, this means it can appear in the
  961. :prop_tgt:`LINK_LIBRARIES`, :prop_tgt:`INTERFACE_LINK_LIBRARIES`, and
  962. :prop_tgt:`INTERFACE_LINK_LIBRARIES_DIRECT` target properties, and be
  963. specified in :command:`target_link_libraries` and :command:`link_libraries`
  964. commands.
  965. * If a ``$<LINK_LIBRARY:...>`` generator expression appears in the
  966. :prop_tgt:`INTERFACE_LINK_LIBRARIES` property of a target, it will be
  967. included in the imported target generated by a :command:`install(EXPORT)`
  968. command. It is the responsibility of the environment consuming this
  969. import to define the link feature used by this expression.
  970. * Each target or library involved in the link step must have at most only
  971. one kind of library feature. The absence of a feature is also incompatible
  972. with all other features. For example:
  973. .. code-block:: cmake
  974. add_library(lib1 ...)
  975. add_library(lib2 ...)
  976. add_library(lib3 ...)
  977. # lib1 will be associated with feature1
  978. target_link_libraries(lib2 PUBLIC "$<LINK_LIBRARY:feature1,lib1>")
  979. # lib1 is being linked with no feature here. This conflicts with the
  980. # use of feature1 in the line above and would result in an error.
  981. target_link_libraries(lib3 PRIVATE lib1 lib2)
  982. Where it isn't possible to use the same feature throughout a build for a
  983. given target or library, the :prop_tgt:`LINK_LIBRARY_OVERRIDE` and
  984. :prop_tgt:`LINK_LIBRARY_OVERRIDE_<LIBRARY>` target properties can be
  985. used to resolve such incompatibilities.
  986. * The ``$<LINK_LIBRARY:...>`` generator expression does not guarantee
  987. that the list of specified targets and libraries will be kept grouped
  988. together. To manage constructs like ``--start-group`` and ``--end-group``,
  989. as supported by the GNU ``ld`` linker, use the :genex:`LINK_GROUP`
  990. generator expression instead.
  991. .. genex:: $<LINK_GROUP:feature,library-list>
  992. .. versionadded:: 3.24
  993. Specify a group of libraries to link to a target, along with a ``feature``
  994. which defines how that group should be linked. For example:
  995. .. code-block:: cmake
  996. add_library(lib1 STATIC ...)
  997. add_library(lib2 ...)
  998. target_link_libraries(lib2 PRIVATE "$<LINK_GROUP:RESCAN,lib1,external>")
  999. This specifies that ``lib2`` should link to ``lib1`` and ``external``, and
  1000. that both of those two libraries should be included on the linker command
  1001. line according to the definition of the ``RESCAN`` feature.
  1002. Feature names are case-sensitive and may only contain letters, numbers and
  1003. underscores. Feature names defined in all uppercase are reserved for CMake's
  1004. own built-in features. Currently, there is only one pre-defined built-in
  1005. group feature:
  1006. .. include:: ../variable/LINK_GROUP_PREDEFINED_FEATURES.txt
  1007. Built-in and custom group features are defined in terms of the following
  1008. variables:
  1009. * :variable:`CMAKE_<LANG>_LINK_GROUP_USING_<FEATURE>_SUPPORTED`
  1010. * :variable:`CMAKE_<LANG>_LINK_GROUP_USING_<FEATURE>`
  1011. * :variable:`CMAKE_LINK_GROUP_USING_<FEATURE>_SUPPORTED`
  1012. * :variable:`CMAKE_LINK_GROUP_USING_<FEATURE>`
  1013. The value used for each of these variables is the value as set at the end of
  1014. the directory scope in which the target was created. The usage is as follows:
  1015. 1. If the language-specific
  1016. :variable:`CMAKE_<LANG>_LINK_GROUP_USING_<FEATURE>_SUPPORTED` variable
  1017. is true, the ``feature`` must be defined by the corresponding
  1018. :variable:`CMAKE_<LANG>_LINK_GROUP_USING_<FEATURE>` variable.
  1019. 2. If no language-specific ``feature`` is supported, then the
  1020. :variable:`CMAKE_LINK_GROUP_USING_<FEATURE>_SUPPORTED` variable must be
  1021. true and the ``feature`` must be defined by the corresponding
  1022. :variable:`CMAKE_LINK_GROUP_USING_<FEATURE>` variable.
  1023. The ``LINK_GROUP`` generator expression is compatible with the
  1024. :genex:`LINK_LIBRARY` generator expression. The libraries involved in a
  1025. group can be specified using the :genex:`LINK_LIBRARY` generator expression.
  1026. Each target or external library involved in the link step is allowed to be
  1027. part of multiple groups, but only if all the groups involved specify the
  1028. same ``feature``. Such groups will not be merged on the linker command line,
  1029. the individual groups will still be preserved. Mixing different group
  1030. features for the same target or library is forbidden.
  1031. .. code-block:: cmake
  1032. add_library(lib1 ...)
  1033. add_library(lib2 ...)
  1034. add_library(lib3 ...)
  1035. add_library(lib4 ...)
  1036. add_library(lib5 ...)
  1037. target_link_libraries(lib3 PUBLIC "$<LINK_GROUP:feature1,lib1,lib2>")
  1038. target_link_libraries(lib4 PRIVATE "$<LINK_GROUP:feature1,lib1,lib3>")
  1039. # lib4 will be linked with the groups {lib1,lib2} and {lib1,lib3}.
  1040. # Both groups specify the same feature, so this is fine.
  1041. target_link_libraries(lib5 PRIVATE "$<LINK_GROUP:feature2,lib1,lib3>")
  1042. # An error will be raised here because both lib1 and lib3 are part of two
  1043. # groups with different features.
  1044. When a target or an external library is involved in the link step as part of
  1045. a group and also as not part of any group, any occurrence of the non-group
  1046. link item will be replaced by the groups it belongs to.
  1047. .. code-block:: cmake
  1048. add_library(lib1 ...)
  1049. add_library(lib2 ...)
  1050. add_library(lib3 ...)
  1051. add_library(lib4 ...)
  1052. target_link_libraries(lib3 PUBLIC lib1)
  1053. target_link_libraries(lib4 PRIVATE lib3 "$<LINK_GROUP:feature1,lib1,lib2>")
  1054. # lib4 will only be linked with lib3 and the group {lib1,lib2}
  1055. Because ``lib1`` is part of the group defined for ``lib4``, that group then
  1056. gets applied back to the use of ``lib1`` for ``lib3``. The end result will
  1057. be as though the linking relationship for ``lib3`` had been specified as:
  1058. .. code-block:: cmake
  1059. target_link_libraries(lib3 PUBLIC "$<LINK_GROUP:feature1,lib1,lib2>")
  1060. Be aware that the precedence of the group over the non-group link item can
  1061. result in circular dependencies between groups. If this occurs, a fatal
  1062. error is raised because circular dependencies are not allowed for groups.
  1063. .. code-block:: cmake
  1064. add_library(lib1A ...)
  1065. add_library(lib1B ...)
  1066. add_library(lib2A ...)
  1067. add_library(lib2B ...)
  1068. add_library(lib3 ...)
  1069. # Non-group linking relationships, these are non-circular so far
  1070. target_link_libraries(lib1A PUBLIC lib2A)
  1071. target_link_libraries(lib2B PUBLIC lib1B)
  1072. # The addition of these groups creates circular dependencies
  1073. target_link_libraries(lib3 PRIVATE
  1074. "$<LINK_GROUP:feat,lib1A,lib1B>"
  1075. "$<LINK_GROUP:feat,lib2A,lib2B>"
  1076. )
  1077. Because of the groups defined for ``lib3``, the linking relationships for
  1078. ``lib1A`` and ``lib2B`` effectively get expanded to the equivalent of:
  1079. .. code-block:: cmake
  1080. target_link_libraries(lib1A PUBLIC "$<LINK_GROUP:feat,lib2A,lib2B>")
  1081. target_link_libraries(lib2B PUBLIC "$<LINK_GROUP:feat,lib1A,lib1B>")
  1082. This creates a circular dependency between groups:
  1083. ``lib1A --> lib2B --> lib1A``.
  1084. The following limitations should also be noted:
  1085. * The ``library-list`` can specify CMake targets or libraries.
  1086. Any CMake target of type :ref:`OBJECT <Object Libraries>`
  1087. or :ref:`INTERFACE <Interface Libraries>` will ignore the feature aspect
  1088. of the expression and instead be linked in the standard way.
  1089. * The ``$<LINK_GROUP:...>`` generator expression can only be used to
  1090. specify link libraries. In practice, this means it can appear in the
  1091. :prop_tgt:`LINK_LIBRARIES`, :prop_tgt:`INTERFACE_LINK_LIBRARIES`,and
  1092. :prop_tgt:`INTERFACE_LINK_LIBRARIES_DIRECT` target properties, and be
  1093. specified in :command:`target_link_libraries` and :command:`link_libraries`
  1094. commands.
  1095. * If a ``$<LINK_GROUP:...>`` generator expression appears in the
  1096. :prop_tgt:`INTERFACE_LINK_LIBRARIES` property of a target, it will be
  1097. included in the imported target generated by a :command:`install(EXPORT)`
  1098. command. It is the responsibility of the environment consuming this
  1099. import to define the link feature used by this expression.
  1100. Link Context
  1101. ^^^^^^^^^^^^
  1102. .. genex:: $<LINK_ONLY:...>
  1103. .. versionadded:: 3.1
  1104. Content of ``...``, except while collecting :ref:`Target Usage Requirements`,
  1105. in which case it is the empty string. This is intended for use in an
  1106. :prop_tgt:`INTERFACE_LINK_LIBRARIES` target property, typically populated
  1107. via the :command:`target_link_libraries` command, to specify private link
  1108. dependencies without other usage requirements such as include directories or
  1109. compile options.
  1110. .. versionadded:: 3.24
  1111. ``LINK_ONLY`` may also be used in a :prop_tgt:`LINK_LIBRARIES` target
  1112. property. See policy :policy:`CMP0131`.
  1113. .. genex:: $<DEVICE_LINK:list>
  1114. .. versionadded:: 3.18
  1115. Returns the list if it is the device link step, an empty list otherwise.
  1116. The device link step is controlled by :prop_tgt:`CUDA_SEPARABLE_COMPILATION`
  1117. and :prop_tgt:`CUDA_RESOLVE_DEVICE_SYMBOLS` properties and
  1118. policy :policy:`CMP0105`. This expression can only be used to specify link
  1119. options.
  1120. .. genex:: $<HOST_LINK:list>
  1121. .. versionadded:: 3.18
  1122. Returns the list if it is the normal link step, an empty list otherwise.
  1123. This expression is mainly useful when a device link step is also involved
  1124. (see :genex:`$<DEVICE_LINK:list>` generator expression). This expression can
  1125. only be used to specify link options.
  1126. .. _`Target-Dependent Queries`:
  1127. Target-Dependent Expressions
  1128. ----------------------------
  1129. These queries refer to a target ``tgt``. Unless otherwise stated, this can
  1130. be any runtime artifact, namely:
  1131. * An executable target created by :command:`add_executable`.
  1132. * A shared library target (``.so``, ``.dll`` but not their ``.lib`` import
  1133. library) created by :command:`add_library`.
  1134. * A static library target created by :command:`add_library`.
  1135. In the following, the phrase "the ``tgt`` filename" means the name of the
  1136. ``tgt`` binary file. This has to be distinguished from the phrase
  1137. "the target name", which is just the string ``tgt``.
  1138. .. genex:: $<TARGET_EXISTS:tgt>
  1139. .. versionadded:: 3.12
  1140. ``1`` if ``tgt`` exists as a CMake target, else ``0``.
  1141. .. genex:: $<TARGET_NAME_IF_EXISTS:tgt>
  1142. .. versionadded:: 3.12
  1143. The target name ``tgt`` if the target exists, an empty string otherwise.
  1144. Note that ``tgt`` is not added as a dependency of the target this
  1145. expression is evaluated on.
  1146. .. genex:: $<TARGET_NAME:...>
  1147. Marks ``...`` as being the name of a target. This is required if exporting
  1148. targets to multiple dependent export sets. The ``...`` must be a literal
  1149. name of a target, it may not contain generator expressions.
  1150. .. genex:: $<TARGET_PROPERTY:tgt,prop>
  1151. Value of the property ``prop`` on the target ``tgt``.
  1152. Note that ``tgt`` is not added as a dependency of the target this
  1153. expression is evaluated on.
  1154. .. versionchanged:: 3.26
  1155. When encountered during evaluation of :ref:`Target Usage Requirements`,
  1156. typically in an ``INTERFACE_*`` target property, lookup of the ``tgt``
  1157. name occurs in the directory of the target specifying the requirement,
  1158. rather than the directory of the consuming target for which the
  1159. expression is being evaluated.
  1160. .. genex:: $<TARGET_PROPERTY:prop>
  1161. :target: TARGET_PROPERTY:prop
  1162. Value of the property ``prop`` on the target for which the expression
  1163. is being evaluated. Note that for generator expressions in
  1164. :ref:`Target Usage Requirements` this is the consuming target rather
  1165. than the target specifying the requirement.
  1166. .. genex:: $<TARGET_OBJECTS:tgt>
  1167. .. versionadded:: 3.1
  1168. List of objects resulting from building ``tgt``. This would typically be
  1169. used on :ref:`object library <Object Libraries>` targets.
  1170. .. genex:: $<TARGET_POLICY:policy>
  1171. ``1`` if the ``policy`` was ``NEW`` when the 'head' target was created,
  1172. else ``0``. If the ``policy`` was not set, the warning message for the policy
  1173. will be emitted. This generator expression only works for a subset of
  1174. policies.
  1175. .. genex:: $<TARGET_FILE:tgt>
  1176. Full path to the ``tgt`` binary file.
  1177. Note that ``tgt`` is not added as a dependency of the target this
  1178. expression is evaluated on, unless the expression is being used in
  1179. :command:`add_custom_command` or :command:`add_custom_target`.
  1180. .. genex:: $<TARGET_FILE_BASE_NAME:tgt>
  1181. .. versionadded:: 3.15
  1182. Base name of ``tgt``, i.e. ``$<TARGET_FILE_NAME:tgt>`` without prefix and
  1183. suffix.
  1184. For example, if the ``tgt`` filename is ``libbase.so``, the base name is ``base``.
  1185. See also the :prop_tgt:`OUTPUT_NAME`, :prop_tgt:`ARCHIVE_OUTPUT_NAME`,
  1186. :prop_tgt:`LIBRARY_OUTPUT_NAME` and :prop_tgt:`RUNTIME_OUTPUT_NAME`
  1187. target properties and their configuration specific variants
  1188. :prop_tgt:`OUTPUT_NAME_<CONFIG>`, :prop_tgt:`ARCHIVE_OUTPUT_NAME_<CONFIG>`,
  1189. :prop_tgt:`LIBRARY_OUTPUT_NAME_<CONFIG>` and
  1190. :prop_tgt:`RUNTIME_OUTPUT_NAME_<CONFIG>`.
  1191. The :prop_tgt:`<CONFIG>_POSTFIX` and :prop_tgt:`DEBUG_POSTFIX` target
  1192. properties can also be considered.
  1193. Note that ``tgt`` is not added as a dependency of the target this
  1194. expression is evaluated on.
  1195. .. genex:: $<TARGET_FILE_PREFIX:tgt>
  1196. .. versionadded:: 3.15
  1197. Prefix of the ``tgt`` filename (such as ``lib``).
  1198. See also the :prop_tgt:`PREFIX` target property.
  1199. Note that ``tgt`` is not added as a dependency of the target this
  1200. expression is evaluated on.
  1201. .. genex:: $<TARGET_FILE_SUFFIX:tgt>
  1202. .. versionadded:: 3.15
  1203. Suffix of the ``tgt`` filename (extension such as ``.so`` or ``.exe``).
  1204. See also the :prop_tgt:`SUFFIX` target property.
  1205. Note that ``tgt`` is not added as a dependency of the target this
  1206. expression is evaluated on.
  1207. .. genex:: $<TARGET_FILE_NAME:tgt>
  1208. The ``tgt`` filename.
  1209. Note that ``tgt`` is not added as a dependency of the target this
  1210. expression is evaluated on (see policy :policy:`CMP0112`).
  1211. .. genex:: $<TARGET_FILE_DIR:tgt>
  1212. Directory of the ``tgt`` binary file.
  1213. Note that ``tgt`` is not added as a dependency of the target this
  1214. expression is evaluated on (see policy :policy:`CMP0112`).
  1215. .. genex:: $<TARGET_IMPORT_FILE:tgt>
  1216. .. versionadded:: 3.27
  1217. Full path to the linker import file. On DLL platforms, it would be the
  1218. ``.lib`` file. For executables on AIX, and for shared libraries on macOS,
  1219. it could be, respectively, the ``.imp`` or ``.tbd`` import file,
  1220. depending on the value of the :prop_tgt:`ENABLE_EXPORTS` property.
  1221. This expands to an empty string when there is no import file associated
  1222. with the target.
  1223. .. genex:: $<TARGET_IMPORT_FILE_BASE_NAME:tgt>
  1224. .. versionadded:: 3.27
  1225. Base name of the linker import file of the target ``tgt`` without prefix or
  1226. suffix. For example, if the target file name is ``libbase.tbd``, the base
  1227. name is ``base``.
  1228. See also the :prop_tgt:`OUTPUT_NAME` and :prop_tgt:`ARCHIVE_OUTPUT_NAME`
  1229. target properties and their configuration specific variants
  1230. :prop_tgt:`OUTPUT_NAME_<CONFIG>` and :prop_tgt:`ARCHIVE_OUTPUT_NAME_<CONFIG>`.
  1231. The :prop_tgt:`<CONFIG>_POSTFIX` and :prop_tgt:`DEBUG_POSTFIX` target
  1232. properties can also be considered.
  1233. Note that ``tgt`` is not added as a dependency of the target this
  1234. expression is evaluated on.
  1235. .. genex:: $<TARGET_IMPORT_FILE_PREFIX:tgt>
  1236. .. versionadded:: 3.27
  1237. Prefix of the import file of the target ``tgt``.
  1238. See also the :prop_tgt:`IMPORT_PREFIX` target property.
  1239. Note that ``tgt`` is not added as a dependency of the target this
  1240. expression is evaluated on.
  1241. .. genex:: $<TARGET_IMPORT_FILE_SUFFIX:tgt>
  1242. .. versionadded:: 3.27
  1243. Suffix of the import file of the target ``tgt``.
  1244. The suffix corresponds to the file extension (such as ``.lib`` or ``.tbd``).
  1245. See also the :prop_tgt:`IMPORT_SUFFIX` target property.
  1246. Note that ``tgt`` is not added as a dependency of the target this
  1247. expression is evaluated on.
  1248. .. genex:: $<TARGET_IMPORT_FILE_NAME:tgt>
  1249. .. versionadded:: 3.27
  1250. Name of the import file of the target ``tgt``.
  1251. Note that ``tgt`` is not added as a dependency of the target this
  1252. expression is evaluated on.
  1253. .. genex:: $<TARGET_IMPORT_FILE_DIR:tgt>
  1254. .. versionadded:: 3.27
  1255. Directory of the import file of the target ``tgt``.
  1256. Note that ``tgt`` is not added as a dependency of the target this
  1257. expression is evaluated on.
  1258. .. genex:: $<TARGET_LINKER_FILE:tgt>
  1259. File used when linking to the ``tgt`` target. This will usually
  1260. be the library that ``tgt`` represents (``.a``, ``.lib``, ``.so``),
  1261. but for a shared library on DLL platforms, it would be the ``.lib``
  1262. import library associated with the DLL.
  1263. .. versionadded:: 3.27
  1264. On macOS, it could be the ``.tbd`` import file associated with the shared
  1265. library, depending on the value of the :prop_tgt:`ENABLE_EXPORTS` property.
  1266. This generator expression is equivalent to
  1267. :genex:`$<TARGET_LINKER_LIBRARY_FILE>` or
  1268. :genex:`$<TARGET_LINKER_IMPORT_FILE>` generator expressions, depending on the
  1269. characteristics of the target and the platform.
  1270. .. genex:: $<TARGET_LINKER_FILE_BASE_NAME:tgt>
  1271. .. versionadded:: 3.15
  1272. Base name of file used to link the target ``tgt``, i.e.
  1273. :genex:`$<TARGET_LINKER_FILE_NAME:tgt>` without prefix and suffix. For
  1274. example, if target file name is ``libbase.a``, the base name is ``base``.
  1275. See also the :prop_tgt:`OUTPUT_NAME`, :prop_tgt:`ARCHIVE_OUTPUT_NAME`,
  1276. and :prop_tgt:`LIBRARY_OUTPUT_NAME` target properties and their configuration
  1277. specific variants :prop_tgt:`OUTPUT_NAME_<CONFIG>`,
  1278. :prop_tgt:`ARCHIVE_OUTPUT_NAME_<CONFIG>` and
  1279. :prop_tgt:`LIBRARY_OUTPUT_NAME_<CONFIG>`.
  1280. The :prop_tgt:`<CONFIG>_POSTFIX` and :prop_tgt:`DEBUG_POSTFIX` target
  1281. properties can also be considered.
  1282. Note that ``tgt`` is not added as a dependency of the target this
  1283. expression is evaluated on.
  1284. .. genex:: $<TARGET_LINKER_FILE_PREFIX:tgt>
  1285. .. versionadded:: 3.15
  1286. Prefix of file used to link target ``tgt``.
  1287. See also the :prop_tgt:`PREFIX` and :prop_tgt:`IMPORT_PREFIX` target
  1288. properties.
  1289. Note that ``tgt`` is not added as a dependency of the target this
  1290. expression is evaluated on.
  1291. .. genex:: $<TARGET_LINKER_FILE_SUFFIX:tgt>
  1292. .. versionadded:: 3.15
  1293. Suffix of file used to link where ``tgt`` is the name of a target.
  1294. The suffix corresponds to the file extension (such as ".so" or ".lib").
  1295. See also the :prop_tgt:`SUFFIX` and :prop_tgt:`IMPORT_SUFFIX` target
  1296. properties.
  1297. Note that ``tgt`` is not added as a dependency of the target this
  1298. expression is evaluated on.
  1299. .. genex:: $<TARGET_LINKER_FILE_NAME:tgt>
  1300. Name of file used to link target ``tgt``.
  1301. Note that ``tgt`` is not added as a dependency of the target this
  1302. expression is evaluated on (see policy :policy:`CMP0112`).
  1303. .. genex:: $<TARGET_LINKER_FILE_DIR:tgt>
  1304. Directory of file used to link target ``tgt``.
  1305. Note that ``tgt`` is not added as a dependency of the target this
  1306. expression is evaluated on (see policy :policy:`CMP0112`).
  1307. .. genex:: $<TARGET_LINKER_LIBRARY_FILE:tgt>
  1308. .. versionadded:: 3.27
  1309. File used when linking o the ``tgt`` target is done using directly the
  1310. library, and not an import file. This will usually be the library that
  1311. ``tgt`` represents (``.a``, ``.so``, ``.dylib``). So, on DLL platforms, it
  1312. will be an empty string.
  1313. .. genex:: $<TARGET_LINKER_LIBRARY_FILE_BASE_NAME:tgt>
  1314. .. versionadded:: 3.27
  1315. Base name of library file used to link the target ``tgt``, i.e.
  1316. :genex:`$<TARGET_LINKER_LIBRARY_FILE_NAME:tgt>` without prefix and suffix.
  1317. For example, if target file name is ``libbase.a``, the base name is ``base``.
  1318. See also the :prop_tgt:`OUTPUT_NAME`, :prop_tgt:`ARCHIVE_OUTPUT_NAME`,
  1319. and :prop_tgt:`LIBRARY_OUTPUT_NAME` target properties and their configuration
  1320. specific variants :prop_tgt:`OUTPUT_NAME_<CONFIG>`,
  1321. :prop_tgt:`ARCHIVE_OUTPUT_NAME_<CONFIG>` and
  1322. :prop_tgt:`LIBRARY_OUTPUT_NAME_<CONFIG>`.
  1323. The :prop_tgt:`<CONFIG>_POSTFIX` and :prop_tgt:`DEBUG_POSTFIX` target
  1324. properties can also be considered.
  1325. Note that ``tgt`` is not added as a dependency of the target this
  1326. expression is evaluated on.
  1327. .. genex:: $<TARGET_LINKER_LIBRARY_FILE_PREFIX:tgt>
  1328. .. versionadded:: 3.27
  1329. Prefix of the library file used to link target ``tgt``.
  1330. See also the :prop_tgt:`PREFIX` target property.
  1331. Note that ``tgt`` is not added as a dependency of the target this
  1332. expression is evaluated on.
  1333. .. genex:: $<TARGET_LINKER_LIBRARY_FILE_SUFFIX:tgt>
  1334. .. versionadded:: 3.27
  1335. Suffix of the library file used to link target ``tgt``.
  1336. The suffix corresponds to the file extension (such as ".a" or ".dylib").
  1337. See also the :prop_tgt:`SUFFIX` target property.
  1338. Note that ``tgt`` is not added as a dependency of the target this
  1339. expression is evaluated on.
  1340. .. genex:: $<TARGET_LINKER_LIBRARY_FILE_NAME:tgt>
  1341. .. versionadded:: 3.27
  1342. Name of the library file used to link target ``tgt``.
  1343. Note that ``tgt`` is not added as a dependency of the target this
  1344. expression is evaluated on.
  1345. .. genex:: $<TARGET_LINKER_LIBRARY_FILE_DIR:tgt>
  1346. .. versionadded:: 3.27
  1347. Directory of the library file used to link target ``tgt``.
  1348. Note that ``tgt`` is not added as a dependency of the target this
  1349. expression is evaluated on.
  1350. .. genex:: $<TARGET_LINKER_IMPORT_FILE:tgt>
  1351. .. versionadded:: 3.27
  1352. File used when linking to the ``tgt`` target is done using an import
  1353. file. This will usually be the import file that ``tgt`` represents
  1354. (``.lib``, ``.tbd``). So, when no import file is involved in the link step,
  1355. an empty string is returned.
  1356. .. genex:: $<TARGET_LINKER_IMPORT_FILE_BASE_NAME:tgt>
  1357. .. versionadded:: 3.27
  1358. Base name of the import file used to link the target ``tgt``, i.e.
  1359. :genex:`$<TARGET_LINKER_IMPORT_FILE_NAME:tgt>` without prefix and suffix.
  1360. For example, if target file name is ``libbase.tbd``, the base name is ``base``.
  1361. See also the :prop_tgt:`OUTPUT_NAME` and :prop_tgt:`ARCHIVE_OUTPUT_NAME`,
  1362. target properties and their configuration
  1363. specific variants :prop_tgt:`OUTPUT_NAME_<CONFIG>` and
  1364. :prop_tgt:`ARCHIVE_OUTPUT_NAME_<CONFIG>`.
  1365. The :prop_tgt:`<CONFIG>_POSTFIX` and :prop_tgt:`DEBUG_POSTFIX` target
  1366. properties can also be considered.
  1367. Note that ``tgt`` is not added as a dependency of the target this
  1368. expression is evaluated on.
  1369. .. genex:: $<TARGET_LINKER_IMPORT_FILE_PREFIX:tgt>
  1370. .. versionadded:: 3.27
  1371. Prefix of the import file used to link target ``tgt``.
  1372. See also the :prop_tgt:`IMPORT_PREFIX` target property.
  1373. Note that ``tgt`` is not added as a dependency of the target this
  1374. expression is evaluated on.
  1375. .. genex:: $<TARGET_LINKER_IMPORT_FILE_SUFFIX:tgt>
  1376. .. versionadded:: 3.27
  1377. Suffix of the import file used to link target ``tgt``.
  1378. The suffix corresponds to the file extension (such as ".lib" or ".tbd").
  1379. See also the :prop_tgt:`IMPORT_SUFFIX` target property.
  1380. Note that ``tgt`` is not added as a dependency of the target this
  1381. expression is evaluated on.
  1382. .. genex:: $<TARGET_LINKER_IMPORT_FILE_NAME:tgt>
  1383. .. versionadded:: 3.27
  1384. Name of the import file used to link target ``tgt``.
  1385. Note that ``tgt`` is not added as a dependency of the target this
  1386. expression is evaluated on.
  1387. .. genex:: $<TARGET_LINKER_IMPORT_FILE_DIR:tgt>
  1388. .. versionadded:: 3.27
  1389. Directory of the import file used to link target ``tgt``.
  1390. Note that ``tgt`` is not added as a dependency of the target this
  1391. expression is evaluated on.
  1392. .. genex:: $<TARGET_SONAME_FILE:tgt>
  1393. File with soname (``.so.3``) where ``tgt`` is the name of a target.
  1394. .. genex:: $<TARGET_SONAME_FILE_NAME:tgt>
  1395. Name of file with soname (``.so.3``).
  1396. Note that ``tgt`` is not added as a dependency of the target this
  1397. expression is evaluated on (see policy :policy:`CMP0112`).
  1398. .. genex:: $<TARGET_SONAME_FILE_DIR:tgt>
  1399. Directory of file with soname (``.so.3``).
  1400. Note that ``tgt`` is not added as a dependency of the target this
  1401. expression is evaluated on (see policy :policy:`CMP0112`).
  1402. .. genex:: $<TARGET_SONAME_IMPORT_FILE:tgt>
  1403. .. versionadded:: 3.27
  1404. Import file with soname (``.3.tbd``) where ``tgt`` is the name of a target.
  1405. .. genex:: $<TARGET_SONAME_IMPORT_FILE_NAME:tgt>
  1406. .. versionadded:: 3.27
  1407. Name of the import file with soname (``.3.tbd``).
  1408. Note that ``tgt`` is not added as a dependency of the target this
  1409. expression is evaluated on.
  1410. .. genex:: $<TARGET_SONAME_IMPORT_FILE_DIR:tgt>
  1411. .. versionadded:: 3.27
  1412. Directory of the import file with soname (``.3.tbd``).
  1413. Note that ``tgt`` is not added as a dependency of the target this
  1414. expression is evaluated on.
  1415. .. genex:: $<TARGET_PDB_FILE:tgt>
  1416. .. versionadded:: 3.1
  1417. Full path to the linker generated program database file (.pdb)
  1418. where ``tgt`` is the name of a target.
  1419. See also the :prop_tgt:`PDB_NAME` and :prop_tgt:`PDB_OUTPUT_DIRECTORY`
  1420. target properties and their configuration specific variants
  1421. :prop_tgt:`PDB_NAME_<CONFIG>` and :prop_tgt:`PDB_OUTPUT_DIRECTORY_<CONFIG>`.
  1422. .. genex:: $<TARGET_PDB_FILE_BASE_NAME:tgt>
  1423. .. versionadded:: 3.15
  1424. Base name of the linker generated program database file (.pdb)
  1425. where ``tgt`` is the name of a target.
  1426. The base name corresponds to the target PDB file name (see
  1427. ``$<TARGET_PDB_FILE_NAME:tgt>``) without prefix and suffix. For example,
  1428. if target file name is ``base.pdb``, the base name is ``base``.
  1429. See also the :prop_tgt:`PDB_NAME` target property and its configuration
  1430. specific variant :prop_tgt:`PDB_NAME_<CONFIG>`.
  1431. The :prop_tgt:`<CONFIG>_POSTFIX` and :prop_tgt:`DEBUG_POSTFIX` target
  1432. properties can also be considered.
  1433. Note that ``tgt`` is not added as a dependency of the target this
  1434. expression is evaluated on.
  1435. .. genex:: $<TARGET_PDB_FILE_NAME:tgt>
  1436. .. versionadded:: 3.1
  1437. Name of the linker generated program database file (.pdb).
  1438. Note that ``tgt`` is not added as a dependency of the target this
  1439. expression is evaluated on (see policy :policy:`CMP0112`).
  1440. .. genex:: $<TARGET_PDB_FILE_DIR:tgt>
  1441. .. versionadded:: 3.1
  1442. Directory of the linker generated program database file (.pdb).
  1443. Note that ``tgt`` is not added as a dependency of the target this
  1444. expression is evaluated on (see policy :policy:`CMP0112`).
  1445. .. genex:: $<TARGET_BUNDLE_DIR:tgt>
  1446. .. versionadded:: 3.9
  1447. Full path to the bundle directory (``/path/to/my.app``,
  1448. ``/path/to/my.framework``, or ``/path/to/my.bundle``),
  1449. where ``tgt`` is the name of a target.
  1450. Note that ``tgt`` is not added as a dependency of the target this
  1451. expression is evaluated on (see policy :policy:`CMP0112`).
  1452. .. genex:: $<TARGET_BUNDLE_DIR_NAME:tgt>
  1453. .. versionadded:: 3.24
  1454. Name of the bundle directory (``my.app``, ``my.framework``, or
  1455. ``my.bundle``), where ``tgt`` is the name of a target.
  1456. Note that ``tgt`` is not added as a dependency of the target this
  1457. expression is evaluated on (see policy :policy:`CMP0112`).
  1458. .. genex:: $<TARGET_BUNDLE_CONTENT_DIR:tgt>
  1459. .. versionadded:: 3.9
  1460. Full path to the bundle content directory where ``tgt`` is the name of a
  1461. target. For the macOS SDK it leads to ``/path/to/my.app/Contents``,
  1462. ``/path/to/my.framework``, or ``/path/to/my.bundle/Contents``.
  1463. For all other SDKs (e.g. iOS) it leads to ``/path/to/my.app``,
  1464. ``/path/to/my.framework``, or ``/path/to/my.bundle`` due to the flat
  1465. bundle structure.
  1466. Note that ``tgt`` is not added as a dependency of the target this
  1467. expression is evaluated on (see policy :policy:`CMP0112`).
  1468. .. genex:: $<TARGET_RUNTIME_DLLS:tgt>
  1469. .. versionadded:: 3.21
  1470. List of DLLs that the target depends on at runtime. This is determined by
  1471. the locations of all the ``SHARED`` targets in the target's transitive
  1472. dependencies. If only the directories of the DLLs are needed, see the
  1473. :genex:`TARGET_RUNTIME_DLL_DIRS` generator expression.
  1474. Using this generator expression on targets other than
  1475. executables, ``SHARED`` libraries, and ``MODULE`` libraries is an error.
  1476. **On non-DLL platforms, this expression always evaluates to an empty string**.
  1477. This generator expression can be used to copy all of the DLLs that a target
  1478. depends on into its output directory in a ``POST_BUILD`` custom command using
  1479. the :option:`cmake -E copy -t <cmake-E copy>` command. For example:
  1480. .. code-block:: cmake
  1481. find_package(foo CONFIG REQUIRED) # package generated by install(EXPORT)
  1482. add_executable(exe main.c)
  1483. target_link_libraries(exe PRIVATE foo::foo foo::bar)
  1484. add_custom_command(TARGET exe POST_BUILD
  1485. COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR:exe> $<TARGET_RUNTIME_DLLS:exe>
  1486. COMMAND_EXPAND_LISTS
  1487. )
  1488. .. note::
  1489. :ref:`Imported Targets` are supported only if they know the location
  1490. of their ``.dll`` files. An imported ``SHARED`` library must have
  1491. :prop_tgt:`IMPORTED_LOCATION` set to its ``.dll`` file. See the
  1492. :ref:`add_library imported libraries <add_library imported libraries>`
  1493. section for details. Many :ref:`Find Modules` produce imported targets
  1494. with the ``UNKNOWN`` type and therefore will be ignored.
  1495. On platforms that support runtime paths (``RPATH``), refer to the
  1496. :prop_tgt:`INSTALL_RPATH` target property.
  1497. On Apple platforms, refer to the :prop_tgt:`INSTALL_NAME_DIR` target property.
  1498. .. genex:: $<TARGET_RUNTIME_DLL_DIRS:tgt>
  1499. .. versionadded:: 3.27
  1500. List of the directories which contain the DLLs that the target depends on at
  1501. runtime (see :genex:`TARGET_RUNTIME_DLLS`). This is determined by
  1502. the locations of all the ``SHARED`` targets in the target's transitive
  1503. dependencies. Using this generator expression on targets other than
  1504. executables, ``SHARED`` libraries, and ``MODULE`` libraries is an error.
  1505. **On non-DLL platforms, this expression always evaluates to an empty string**.
  1506. This generator expression can e.g. be used to create a batch file using
  1507. :command:`file(GENERATE)` which sets the PATH environment variable accordingly.
  1508. Export And Install Expressions
  1509. ------------------------------
  1510. .. genex:: $<INSTALL_INTERFACE:...>
  1511. Content of ``...`` when the property is exported using
  1512. :command:`install(EXPORT)`, and empty otherwise.
  1513. .. genex:: $<BUILD_INTERFACE:...>
  1514. Content of ``...`` when the property is exported using :command:`export`, or
  1515. when the target is used by another target in the same buildsystem. Expands to
  1516. the empty string otherwise.
  1517. .. genex:: $<BUILD_LOCAL_INTERFACE:...>
  1518. .. versionadded:: 3.26
  1519. Content of ``...`` when the target is used by another target in the same
  1520. buildsystem. Expands to the empty string otherwise.
  1521. .. genex:: $<INSTALL_PREFIX>
  1522. Content of the install prefix when the target is exported via
  1523. :command:`install(EXPORT)`, or when evaluated in the
  1524. :prop_tgt:`INSTALL_NAME_DIR` property, the ``INSTALL_NAME_DIR`` argument of
  1525. :command:`install(RUNTIME_DEPENDENCY_SET)`, the code argument of
  1526. :command:`install(CODE)`, or the file argument of :command:`install(SCRIPT)`,
  1527. and empty otherwise.
  1528. Multi-level Expression Evaluation
  1529. ---------------------------------
  1530. .. genex:: $<GENEX_EVAL:expr>
  1531. .. versionadded:: 3.12
  1532. Content of ``expr`` evaluated as a generator expression in the current
  1533. context. This enables consumption of generator expressions whose
  1534. evaluation results itself in generator expressions.
  1535. .. genex:: $<TARGET_GENEX_EVAL:tgt,expr>
  1536. .. versionadded:: 3.12
  1537. Content of ``expr`` evaluated as a generator expression in the context of
  1538. ``tgt`` target. This enables consumption of custom target properties that
  1539. themselves contain generator expressions.
  1540. Having the capability to evaluate generator expressions is very useful when
  1541. you want to manage custom properties supporting generator expressions.
  1542. For example:
  1543. .. code-block:: cmake
  1544. add_library(foo ...)
  1545. set_property(TARGET foo PROPERTY
  1546. CUSTOM_KEYS $<$<CONFIG:DEBUG>:FOO_EXTRA_THINGS>
  1547. )
  1548. add_custom_target(printFooKeys
  1549. COMMAND ${CMAKE_COMMAND} -E echo $<TARGET_PROPERTY:foo,CUSTOM_KEYS>
  1550. )
  1551. This naive implementation of the ``printFooKeys`` custom command is wrong
  1552. because ``CUSTOM_KEYS`` target property is not evaluated and the content
  1553. is passed as is (i.e. ``$<$<CONFIG:DEBUG>:FOO_EXTRA_THINGS>``).
  1554. To have the expected result (i.e. ``FOO_EXTRA_THINGS`` if config is
  1555. ``Debug``), it is required to evaluate the output of
  1556. ``$<TARGET_PROPERTY:foo,CUSTOM_KEYS>``:
  1557. .. code-block:: cmake
  1558. add_custom_target(printFooKeys
  1559. COMMAND ${CMAKE_COMMAND} -E
  1560. echo $<TARGET_GENEX_EVAL:foo,$<TARGET_PROPERTY:foo,CUSTOM_KEYS>>
  1561. )
  1562. Escaped Characters
  1563. ------------------
  1564. These expressions evaluate to specific string literals. Use them in place of
  1565. the actual string literal where you need to prevent them from having their
  1566. special meaning.
  1567. .. genex:: $<ANGLE-R>
  1568. A literal ``>``. Used for example to compare strings that contain a ``>``.
  1569. .. genex:: $<COMMA>
  1570. A literal ``,``. Used for example to compare strings which contain a ``,``.
  1571. .. genex:: $<SEMICOLON>
  1572. A literal ``;``. Used to prevent list expansion on an argument with ``;``.
  1573. Deprecated Expressions
  1574. ----------------------
  1575. .. genex:: $<CONFIGURATION>
  1576. Configuration name. Deprecated since CMake 3.0. Use :genex:`CONFIG` instead.