cmake-generator-expressions.7.rst 76 KB

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