cmake-generator-expressions.7.rst 109 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349
  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. For tools that expect ``-I``'s value to be a separate argument, use the
  90. semicolon trick learned earlier:
  91. .. code-block:: cmake
  92. add_custom_target(run_some_tool
  93. COMMAND some_tool "$<LIST:TRANSFORM,$<TARGET_PROPERTY:tgt,INCLUDE_DIRECTORIES>,PREPEND,-I;>"
  94. COMMAND_EXPAND_LISTS
  95. VERBATIM
  96. )
  97. A common mistake is to try to split a generator expression across multiple
  98. lines with indenting:
  99. .. code-block:: cmake
  100. # WRONG: New lines and spaces all treated as argument separators, so the
  101. # generator expression is split and not recognized correctly.
  102. target_compile_definitions(tgt PRIVATE
  103. $<$<AND:
  104. $<CXX_COMPILER_ID:GNU>,
  105. $<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,5>
  106. >:HAVE_5_OR_LATER>
  107. )
  108. Again, use helper variables with well-chosen names to build up a readable
  109. expression instead:
  110. .. code-block:: cmake
  111. set(is_gnu "$<CXX_COMPILER_ID:GNU>")
  112. set(v5_or_later "$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,5>")
  113. set(meet_requirements "$<AND:${is_gnu},${v5_or_later}>")
  114. target_compile_definitions(tgt PRIVATE
  115. "$<${meet_requirements}:HAVE_5_OR_LATER>"
  116. )
  117. Debugging
  118. =========
  119. Since generator expressions are evaluated during generation of the buildsystem,
  120. and not during processing of ``CMakeLists.txt`` files, it is not possible to
  121. inspect their result with the :command:`message()` command. One possible way
  122. to generate debug messages is to add a custom target:
  123. .. code-block:: cmake
  124. add_custom_target(genexdebug COMMAND ${CMAKE_COMMAND} -E echo "$<...>")
  125. After running :program:`cmake`, you can then build the ``genexdebug`` target to print
  126. the result of the ``$<...>`` expression (i.e. run the command
  127. :option:`cmake --build ... --target genexdebug <cmake--build --target>`).
  128. Another way is to write debug messages to a file with :command:`file(GENERATE)`:
  129. .. code-block:: cmake
  130. file(GENERATE OUTPUT filename CONTENT "$<...>")
  131. Generator Expression Reference
  132. ==============================
  133. .. note::
  134. This reference deviates from most of the CMake documentation in that it
  135. omits angular brackets ``<...>`` around placeholders like ``condition``,
  136. ``string``, ``target``, etc. This is to prevent an opportunity for those
  137. placeholders to be misinterpreted as generator expressions.
  138. .. _`Conditional Generator Expressions`:
  139. Conditional Expressions
  140. -----------------------
  141. A fundamental category of generator expressions relates to conditional logic.
  142. Two forms of conditional generator expressions are supported:
  143. .. genex:: $<condition:true_string>
  144. Evaluates to ``true_string`` if ``condition`` is ``1``, or an empty string
  145. if ``condition`` evaluates to ``0``. Any other value for ``condition``
  146. results in an error.
  147. .. genex:: $<IF:condition,true_string,false_string>
  148. .. versionadded:: 3.8
  149. Evaluates to ``true_string`` if ``condition`` is ``1``, or ``false_string``
  150. if ``condition`` is ``0``. Any other value for ``condition`` results in an
  151. error.
  152. .. versionadded:: 3.28
  153. This generator expression short-circuits such that generator expressions in
  154. ``false_string`` will not evaluate when ``condition`` is ``1``, and generator
  155. expressions in ``true_string`` will not evaluate when condition is ``0``.
  156. Typically, the ``condition`` is itself a generator expression. For instance,
  157. the following expression expands to ``DEBUG_MODE`` when the ``Debug``
  158. configuration is used, and the empty string for all other configurations:
  159. .. code-block:: cmake
  160. $<$<CONFIG:Debug>:DEBUG_MODE>
  161. Boolean-like ``condition`` values other than ``1`` or ``0`` can be handled
  162. by wrapping them with the ``$<BOOL:...>`` generator expression:
  163. .. genex:: $<BOOL:string>
  164. Converts ``string`` to ``0`` or ``1``. Evaluates to ``0`` if any of the
  165. following is true:
  166. * ``string`` is empty,
  167. * ``string`` is a case-insensitive equal of
  168. ``0``, ``FALSE``, ``OFF``, ``N``, ``NO``, ``IGNORE``, or ``NOTFOUND``, or
  169. * ``string`` ends in the suffix ``-NOTFOUND`` (case-sensitive).
  170. Otherwise evaluates to ``1``.
  171. The ``$<BOOL:...>`` generator expression is often used when a ``condition``
  172. is provided by a CMake variable:
  173. .. code-block:: cmake
  174. $<$<BOOL:${HAVE_SOME_FEATURE}>:-DENABLE_SOME_FEATURE>
  175. .. _`Boolean Generator Expressions`:
  176. Logical Operators
  177. -----------------
  178. The common boolean logic operators are supported:
  179. .. genex:: $<AND:conditions>
  180. where ``conditions`` is a comma-separated list of boolean expressions,
  181. all of which must evaluate to either ``1`` or ``0``. The whole expression
  182. evaluates to ``1`` if all conditions are ``1``. If any condition is ``0``,
  183. the whole expression evaluates to ``0``.
  184. .. genex:: $<OR:conditions>
  185. where ``conditions`` is a comma-separated list of boolean expressions.
  186. all of which must evaluate to either ``1`` or ``0``. The whole expression
  187. evaluates to ``1`` if at least one of the ``conditions`` is ``1``. If all
  188. ``conditions`` evaluate to ``0``, the whole expression evaluates to ``0``.
  189. .. genex:: $<NOT:condition>
  190. ``condition`` must be ``0`` or ``1``. The result of the expression is
  191. ``0`` if ``condition`` is ``1``, else ``1``.
  192. .. versionadded:: 3.28
  193. Logical operators short-circuit such that generator expressions in the
  194. arguments list will not be evaluated once a return value can be determined.
  195. .. _`Comparison Expressions`:
  196. Primary Comparison Expressions
  197. ------------------------------
  198. CMake supports a variety of generator expressions that compare things.
  199. This section covers the primary and most widely used comparison types.
  200. Other more specific comparison types are documented in their own separate
  201. sections further below.
  202. Numeric Comparisons
  203. ^^^^^^^^^^^^^^^^^^^
  204. .. genex:: $<EQUAL:value1,value2>
  205. ``1`` if ``value1`` and ``value2`` are numerically equal, else ``0``.
  206. Version Comparisons
  207. ^^^^^^^^^^^^^^^^^^^
  208. .. genex:: $<VERSION_LESS:v1,v2>
  209. ``1`` if ``v1`` is a version less than ``v2``, else ``0``.
  210. .. genex:: $<VERSION_GREATER:v1,v2>
  211. ``1`` if ``v1`` is a version greater than ``v2``, else ``0``.
  212. .. genex:: $<VERSION_EQUAL:v1,v2>
  213. ``1`` if ``v1`` is the same version as ``v2``, else ``0``.
  214. .. genex:: $<VERSION_LESS_EQUAL:v1,v2>
  215. .. versionadded:: 3.7
  216. ``1`` if ``v1`` is a version less than or equal to ``v2``, else ``0``.
  217. .. genex:: $<VERSION_GREATER_EQUAL:v1,v2>
  218. .. versionadded:: 3.7
  219. ``1`` if ``v1`` is a version greater than or equal to ``v2``, else ``0``.
  220. String Expressions
  221. ------------------
  222. Most of the expressions in this section are closely associated with the
  223. :command:`string` command, providing the same capabilities, but in
  224. the form of a generator expression.
  225. In each of the following string-related generator expressions, the ``string``
  226. must not contain any commas if that generator expression expects something to
  227. be provided after the ``string``. For example, the expression
  228. ``$<STRING:FIND,string,value>`` requires a ``value`` after the ``string``.
  229. Since a comma is used to separate the ``string`` and the ``value``, the
  230. ``string`` cannot itself contain a comma. This restriction does not apply to
  231. the :command:`string` command, it is specific to the string-handling generator
  232. expressions only. The :genex:`$<COMMA>` generator expression can be used to
  233. specify a comma as part of the arguments of the string-related generator
  234. expressions.
  235. .. _`String Comparisons Generator Expressions`:
  236. String Comparisons
  237. ^^^^^^^^^^^^^^^^^^
  238. The comparisons are case-sensitive. For a case-insensitive comparison,
  239. combine with a :ref:`string transforming generator expression
  240. <String Transforming Generator Expressions>`. For example, the following
  241. evaluates to ``1`` if ``${foo}`` is any of ``BAR``, ``Bar``, ``bar``, etc.
  242. .. code-block:: cmake
  243. $<STREQUAL:$<STRING:TOUPPER,${foo}>,BAR>
  244. .. genex:: $<STREQUAL:string1,string2>
  245. ``1`` if ``string1`` and ``string2`` are lexicographically equal, else ``0``.
  246. .. genex:: $<STRLESS:string1,string2>
  247. .. versionadded:: 4.3
  248. ``1`` if ``string1`` is lexicographically less than ``string2``, else ``0``.
  249. .. genex:: $<STRGREATER:string1,string2>
  250. .. versionadded:: 4.3
  251. ``1`` if ``string1`` is lexicographically greater than ``string2``, else
  252. ``0``.
  253. .. genex:: $<STRLESS_EQUAL:string1,string2>
  254. .. versionadded:: 4.3
  255. ``1`` if ``string1`` is lexicographically less than or equal to ``string2``,
  256. else ``0``.
  257. .. genex:: $<STRGREATER_EQUAL:string1,string2>
  258. .. versionadded:: 4.3
  259. ``1`` if ``string1`` is lexicographically greater than or equal to
  260. ``string2``, else ``0``.
  261. .. _`String Queries Generator Expressions`:
  262. String Queries
  263. ^^^^^^^^^^^^^^
  264. .. genex:: $<STRING:LENGTH,string>
  265. .. versionadded:: 4.3
  266. The given string's length in bytes. Note that this means, if ``string``
  267. contains multi-byte characters, the result will *not* be the number of
  268. characters.
  269. .. genex:: $<STRING:SUBSTRING,string,begin,length>
  270. .. versionadded:: 4.3
  271. The substring of the given ``string``. If ``length`` is ``-1`` or greater
  272. than the ``string`` length the remainder of the string starting at ``begin``
  273. will be returned.
  274. Both ``begin`` and ``length`` are counted in bytes, so care must
  275. be exercised if ``string`` could contain multi-byte characters.
  276. .. genex:: $<STRING:FIND,string[,FROM:(BEGIN|END)],substring>
  277. The position where the given ``substring`` was found in the supplied
  278. ``string``. If the ``substring`` is not found, a position of -1 is returned.
  279. The ``FROM:`` option defines how the search will be done:
  280. ``BEGIN``
  281. The search will start at the beginning of the ``string``. This the default.
  282. ``END``
  283. The search will start from the end of the ``string``.
  284. The ``$<STRING:FIND>`` generator expression treats all strings as ASCII-only
  285. characters. The index returned will also be counted in bytes, so strings
  286. containing multi-byte characters may lead to unexpected results.
  287. .. genex:: $<STRING:MATCH,string[,SEEK:(ONCE|ALL)],regular_expression>
  288. .. versionadded:: 4.3
  289. Match, in the ``string``, the ``regular_expression``.
  290. The ``SEEK:`` option specifies the match behavior:
  291. ``ONCE``
  292. Match only the first occurrence. This is the default.
  293. ``ALL``
  294. Match as many times as possible and return the matches as a list.
  295. See the :ref:`Regular expressions specification <Regex Specification>` for
  296. the syntax of the ``regular_expression`` parameter.
  297. .. _`String Generating Generator Expressions`:
  298. String Generations
  299. ^^^^^^^^^^^^^^^^^^
  300. .. genex:: $<STRING:JOIN,glue,input[,input]...>
  301. .. versionadded:: 4.3
  302. Join all the ``input`` arguments together using the ``glue`` string.
  303. .. genex:: $<STRING:ASCII,number[,number]...>
  304. .. versionadded:: 4.3
  305. Convert all numbers, in the range 1-255, into corresponding ASCII
  306. characters. Any number outside this range will raise an error.
  307. .. genex:: $<STRING:TIMESTAMP[,(UTC|format)]...>
  308. .. versionadded:: 4.3
  309. Produce a string representation of the current date and/or time.
  310. If the generator expression is unable to obtain a timestamp, the result will
  311. be the empty string ``""``.
  312. The optional ``UTC`` flag requests the current date/time representation to
  313. be in Coordinated Universal Time (UTC) rather than local time.
  314. If the ``SOURCE_DATE_EPOCH`` environment variable is set, its value will be
  315. used instead of the current time.
  316. See https://reproducible-builds.org/specs/source-date-epoch/ for details.
  317. The optional ``<format>`` may contain the following format specifiers:
  318. ``%%``
  319. A literal percent sign (%).
  320. ``%d``
  321. The day of the current month (01-31).
  322. ``%H``
  323. The hour on a 24-hour clock (00-23).
  324. ``%I``
  325. The hour on a 12-hour clock (01-12).
  326. ``%j``
  327. The day of the current year (001-366).
  328. ``%m``
  329. The month of the current year (01-12).
  330. ``%b``
  331. Abbreviated month name (e.g. Oct).
  332. ``%B``
  333. Full month name (e.g. October).
  334. ``%M``
  335. The minute of the current hour (00-59).
  336. ``%s``
  337. Seconds since midnight (UTC) 1-Jan-1970 (UNIX time).
  338. ``%S``
  339. The second of the current minute. 60 represents a leap second. (00-60)
  340. ``%f``
  341. The microsecond of the current second (000000-999999).
  342. ``%U``
  343. The week number of the current year (00-53).
  344. ``%V``
  345. The ISO 8601 week number of the current year (01-53).
  346. ``%w``
  347. The day of the current week. 0 is Sunday. (0-6)
  348. ``%a``
  349. Abbreviated weekday name (e.g. Fri).
  350. ``%A``
  351. Full weekday name (e.g. Friday).
  352. ``%y``
  353. The last two digits of the current year (00-99).
  354. ``%Y``
  355. The current year.
  356. ``%z``
  357. The offset of the time zone from UTC, in hours and minutes,
  358. with format ``+hhmm`` or ``-hhmm``.
  359. ``%Z``
  360. The time zone name.
  361. Unknown format specifiers will be ignored and copied to the output
  362. as-is.
  363. If no explicit ``format`` is given, it will default to:
  364. * ``%Y-%m-%dT%H:%M:%S`` for local time.
  365. * ``%Y-%m-%dT%H:%M:%SZ`` for UTC.
  366. .. genex:: $<STRING:RANDOM[,(LENGTH:length|ALPHABET:alphabet|RANDOM_SEED:seed)]...>
  367. .. versionadded:: 4.3
  368. Produce a random string of ASCII characters. The possible options are:
  369. ``LENGTH:length``
  370. Define the length of the string. The default length is 5 characters.
  371. ``ALPHABET:alphabet``
  372. Define the characters used for the generation. The alphabet is always
  373. interpreted as holding ASCII characters. The default alphabet is all
  374. numbers and upper and lower case letters.
  375. ``RANDOM_SEED:seed``
  376. Specify an integer which will be used to seed the random number generator.
  377. .. genex:: $<STRING:UUID,NAMESPACE:namespace,TYPE:(MD5|SHA1)[,NAME:name][,CASE:(LOWER|UPPER)]>
  378. .. versionadded:: 4.3
  379. Create a universally unique identifier (aka GUID) as per RFC4122.
  380. A UUID has the format ``xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx``
  381. where each ``x`` represents an hexadecimal character.
  382. The UUID is based on the hash of the combined values of:
  383. ``NAMESPACE:namespace``
  384. ``namespace`` which has to be a valid UUID.
  385. ``NAME:name``
  386. ``name`` is an arbitrary string.
  387. ``TYPE:``
  388. The hash algorithm can be either:
  389. ``MD5``
  390. Version 3 UUID.
  391. ``SHA1``
  392. Version 5 UUID.
  393. ``CASE:``
  394. Specify the case of the hexadecimal characters.
  395. ``LOWER``
  396. Hexadecimal characters are all of lowercase. This is the default.
  397. ``UPPER``
  398. Hexadecimal characters are all of uppercase.
  399. .. _`String Transforming Generator Expressions`:
  400. String Transformations
  401. ^^^^^^^^^^^^^^^^^^^^^^
  402. .. genex:: $<STRING:REPLACE[,(STRING|REGEX)],string,match_string,replace_string>
  403. .. versionadded:: 4.3
  404. Replace all occurrences of ``match_string`` in the ``string`` with
  405. ``replace_string``.
  406. The ``match_string`` can be of two different types:
  407. ``STRING``
  408. ``match_string`` is a literal string and match will be done by simple
  409. string comparison. This is the default.
  410. ``REGEX``
  411. ``match_string`` is a regular expression. Match this regular_expression as
  412. many times as possible and substitute the ``replace_string`` for the match
  413. in the ``string``.
  414. The ``replace_string`` may refer to parenthesis-delimited subexpressions of
  415. the match using \\1, \\2, ..., \\9. Note that two backslashes (\\\\1) are
  416. required in CMake code to get a backslash through argument parsing.
  417. .. genex:: $<STRING:APPEND,string,input[,input]...>
  418. .. versionadded:: 4.3
  419. Append all the ``input`` arguments to the ``string``.
  420. .. genex:: $<STRING:PREPEND,string,input[,input]...>
  421. .. versionadded:: 4.3
  422. Prepend all the ``input`` arguments to the ``string``.
  423. .. genex:: $<STRING:TOLOWER,string>
  424. .. versionadded:: 4.3
  425. Content of ``string`` converted to lower case.
  426. .. genex:: $<STRING:TOUPPER,string>
  427. .. versionadded:: 4.3
  428. Content of ``string`` converted to upper case.
  429. .. genex:: $<STRING:STRIP,SPACES,string>
  430. .. versionadded:: 4.3
  431. Remove the specified elements from the ``string``. The possible options are:
  432. ``SPACES``
  433. Remove the leading and trailing spaces of the ``string``.
  434. .. genex:: $<STRING:QUOTE,REGEX,string>
  435. .. versionadded:: 4.3
  436. Escape the specified elements of the ``string``. The possible options are:
  437. ``REGEX``
  438. Escape all characters that have special meaning in a regular expressions,
  439. such that the ``string`` can be used as part of a regular expression to
  440. match the input literally.
  441. .. genex:: $<STRING:HEX,string>
  442. .. versionadded:: 4.3
  443. Convert each byte in the ``string`` to its hexadecimal representation.
  444. Letters in the result (a through f) are in lowercase.
  445. .. genex:: $<STRING:HASH,string,ALGORITHM:algorithm>
  446. .. versionadded:: 4.3
  447. Compute a cryptographic hash of the ``string``. The supported algorithm
  448. names, as specified by the ``ALGORITHM:`` option are:
  449. ``MD5``
  450. Message-Digest Algorithm 5, RFC 1321.
  451. ``SHA1``
  452. US Secure Hash Algorithm 1, RFC 3174.
  453. ``SHA224``
  454. US Secure Hash Algorithms, RFC 4634.
  455. ``SHA256``
  456. US Secure Hash Algorithms, RFC 4634.
  457. ``SHA384``
  458. US Secure Hash Algorithms, RFC 4634.
  459. ``SHA512``
  460. US Secure Hash Algorithms, RFC 4634.
  461. ``SHA3_224``
  462. Keccak SHA-3.
  463. ``SHA3_256``
  464. Keccak SHA-3.
  465. ``SHA3_384``
  466. Keccak SHA-3.
  467. ``SHA3_512``
  468. Keccak SHA-3.
  469. .. genex:: $<STRING:MAKE_C_IDENTIFIER,string>
  470. .. versionadded:: 4.3
  471. Convert each non-alphanumeric character in the ``string`` to an underscore.
  472. If the first character of the ``string`` is a digit, an underscore will also
  473. be prepended.
  474. .. genex:: $<LOWER_CASE:string>
  475. Content of ``string`` converted to lower case.
  476. .. genex:: $<UPPER_CASE:string>
  477. Content of ``string`` converted to upper case.
  478. .. genex:: $<MAKE_C_IDENTIFIER:string>
  479. Content of ``string`` converted to a C identifier. The conversion follows
  480. the same behavior as :command:`string(MAKE_C_IDENTIFIER)`.
  481. List Expressions
  482. ----------------
  483. Most of the expressions in this section are closely associated with the
  484. :command:`list` command, providing the same capabilities, but in
  485. the form of a generator expression.
  486. In each of the following list-related generator expressions, the ``list``
  487. must not contain any commas if that generator expression expects something to
  488. be provided after the ``list``. For example, the expression
  489. ``$<LIST:FIND,list,value>`` requires a ``value`` after the ``list``.
  490. Since a comma is used to separate the ``list`` and the ``value``, the ``list``
  491. cannot itself contain a comma. This restriction does not apply to the
  492. :command:`list` command, it is specific to the list-handling generator
  493. expressions only.
  494. .. _GenEx List Comparisons:
  495. List Comparisons
  496. ^^^^^^^^^^^^^^^^
  497. .. genex:: $<IN_LIST:string,list>
  498. .. versionadded:: 3.12
  499. ``1`` if ``string`` is an item in the semicolon-separated ``list``, else ``0``.
  500. It uses case-sensitive comparisons.
  501. .. _GenEx List Queries:
  502. List Queries
  503. ^^^^^^^^^^^^
  504. .. genex:: $<LIST:LENGTH,list>
  505. .. versionadded:: 3.27
  506. The number of items in the ``list``.
  507. .. genex:: $<LIST:GET,list,index,...>
  508. .. versionadded:: 3.27
  509. Expands to the list of items specified by indices from the ``list``.
  510. .. genex:: $<LIST:SUBLIST,list,begin,length>
  511. .. versionadded:: 3.27
  512. A sublist of the given ``list``. If ``length`` is 0, an empty list
  513. will be returned. If ``length`` is -1 or the list is smaller than
  514. ``begin + length``, the remaining items of the list starting at
  515. ``begin`` will be returned.
  516. .. genex:: $<LIST:FIND,list,value>
  517. .. versionadded:: 3.27
  518. The index of the first item in ``list`` with the specified ``value``,
  519. or -1 if ``value`` is not in the ``list``.
  520. .. _GenEx List Transformations:
  521. List Transformations
  522. ^^^^^^^^^^^^^^^^^^^^
  523. .. _GenEx LIST-JOIN:
  524. .. genex:: $<LIST:JOIN,list,glue>
  525. .. versionadded:: 3.27
  526. Converts ``list`` to a single string with the content of the ``glue`` string
  527. inserted between each item. This is conceptually the same operation as
  528. :genex:`$<JOIN:list,glue>`, but the two have different behavior with regard
  529. to empty items. ``$<LIST:JOIN,list,glue>`` preserves all empty items,
  530. whereas :genex:`$<JOIN:list,glue>` drops all empty items from the list.
  531. .. genex:: $<LIST:APPEND,list,item,...>
  532. .. versionadded:: 3.27
  533. The ``list`` with each ``item`` appended. Multiple items should be
  534. separated by commas.
  535. .. genex:: $<LIST:PREPEND,list,item,...>
  536. .. versionadded:: 3.27
  537. The ``list`` with each ``item`` inserted at the beginning. If there are
  538. multiple items, they should be separated by commas, and the order of the
  539. prepended items will be preserved.
  540. .. genex:: $<LIST:INSERT,list,index,item,...>
  541. .. versionadded:: 3.27
  542. The ``list`` with the ``item`` (or multiple items) inserted at the specified
  543. ``index``. Multiple items should be separated by commas.
  544. It is an error to specify an out-of-range ``index``. Valid indexes are 0 to N,
  545. where N is the length of the list, inclusive. An empty list has length 0.
  546. .. genex:: $<LIST:POP_BACK,list>
  547. .. versionadded:: 3.27
  548. The ``list`` with the last item removed.
  549. .. genex:: $<LIST:POP_FRONT,list>
  550. .. versionadded:: 3.27
  551. The ``list`` with the first item removed.
  552. .. genex:: $<LIST:REMOVE_ITEM,list,value,...>
  553. .. versionadded:: 3.27
  554. The ``list`` with all instances of the given ``value`` (or values) removed.
  555. If multiple values are given, they should be separated by commas.
  556. .. genex:: $<LIST:REMOVE_AT,list,index,...>
  557. .. versionadded:: 3.27
  558. The ``list`` with the item at each given ``index`` removed.
  559. .. _GenEx LIST-REMOVE_DUPLICATES:
  560. .. genex:: $<LIST:REMOVE_DUPLICATES,list>
  561. .. versionadded:: 3.27
  562. The ``list`` with all duplicated items removed. The relative order of
  563. items is preserved, but if duplicates are encountered, only the first
  564. instance is preserved. The result is the same as
  565. :genex:`$<REMOVE_DUPLICATES:list>`.
  566. .. _GenEx LIST-FILTER:
  567. .. genex:: $<LIST:FILTER,list,INCLUDE|EXCLUDE,regex>
  568. .. versionadded:: 3.27
  569. A list of items from the ``list`` which match (``INCLUDE``) or do not match
  570. (``EXCLUDE``) the regular expression ``regex``. The result is the same as
  571. :genex:`$<FILTER:list,INCLUDE|EXCLUDE,regex>`.
  572. .. genex:: $<LIST:TRANSFORM,list,ACTION[,SELECTOR]>
  573. .. versionadded:: 3.27
  574. The ``list`` transformed by applying an ``ACTION`` to all or, by
  575. specifying a ``SELECTOR``, to the selected list items.
  576. .. note::
  577. The ``TRANSFORM`` sub-command does not change the number of items in the
  578. list. If a ``SELECTOR`` is specified, only some items will be changed,
  579. the other ones will remain the same as before the transformation.
  580. ``ACTION`` specifies the action to apply to the items of the list.
  581. The actions have exactly the same semantics as for the
  582. :command:`list(TRANSFORM)` command. ``ACTION`` must be one of the following:
  583. :command:`APPEND <list(TRANSFORM_APPEND)>`, :command:`PREPEND <list(TRANSFORM_APPEND)>`
  584. Append, prepend specified value to each item of the list.
  585. .. code-block:: cmake
  586. $<LIST:TRANSFORM,list,(APPEND|PREPEND),value[,SELECTOR]>
  587. :command:`TOLOWER <list(TRANSFORM_TOLOWER)>`, :command:`TOUPPER <list(TRANSFORM_TOLOWER)>`
  588. Convert each item of the list to lower, upper characters.
  589. .. code-block:: cmake
  590. $<LIST:TRANSFORM,list,(TOLOWER|TOUPPER)[,SELECTOR]>
  591. :command:`STRIP <list(TRANSFORM_STRIP)>`
  592. Remove leading and trailing spaces from each item of the list.
  593. .. code-block:: cmake
  594. $<LIST:TRANSFORM,list,STRIP[,SELECTOR]>
  595. :command:`REPLACE <list(TRANSFORM_REPLACE)>`:
  596. Match the regular expression as many times as possible and substitute
  597. the replacement expression for the match for each item of the list.
  598. .. code-block:: cmake
  599. $<LIST:TRANSFORM,list,REPLACE,regular_expression,replace_expression[,SELECTOR]>
  600. .. versionchanged:: 4.1
  601. The ``^`` anchor now matches only at the beginning of the input
  602. element instead of the beginning of each repeated search.
  603. See policy :policy:`CMP0186`.
  604. ``SELECTOR`` determines which items of the list will be transformed.
  605. Only one type of selector can be specified at a time. When given,
  606. ``SELECTOR`` must be one of the following:
  607. ``AT``
  608. Specify a list of indexes.
  609. .. code-block:: cmake
  610. $<LIST:TRANSFORM,list,ACTION,AT,index[,index...]>
  611. ``FOR``
  612. Specify a range with, optionally, an increment used to iterate over the
  613. range.
  614. .. code-block:: cmake
  615. $<LIST:TRANSFORM,list,ACTION,FOR,start,stop[,step]>
  616. ``REGEX``
  617. Specify a regular expression.
  618. Only items matching the regular expression will be transformed.
  619. .. code-block:: cmake
  620. $<LIST:TRANSFORM,list,ACTION,REGEX,regular_expression>
  621. .. genex:: $<JOIN:list,glue>
  622. Joins the ``list`` with the content of the ``glue`` string inserted between
  623. each item. This is conceptually the same operation as
  624. :ref:`$\<LIST:JOIN,list,glue\> <GenEx LIST-JOIN>`, but the two have
  625. different behavior with regard to empty items.
  626. :ref:`$\<LIST:JOIN,list,glue\> <GenEx LIST-JOIN>` preserves all empty items,
  627. whereas ``$<JOIN:list,glue>`` drops all empty items from the list.
  628. .. genex:: $<REMOVE_DUPLICATES:list>
  629. .. versionadded:: 3.15
  630. Removes duplicated items in the given ``list``. The relative order of items
  631. is preserved, and if duplicates are encountered, only the first instance is
  632. retained. The result is the same as
  633. :ref:`$\<LIST:REMOVE_DUPLICATES,list\> <GenEx LIST-REMOVE_DUPLICATES>`.
  634. .. genex:: $<FILTER:list,INCLUDE|EXCLUDE,regex>
  635. .. versionadded:: 3.15
  636. Includes or removes items from ``list`` that match the regular expression
  637. ``regex``. The result is the same as
  638. :ref:`$\<LIST:FILTER,list,INCLUDE|EXCLUDE,regex\> <GenEx LIST-FILTER>`.
  639. .. _GenEx List Ordering:
  640. List Ordering
  641. ^^^^^^^^^^^^^
  642. .. genex:: $<LIST:REVERSE,list>
  643. .. versionadded:: 3.27
  644. The ``list`` with the items in reverse order.
  645. .. genex:: $<LIST:SORT,list[,(COMPARE:option|CASE:option|ORDER:option)]...>
  646. .. versionadded:: 3.27
  647. The ``list`` sorted according to the specified options.
  648. Use one of the ``COMPARE`` options to select the comparison method
  649. for sorting:
  650. ``STRING``
  651. Sorts a list of strings alphabetically.
  652. This is the default behavior if the ``COMPARE`` option is not given.
  653. ``FILE_BASENAME``
  654. Sorts a list of file paths by their basenames.
  655. ``NATURAL``
  656. Sorts a list of strings using natural order (see the man page for
  657. ``strverscmp(3)``), such that contiguous digits are compared as whole
  658. numbers. For example, the following list ``10.0 1.1 2.1 8.0 2.0 3.1``
  659. will be sorted as ``1.1 2.0 2.1 3.1 8.0 10.0`` if the ``NATURAL``
  660. comparison is selected, whereas it will be sorted as
  661. ``1.1 10.0 2.0 2.1 3.1 8.0`` with the ``STRING`` comparison.
  662. Use one of the ``CASE`` options to select a case-sensitive or
  663. case-insensitive sort mode:
  664. ``SENSITIVE``
  665. List items are sorted in a case-sensitive manner.
  666. This is the default behavior if the ``CASE`` option is not given.
  667. ``INSENSITIVE``
  668. List items are sorted in a case-insensitive manner. The order of
  669. items which differ only by upper/lowercase is not specified.
  670. To control the sort order, one of the ``ORDER`` options can be given:
  671. ``ASCENDING``
  672. Sorts the list in ascending order.
  673. This is the default behavior when the ``ORDER`` option is not given.
  674. ``DESCENDING``
  675. Sorts the list in descending order.
  676. Options can be specified in any order, but it is an error to specify the
  677. same option multiple times.
  678. .. code-block:: cmake
  679. $<LIST:SORT,list,CASE:SENSITIVE,COMPARE:STRING,ORDER:DESCENDING>
  680. Path Expressions
  681. ----------------
  682. Most of the expressions in this section are closely associated with the
  683. :command:`cmake_path` command, providing the same capabilities, but in
  684. the form of a generator expression.
  685. For all generator expressions in this section, paths are expected to be in
  686. cmake-style format. The :ref:`$\<PATH:CMAKE_PATH\> <GenEx PATH-CMAKE_PATH>`
  687. generator expression can be used to convert a native path to a cmake-style
  688. one.
  689. .. _GenEx Path Comparisons:
  690. Path Comparisons
  691. ^^^^^^^^^^^^^^^^
  692. .. genex:: $<PATH_EQUAL:path1,path2>
  693. .. versionadded:: 3.24
  694. Compares the lexical representations of two paths. No normalization is
  695. performed on either path. Returns ``1`` if the paths are equal, ``0``
  696. otherwise.
  697. See :ref:`cmake_path(COMPARE) <Path Comparison>` for more details.
  698. .. _GenEx Path Queries:
  699. Path Queries
  700. ^^^^^^^^^^^^
  701. These expressions provide the generation-time capabilities equivalent to the
  702. :ref:`Query <Path Query>` options of the :command:`cmake_path` command.
  703. All paths are expected to be in cmake-style format.
  704. .. genex:: $<PATH:HAS_*,path>
  705. .. versionadded:: 3.24
  706. The following operations return ``1`` if the particular path component is
  707. present, ``0`` otherwise. See :ref:`Path Structure And Terminology` for the
  708. meaning of each path component.
  709. .. code-block:: cmake
  710. $<PATH:HAS_ROOT_NAME,path>
  711. $<PATH:HAS_ROOT_DIRECTORY,path>
  712. $<PATH:HAS_ROOT_PATH,path>
  713. $<PATH:HAS_FILENAME,path>
  714. $<PATH:HAS_EXTENSION,path>
  715. $<PATH:HAS_STEM,path>
  716. $<PATH:HAS_RELATIVE_PART,path>
  717. $<PATH:HAS_PARENT_PATH,path>
  718. Note the following special cases:
  719. * For ``HAS_ROOT_PATH``, a true result will only be returned if at least one
  720. of ``root-name`` or ``root-directory`` is non-empty.
  721. * For ``HAS_PARENT_PATH``, the root directory is also considered to have a
  722. parent, which will be itself. The result is true except if the path
  723. consists of just a :ref:`filename <FILENAME_DEF>`.
  724. .. genex:: $<PATH:IS_ABSOLUTE,path>
  725. .. versionadded:: 3.24
  726. Returns ``1`` if the path is absolute according to
  727. :command:`cmake_path(IS_ABSOLUTE)`, ``0`` otherwise.
  728. .. genex:: $<PATH:IS_RELATIVE,path>
  729. .. versionadded:: 3.24
  730. Returns ``1`` if the path is relative according to
  731. :command:`cmake_path(IS_RELATIVE)`, ``0`` otherwise.
  732. .. genex:: $<PATH:IS_PREFIX[,NORMALIZE],path,input>
  733. .. versionadded:: 3.24
  734. Returns ``1`` if ``path`` is the prefix of ``input``, ``0`` otherwise.
  735. When the ``NORMALIZE`` option is specified, ``path`` and ``input`` are
  736. :ref:`normalized <Normalization>` before the check.
  737. .. _GenEx Path Decomposition:
  738. Path Decomposition
  739. ^^^^^^^^^^^^^^^^^^
  740. These expressions provide the generation-time capabilities equivalent to the
  741. :ref:`Decomposition <Path Decomposition>` options of the :command:`cmake_path`
  742. command. All paths are expected to be in cmake-style format.
  743. .. genex:: $<PATH:GET_*,...>
  744. .. versionadded:: 3.24
  745. The following operations retrieve a different component or group of
  746. components from a path. See :ref:`Path Structure And Terminology` for the
  747. meaning of each path component.
  748. .. versionchanged:: 3.27
  749. All operations now accept a list of paths as argument. When a list of paths
  750. is specified, the operation will be applied to each path.
  751. .. code-block:: cmake
  752. $<PATH:GET_ROOT_NAME,path...>
  753. $<PATH:GET_ROOT_DIRECTORY,path...>
  754. $<PATH:GET_ROOT_PATH,path...>
  755. $<PATH:GET_FILENAME,path...>
  756. $<PATH:GET_EXTENSION[,LAST_ONLY],path...>
  757. $<PATH:GET_STEM[,LAST_ONLY],path...>
  758. $<PATH:GET_RELATIVE_PART,path...>
  759. $<PATH:GET_PARENT_PATH,path...>
  760. If a requested component is not present in the path, an empty string is
  761. returned.
  762. .. _GenEx Path Transformations:
  763. Path Transformations
  764. ^^^^^^^^^^^^^^^^^^^^
  765. These expressions provide the generation-time capabilities equivalent to the
  766. :ref:`Modification <Path Modification>` and :ref:`Generation <Path Generation>`
  767. options of the :command:`cmake_path` command. All paths are expected to be
  768. in cmake-style format.
  769. .. versionchanged:: 3.27
  770. All operations now accept a list of paths as argument. When a list of paths
  771. is specified, the operation will be applied to each path.
  772. .. _GenEx PATH-CMAKE_PATH:
  773. .. genex:: $<PATH:CMAKE_PATH[,NORMALIZE],path...>
  774. .. versionadded:: 3.24
  775. Returns ``path``. If ``path`` is a native path, it is converted into a
  776. cmake-style path with forward-slashes (``/``). On Windows, the long filename
  777. marker is taken into account.
  778. When the ``NORMALIZE`` option is specified, the path is :ref:`normalized
  779. <Normalization>` after the conversion.
  780. .. genex:: $<PATH:NATIVE_PATH[,NORMALIZE],path...>
  781. .. versionadded:: 4.0
  782. Returns ``path`` converted into a native format with platform-specific
  783. slashes (``\`` on Windows hosts and ``/`` elsewhere).
  784. When the ``NORMALIZE`` option is specified, the path is :ref:`normalized
  785. <Normalization>` before the conversion.
  786. .. genex:: $<PATH:APPEND,path...,input,...>
  787. .. versionadded:: 3.24
  788. Returns all the ``input`` arguments appended to ``path`` using ``/`` as the
  789. ``directory-separator``. Depending on the ``input``, the value of ``path``
  790. may be discarded.
  791. See :command:`cmake_path(APPEND)` for more details.
  792. .. genex:: $<PATH:REMOVE_FILENAME,path...>
  793. .. versionadded:: 3.24
  794. Returns ``path`` with filename component (as returned by
  795. ``$<PATH:GET_FILENAME>``) removed. After removal, any trailing
  796. ``directory-separator`` is left alone, if present.
  797. See :command:`cmake_path(REMOVE_FILENAME)` for more details.
  798. .. genex:: $<PATH:REPLACE_FILENAME,path...,input>
  799. .. versionadded:: 3.24
  800. Returns ``path`` with the filename component replaced by ``input``. If
  801. ``path`` has no filename component (i.e. ``$<PATH:HAS_FILENAME>`` returns
  802. ``0``), ``path`` is unchanged.
  803. See :command:`cmake_path(REPLACE_FILENAME)` for more details.
  804. .. genex:: $<PATH:REMOVE_EXTENSION[,LAST_ONLY],path...>
  805. .. versionadded:: 3.24
  806. Returns ``path`` with the :ref:`extension <EXTENSION_DEF>` removed, if any.
  807. See :command:`cmake_path(REMOVE_EXTENSION)` for more details.
  808. .. genex:: $<PATH:REPLACE_EXTENSION[,LAST_ONLY],path...,input>
  809. .. versionadded:: 3.24
  810. Returns ``path`` with the :ref:`extension <EXTENSION_DEF>` replaced by
  811. ``input``, if any.
  812. See :command:`cmake_path(REPLACE_EXTENSION)` for more details.
  813. .. genex:: $<PATH:NORMAL_PATH,path...>
  814. .. versionadded:: 3.24
  815. Returns ``path`` normalized according to the steps described in
  816. :ref:`Normalization`.
  817. .. genex:: $<PATH:RELATIVE_PATH,path...,base_directory>
  818. .. versionadded:: 3.24
  819. Returns ``path``, modified to make it relative to the ``base_directory``
  820. argument.
  821. See :command:`cmake_path(RELATIVE_PATH)` for more details.
  822. .. genex:: $<PATH:ABSOLUTE_PATH[,NORMALIZE],path...,base_directory>
  823. .. versionadded:: 3.24
  824. Returns ``path`` as absolute. If ``path`` is a relative path
  825. (``$<PATH:IS_RELATIVE>`` returns ``1``), it is evaluated relative to the
  826. given base directory specified by ``base_directory`` argument.
  827. When the ``NORMALIZE`` option is specified, the path is
  828. :ref:`normalized <Normalization>` after the path computation.
  829. See :command:`cmake_path(ABSOLUTE_PATH)` for more details.
  830. Shell Paths
  831. ^^^^^^^^^^^
  832. .. genex:: $<SHELL_PATH:...>
  833. .. versionadded:: 3.4
  834. Content of ``...`` converted to shell path style. For example, slashes are
  835. converted to backslashes in Windows shells and drive letters are converted
  836. to posix paths in MSYS shells. The ``...`` must be an absolute path.
  837. .. versionadded:: 3.14
  838. The ``...`` may be a :ref:`semicolon-separated list <CMake Language Lists>`
  839. of paths, in which case each path is converted individually and a result
  840. list is generated using the shell path separator (``:`` on POSIX and
  841. ``;`` on Windows). Be sure to enclose the argument containing this genex
  842. in double quotes in CMake source code so that ``;`` does not split arguments.
  843. Configuration Expressions
  844. -------------------------
  845. .. genex:: $<CONFIG>
  846. Configuration name. Use this instead of the deprecated :genex:`CONFIGURATION`
  847. generator expression.
  848. .. genex:: $<CONFIG:cfgs>
  849. ``1`` if config is any one of the entries in comma-separated list
  850. ``cfgs``, else ``0``. This is a case-insensitive comparison. The mapping in
  851. :prop_tgt:`MAP_IMPORTED_CONFIG_<CONFIG>` is also considered by this
  852. expression when it is evaluated on a property of an :prop_tgt:`IMPORTED`
  853. target.
  854. .. versionchanged:: 3.19
  855. Multiple configurations can be specified for ``cfgs``.
  856. CMake 3.18 and earlier only accepted a single configuration.
  857. .. genex:: $<OUTPUT_CONFIG:...>
  858. .. versionadded:: 3.20
  859. Only valid in :command:`add_custom_command` and :command:`add_custom_target`
  860. as the outer-most generator expression in an argument.
  861. With the :generator:`Ninja Multi-Config` generator, generator expressions
  862. in ``...`` are evaluated using the custom command's "output config".
  863. With other generators, the content of ``...`` is evaluated normally.
  864. .. genex:: $<COMMAND_CONFIG:...>
  865. .. versionadded:: 3.20
  866. Only valid in :command:`add_custom_command` and :command:`add_custom_target`
  867. as the outer-most generator expression in an argument.
  868. With the :generator:`Ninja Multi-Config` generator, generator expressions
  869. in ``...`` are evaluated using the custom command's "command config".
  870. With other generators, the content of ``...`` is evaluated normally.
  871. Toolchain And Language Expressions
  872. ----------------------------------
  873. Platform
  874. ^^^^^^^^
  875. .. genex:: $<PLATFORM_ID>
  876. The current system's CMake platform id.
  877. See also the :variable:`CMAKE_SYSTEM_NAME` variable.
  878. .. genex:: $<PLATFORM_ID:platform_ids>
  879. ``1`` if CMake's platform id matches any one of the entries in
  880. comma-separated list ``platform_ids``, otherwise ``0``.
  881. See also the :variable:`CMAKE_SYSTEM_NAME` variable.
  882. Compiler Version
  883. ^^^^^^^^^^^^^^^^
  884. See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable, which is
  885. closely related to the expressions in this sub-section.
  886. .. genex:: $<C_COMPILER_VERSION>
  887. The version of the C compiler used.
  888. .. genex:: $<C_COMPILER_VERSION:version>
  889. ``1`` if the version of the C compiler matches ``version``, otherwise ``0``.
  890. .. genex:: $<CXX_COMPILER_VERSION>
  891. The version of the CXX compiler used.
  892. .. genex:: $<CXX_COMPILER_VERSION:version>
  893. ``1`` if the version of the C++ compiler matches ``version``, otherwise ``0``.
  894. .. genex:: $<CUDA_COMPILER_VERSION>
  895. .. versionadded:: 3.15
  896. The version of the CUDA compiler used.
  897. .. genex:: $<CUDA_COMPILER_VERSION:version>
  898. .. versionadded:: 3.15
  899. ``1`` if the version of the C++ compiler matches ``version``, otherwise ``0``.
  900. .. genex:: $<OBJC_COMPILER_VERSION>
  901. .. versionadded:: 3.16
  902. The version of the Objective-C compiler used.
  903. .. genex:: $<OBJC_COMPILER_VERSION:version>
  904. .. versionadded:: 3.16
  905. ``1`` if the version of the Objective-C compiler matches ``version``, otherwise ``0``.
  906. .. genex:: $<OBJCXX_COMPILER_VERSION>
  907. .. versionadded:: 3.16
  908. The version of the Objective-C++ compiler used.
  909. .. genex:: $<OBJCXX_COMPILER_VERSION:version>
  910. .. versionadded:: 3.16
  911. ``1`` if the version of the Objective-C++ compiler matches ``version``, otherwise ``0``.
  912. .. genex:: $<Fortran_COMPILER_VERSION>
  913. The version of the Fortran compiler used.
  914. .. genex:: $<Fortran_COMPILER_VERSION:version>
  915. ``1`` if the version of the Fortran compiler matches ``version``, otherwise ``0``.
  916. .. genex:: $<HIP_COMPILER_VERSION>
  917. .. versionadded:: 3.21
  918. The version of the HIP compiler used.
  919. .. genex:: $<HIP_COMPILER_VERSION:version>
  920. .. versionadded:: 3.21
  921. ``1`` if the version of the HIP compiler matches ``version``, otherwise ``0``.
  922. .. genex:: $<ISPC_COMPILER_VERSION>
  923. .. versionadded:: 3.19
  924. The version of the ISPC compiler used.
  925. .. genex:: $<ISPC_COMPILER_VERSION:version>
  926. .. versionadded:: 3.19
  927. ``1`` if the version of the ISPC compiler matches ``version``, otherwise ``0``.
  928. Compiler Language, ID, and Frontend-Variant
  929. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  930. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` and
  931. :variable:`CMAKE_<LANG>_COMPILER_FRONTEND_VARIANT` variables, which are closely
  932. related to most of the expressions in this sub-section.
  933. .. genex:: $<C_COMPILER_ID>
  934. CMake's compiler id of the C compiler used.
  935. .. genex:: $<C_COMPILER_ID:compiler_ids>
  936. where ``compiler_ids`` is a comma-separated list.
  937. ``1`` if CMake's compiler id of the C compiler matches any one
  938. of the entries in ``compiler_ids``, otherwise ``0``.
  939. .. versionchanged:: 3.15
  940. Multiple ``compiler_ids`` can be specified.
  941. CMake 3.14 and earlier only accepted a single compiler ID.
  942. .. genex:: $<CXX_COMPILER_ID>
  943. CMake's compiler id of the C++ compiler used.
  944. .. genex:: $<CXX_COMPILER_ID:compiler_ids>
  945. where ``compiler_ids`` is a comma-separated list.
  946. ``1`` if CMake's compiler id of the C++ compiler matches any one
  947. of the entries in ``compiler_ids``, otherwise ``0``.
  948. .. versionchanged:: 3.15
  949. Multiple ``compiler_ids`` can be specified.
  950. CMake 3.14 and earlier only accepted a single compiler ID.
  951. .. genex:: $<CUDA_COMPILER_ID>
  952. .. versionadded:: 3.15
  953. CMake's compiler id of the CUDA compiler used.
  954. .. genex:: $<CUDA_COMPILER_ID:compiler_ids>
  955. .. versionadded:: 3.15
  956. where ``compiler_ids`` is a comma-separated list.
  957. ``1`` if CMake's compiler id of the CUDA compiler matches any one
  958. of the entries in ``compiler_ids``, otherwise ``0``.
  959. .. genex:: $<OBJC_COMPILER_ID>
  960. .. versionadded:: 3.16
  961. CMake's compiler id of the Objective-C compiler used.
  962. .. genex:: $<OBJC_COMPILER_ID:compiler_ids>
  963. .. versionadded:: 3.16
  964. where ``compiler_ids`` is a comma-separated list.
  965. ``1`` if CMake's compiler id of the Objective-C compiler matches any one
  966. of the entries in ``compiler_ids``, otherwise ``0``.
  967. .. genex:: $<OBJCXX_COMPILER_ID>
  968. .. versionadded:: 3.16
  969. CMake's compiler id of the Objective-C++ compiler used.
  970. .. genex:: $<OBJCXX_COMPILER_ID:compiler_ids>
  971. .. versionadded:: 3.16
  972. where ``compiler_ids`` is a comma-separated list.
  973. ``1`` if CMake's compiler id of the Objective-C++ compiler matches any one
  974. of the entries in ``compiler_ids``, otherwise ``0``.
  975. .. genex:: $<Fortran_COMPILER_ID>
  976. CMake's compiler id of the Fortran compiler used.
  977. .. genex:: $<Fortran_COMPILER_ID:compiler_ids>
  978. where ``compiler_ids`` is a comma-separated list.
  979. ``1`` if CMake's compiler id of the Fortran compiler matches any one
  980. of the entries in ``compiler_ids``, otherwise ``0``.
  981. .. versionchanged:: 3.15
  982. Multiple ``compiler_ids`` can be specified.
  983. CMake 3.14 and earlier only accepted a single compiler ID.
  984. .. genex:: $<HIP_COMPILER_ID>
  985. .. versionadded:: 3.21
  986. CMake's compiler id of the HIP compiler used.
  987. .. genex:: $<HIP_COMPILER_ID:compiler_ids>
  988. .. versionadded:: 3.21
  989. where ``compiler_ids`` is a comma-separated list.
  990. ``1`` if CMake's compiler id of the HIP compiler matches any one
  991. of the entries in ``compiler_ids``, otherwise ``0``.
  992. .. genex:: $<ISPC_COMPILER_ID>
  993. .. versionadded:: 3.19
  994. CMake's compiler id of the ISPC compiler used.
  995. .. genex:: $<ISPC_COMPILER_ID:compiler_ids>
  996. .. versionadded:: 3.19
  997. where ``compiler_ids`` is a comma-separated list.
  998. ``1`` if CMake's compiler id of the ISPC compiler matches any one
  999. of the entries in ``compiler_ids``, otherwise ``0``.
  1000. .. genex:: $<C_COMPILER_FRONTEND_VARIANT>
  1001. .. versionadded:: 3.30
  1002. CMake's compiler frontend variant of the C compiler used.
  1003. .. genex:: $<C_COMPILER_FRONTEND_VARIANT:compiler_ids>
  1004. .. versionadded:: 3.30
  1005. where ``compiler_ids`` is a comma-separated list.
  1006. ``1`` if CMake's compiler frontend variant of the C compiler matches any one
  1007. of the entries in ``compiler_ids``, otherwise ``0``.
  1008. .. genex:: $<CXX_COMPILER_FRONTEND_VARIANT>
  1009. .. versionadded:: 3.30
  1010. CMake's compiler frontend variant of the C++ compiler used.
  1011. .. genex:: $<CXX_COMPILER_FRONTEND_VARIANT:compiler_ids>
  1012. .. versionadded:: 3.30
  1013. where ``compiler_ids`` is a comma-separated list.
  1014. ``1`` if CMake's compiler frontend variant of the C++ compiler matches any one
  1015. of the entries in ``compiler_ids``, otherwise ``0``.
  1016. .. genex:: $<CUDA_COMPILER_FRONTEND_VARIANT>
  1017. .. versionadded:: 3.30
  1018. CMake's compiler id of the CUDA compiler used.
  1019. .. genex:: $<CUDA_COMPILER_FRONTEND_VARIANT:compiler_ids>
  1020. .. versionadded:: 3.30
  1021. where ``compiler_ids`` is a comma-separated list.
  1022. ``1`` if CMake's compiler frontend variant of the CUDA compiler matches any one
  1023. of the entries in ``compiler_ids``, otherwise ``0``.
  1024. .. genex:: $<OBJC_COMPILER_FRONTEND_VARIANT>
  1025. .. versionadded:: 3.30
  1026. CMake's compiler frontend variant of the Objective-C compiler used.
  1027. .. genex:: $<OBJC_COMPILER_FRONTEND_VARIANT:compiler_ids>
  1028. .. versionadded:: 3.30
  1029. where ``compiler_ids`` is a comma-separated list.
  1030. ``1`` if CMake's compiler frontend variant of the Objective-C compiler matches any one
  1031. of the entries in ``compiler_ids``, otherwise ``0``.
  1032. .. genex:: $<OBJCXX_COMPILER_FRONTEND_VARIANT>
  1033. .. versionadded:: 3.30
  1034. CMake's compiler frontend variant of the Objective-C++ compiler used.
  1035. .. genex:: $<OBJCXX_COMPILER_FRONTEND_VARIANT:compiler_ids>
  1036. .. versionadded:: 3.30
  1037. where ``compiler_ids`` is a comma-separated list.
  1038. ``1`` if CMake's compiler frontend variant of the Objective-C++ compiler matches any one
  1039. of the entries in ``compiler_ids``, otherwise ``0``.
  1040. .. genex:: $<Fortran_COMPILER_FRONTEND_VARIANT>
  1041. .. versionadded:: 3.30
  1042. CMake's compiler id of the Fortran compiler used.
  1043. .. genex:: $<Fortran_COMPILER_FRONTEND_VARIANT:compiler_ids>
  1044. .. versionadded:: 3.30
  1045. where ``compiler_ids`` is a comma-separated list.
  1046. ``1`` if CMake's compiler frontend variant of the Fortran compiler matches any one
  1047. of the entries in ``compiler_ids``, otherwise ``0``.
  1048. .. genex:: $<HIP_COMPILER_FRONTEND_VARIANT>
  1049. .. versionadded:: 3.30
  1050. CMake's compiler id of the HIP compiler used.
  1051. .. genex:: $<HIP_COMPILER_FRONTEND_VARIANT:compiler_ids>
  1052. .. versionadded:: 3.30
  1053. where ``compiler_ids`` is a comma-separated list.
  1054. ``1`` if CMake's compiler frontend variant of the HIP compiler matches any one
  1055. of the entries in ``compiler_ids``, otherwise ``0``.
  1056. .. genex:: $<ISPC_COMPILER_FRONTEND_VARIANT>
  1057. .. versionadded:: 3.30
  1058. CMake's compiler id of the ISPC compiler used.
  1059. .. genex:: $<ISPC_COMPILER_FRONTEND_VARIANT:compiler_ids>
  1060. .. versionadded:: 3.30
  1061. where ``compiler_ids`` is a comma-separated list.
  1062. ``1`` if CMake's compiler frontend variant of the ISPC compiler matches any one
  1063. of the entries in ``compiler_ids``, otherwise ``0``.
  1064. .. genex:: $<COMPILE_LANGUAGE>
  1065. .. versionadded:: 3.3
  1066. The compile language of source files when evaluating compile options.
  1067. See the related boolean expression
  1068. :genex:`$<COMPILE_LANGUAGE:languages> <COMPILE_LANGUAGE:languages>`
  1069. for notes about the portability of this generator expression.
  1070. .. genex:: $<COMPILE_LANGUAGE:languages>
  1071. :target: COMPILE_LANGUAGE:languages
  1072. .. versionadded:: 3.3
  1073. .. versionchanged:: 3.15
  1074. Multiple languages can be specified for ``languages``.
  1075. CMake 3.14 and earlier only accepted a single language.
  1076. ``1`` when the language used for compilation unit matches any of the
  1077. comma-separated entries in ``languages``, otherwise ``0``. This expression
  1078. may be used to specify compile options, compile definitions, and include
  1079. directories for source files of a particular language in a target. For
  1080. example:
  1081. .. code-block:: cmake
  1082. add_executable(myapp main.cpp foo.c bar.cpp zot.cu)
  1083. target_compile_options(myapp
  1084. PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
  1085. )
  1086. target_compile_definitions(myapp
  1087. PRIVATE $<$<COMPILE_LANGUAGE:CXX>:COMPILING_CXX>
  1088. $<$<COMPILE_LANGUAGE:CUDA>:COMPILING_CUDA>
  1089. )
  1090. target_include_directories(myapp
  1091. PRIVATE $<$<COMPILE_LANGUAGE:CXX,CUDA>:/opt/foo/headers>
  1092. )
  1093. This specifies the use of the ``-fno-exceptions`` compile option,
  1094. ``COMPILING_CXX`` compile definition, and ``cxx_headers`` include
  1095. directory for C++ only (compiler id checks elided). It also specifies
  1096. a ``COMPILING_CUDA`` compile definition for CUDA.
  1097. Note that with :ref:`Visual Studio Generators` and :generator:`Xcode` there
  1098. is no way to represent target-wide compile definitions or include directories
  1099. separately for ``C`` and ``CXX`` languages.
  1100. Also, with :ref:`Visual Studio Generators` there is no way to represent
  1101. target-wide flags separately for ``C`` and ``CXX`` languages. Under these
  1102. generators, expressions for both C and C++ sources will be evaluated
  1103. using ``CXX`` if there are any C++ sources and otherwise using ``C``.
  1104. A workaround is to create separate libraries for each source file language
  1105. instead:
  1106. .. code-block:: cmake
  1107. add_library(myapp_c foo.c)
  1108. add_library(myapp_cxx bar.cpp)
  1109. target_compile_options(myapp_cxx PUBLIC -fno-exceptions)
  1110. add_executable(myapp main.cpp)
  1111. target_link_libraries(myapp myapp_c myapp_cxx)
  1112. .. genex:: $<COMPILE_LANG_AND_ID:language,compiler_ids>
  1113. .. versionadded:: 3.15
  1114. ``1`` when the language used for compilation unit matches ``language`` and
  1115. CMake's compiler id of the ``language`` compiler matches any one of the
  1116. comma-separated entries in ``compiler_ids``, otherwise ``0``. This expression
  1117. is a short form for the combination of ``$<COMPILE_LANGUAGE:language>`` and
  1118. ``$<LANG_COMPILER_ID:compiler_ids>``. This expression may be used to specify
  1119. compile options, compile definitions, and include directories for source
  1120. files of a particular language and compiler combination in a target.
  1121. For example:
  1122. .. code-block:: cmake
  1123. add_executable(myapp main.cpp foo.c bar.cpp zot.cu)
  1124. target_compile_definitions(myapp
  1125. PRIVATE $<$<COMPILE_LANG_AND_ID:CXX,AppleClang,Clang>:COMPILING_CXX_WITH_CLANG>
  1126. $<$<COMPILE_LANG_AND_ID:CXX,Intel>:COMPILING_CXX_WITH_INTEL>
  1127. $<$<COMPILE_LANG_AND_ID:C,Clang>:COMPILING_C_WITH_CLANG>
  1128. )
  1129. This specifies the use of different compile definitions based on both
  1130. the compiler id and compilation language. This example will have a
  1131. ``COMPILING_CXX_WITH_CLANG`` compile definition when Clang is the CXX
  1132. compiler, and ``COMPILING_CXX_WITH_INTEL`` when Intel is the CXX compiler.
  1133. Likewise, when the C compiler is Clang, it will only see the
  1134. ``COMPILING_C_WITH_CLANG`` definition.
  1135. Without the ``COMPILE_LANG_AND_ID`` generator expression, the same logic
  1136. would be expressed as:
  1137. .. code-block:: cmake
  1138. target_compile_definitions(myapp
  1139. PRIVATE $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:AppleClang,Clang>>:COMPILING_CXX_WITH_CLANG>
  1140. $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:Intel>>:COMPILING_CXX_WITH_INTEL>
  1141. $<$<AND:$<COMPILE_LANGUAGE:C>,$<C_COMPILER_ID:Clang>>:COMPILING_C_WITH_CLANG>
  1142. )
  1143. Compile Features
  1144. ^^^^^^^^^^^^^^^^
  1145. .. genex:: $<COMPILE_FEATURES:features>
  1146. .. versionadded:: 3.1
  1147. where ``features`` is a comma-separated list.
  1148. Evaluates to ``1`` if all of the ``features`` are available for the 'head'
  1149. target, and ``0`` otherwise. If this expression is used while evaluating
  1150. the link implementation of a target and if any dependency transitively
  1151. increases the required :prop_tgt:`C_STANDARD` or :prop_tgt:`CXX_STANDARD`
  1152. for the 'head' target, an error is reported. See the
  1153. :manual:`cmake-compile-features(7)` manual for information on
  1154. compile features and a list of supported compilers.
  1155. Compile Context
  1156. ^^^^^^^^^^^^^^^
  1157. .. genex:: $<COMPILE_ONLY:...>
  1158. .. versionadded:: 3.27
  1159. Content of ``...``, when collecting
  1160. :ref:`transitive compile properties <Transitive Compile Properties>`,
  1161. otherwise it is the empty string. This is intended for use in an
  1162. :prop_tgt:`INTERFACE_LINK_LIBRARIES` and :prop_tgt:`LINK_LIBRARIES` target
  1163. properties, typically populated via the :command:`target_link_libraries` command.
  1164. Provides compilation usage requirements without any linking requirements.
  1165. Use cases include header-only usage where all usages are known to not have
  1166. linking requirements (e.g., all-``inline`` or C++ template libraries).
  1167. Note that for proper evaluation of this expression requires policy :policy:`CMP0099`
  1168. to be set to ``NEW``.
  1169. Link Language and ID
  1170. ^^^^^^^^^^^^^^^^^^^^
  1171. .. genex:: $<LINK_LANGUAGE>
  1172. .. versionadded:: 3.18
  1173. The link language of the target when evaluating link options.
  1174. See :ref:`the related boolean expression
  1175. <Boolean LINK_LANGUAGE Generator Expression>` ``$<LINK_LANGUAGE:languages>``
  1176. for notes about the portability of this generator expression.
  1177. .. note::
  1178. This generator expression is not supported by the link libraries
  1179. properties to avoid side-effects due to the double evaluation of
  1180. these properties.
  1181. .. _`Boolean LINK_LANGUAGE Generator Expression`:
  1182. .. genex:: $<LINK_LANGUAGE:languages>
  1183. .. versionadded:: 3.18
  1184. ``1`` when the language used for link step matches any of the comma-separated
  1185. entries in ``languages``, otherwise ``0``. This expression may be used to
  1186. specify link libraries, link options, link directories and link dependencies
  1187. of a particular language in a target. For example:
  1188. .. code-block:: cmake
  1189. add_library(api_C ...)
  1190. add_library(api_CXX ...)
  1191. add_library(api INTERFACE)
  1192. target_link_options(api INTERFACE $<$<LINK_LANGUAGE:C>:-opt_c>
  1193. $<$<LINK_LANGUAGE:CXX>:-opt_cxx>)
  1194. target_link_libraries(api INTERFACE $<$<LINK_LANGUAGE:C>:api_C>
  1195. $<$<LINK_LANGUAGE:CXX>:api_CXX>)
  1196. add_executable(myapp1 main.c)
  1197. target_link_options(myapp1 PRIVATE api)
  1198. add_executable(myapp2 main.cpp)
  1199. target_link_options(myapp2 PRIVATE api)
  1200. This specifies to use the ``api`` target for linking targets ``myapp1`` and
  1201. ``myapp2``. In practice, ``myapp1`` will link with target ``api_C`` and
  1202. option ``-opt_c`` because it will use ``C`` as link language. And ``myapp2``
  1203. will link with ``api_CXX`` and option ``-opt_cxx`` because ``CXX`` will be
  1204. the link language.
  1205. .. _`Constraints LINK_LANGUAGE Generator Expression`:
  1206. .. note::
  1207. To determine the link language of a target, it is required to collect,
  1208. transitively, all the targets which will be linked to it. So, for link
  1209. libraries properties, a double evaluation will be done. During the first
  1210. evaluation, ``$<LINK_LANGUAGE:..>`` expressions will always return ``0``.
  1211. The link language computed after this first pass will be used to do the
  1212. second pass. To avoid inconsistency, it is required that the second pass
  1213. do not change the link language. Moreover, to avoid unexpected
  1214. side-effects, it is required to specify complete entities as part of the
  1215. ``$<LINK_LANGUAGE:..>`` expression. For example:
  1216. .. code-block:: cmake
  1217. add_library(lib STATIC file.cxx)
  1218. add_library(libother STATIC file.c)
  1219. # bad usage
  1220. add_executable(myapp1 main.c)
  1221. target_link_libraries(myapp1 PRIVATE lib$<$<LINK_LANGUAGE:C>:other>)
  1222. # correct usage
  1223. add_executable(myapp2 main.c)
  1224. target_link_libraries(myapp2 PRIVATE $<$<LINK_LANGUAGE:C>:libother>)
  1225. In this example, for ``myapp1``, the first pass will, unexpectedly,
  1226. determine that the link language is ``CXX`` because the evaluation of the
  1227. generator expression will be an empty string so ``myapp1`` will depends on
  1228. target ``lib`` which is ``C++``. On the contrary, for ``myapp2``, the first
  1229. evaluation will give ``C`` as link language, so the second pass will
  1230. correctly add target ``libother`` as link dependency.
  1231. .. genex:: $<LINK_LANG_AND_ID:language,compiler_ids>
  1232. .. versionadded:: 3.18
  1233. ``1`` when the language used for link step matches ``language`` and the
  1234. CMake's compiler id of the language linker matches any one of the comma-separated
  1235. entries in ``compiler_ids``, otherwise ``0``. This expression is a short form
  1236. for the combination of ``$<LINK_LANGUAGE:language>`` and
  1237. ``$<LANG_COMPILER_ID:compiler_ids>``. This expression may be used to specify
  1238. link libraries, link options, link directories and link dependencies of a
  1239. particular language and linker combination in a target. For example:
  1240. .. code-block:: cmake
  1241. add_library(libC_Clang ...)
  1242. add_library(libCXX_Clang ...)
  1243. add_library(libC_Intel ...)
  1244. add_library(libCXX_Intel ...)
  1245. add_executable(myapp main.c)
  1246. if (CXX_CONFIG)
  1247. target_sources(myapp PRIVATE file.cxx)
  1248. endif()
  1249. target_link_libraries(myapp
  1250. PRIVATE $<$<LINK_LANG_AND_ID:CXX,Clang,AppleClang>:libCXX_Clang>
  1251. $<$<LINK_LANG_AND_ID:C,Clang,AppleClang>:libC_Clang>
  1252. $<$<LINK_LANG_AND_ID:CXX,Intel>:libCXX_Intel>
  1253. $<$<LINK_LANG_AND_ID:C,Intel>:libC_Intel>)
  1254. This specifies the use of different link libraries based on both the
  1255. compiler id and link language. This example will have target ``libCXX_Clang``
  1256. as link dependency when ``Clang`` or ``AppleClang`` is the ``CXX``
  1257. linker, and ``libCXX_Intel`` when ``Intel`` is the ``CXX`` linker.
  1258. Likewise when the ``C`` linker is ``Clang`` or ``AppleClang``, target
  1259. ``libC_Clang`` will be added as link dependency and ``libC_Intel`` when
  1260. ``Intel`` is the ``C`` linker.
  1261. See :ref:`the note related to
  1262. <Constraints LINK_LANGUAGE Generator Expression>`
  1263. ``$<LINK_LANGUAGE:language>`` for constraints about the usage of this
  1264. generator expression.
  1265. Link Features
  1266. ^^^^^^^^^^^^^
  1267. .. genex:: $<LINK_LIBRARY:feature,library-list>
  1268. .. versionadded:: 3.24
  1269. Specify a set of libraries to link to a target, along with a ``feature``
  1270. which provides details about *how* they should be linked. For example:
  1271. .. code-block:: cmake
  1272. add_library(lib1 STATIC ...)
  1273. add_library(lib2 ...)
  1274. target_link_libraries(lib2 PRIVATE "$<LINK_LIBRARY:WHOLE_ARCHIVE,lib1>")
  1275. This specifies that ``lib2`` should link to ``lib1`` and use the
  1276. ``WHOLE_ARCHIVE`` feature when doing so.
  1277. Feature names are case-sensitive and may only contain letters, numbers and
  1278. underscores. Feature names defined in all uppercase are reserved for CMake's
  1279. own built-in features. The pre-defined built-in library features are:
  1280. .. include:: ../variable/include/LINK_LIBRARY_PREDEFINED_FEATURES.rst
  1281. Built-in and custom library features are defined in terms of the following
  1282. variables:
  1283. * :variable:`CMAKE_<LANG>_LINK_LIBRARY_USING_<FEATURE>_SUPPORTED`
  1284. * :variable:`CMAKE_<LANG>_LINK_LIBRARY_USING_<FEATURE>`
  1285. * :variable:`CMAKE_LINK_LIBRARY_USING_<FEATURE>_SUPPORTED`
  1286. * :variable:`CMAKE_LINK_LIBRARY_USING_<FEATURE>`
  1287. The value used for each of these variables is the value as set at the end of
  1288. the directory scope in which the target was created. The usage is as follows:
  1289. 1. If the language-specific
  1290. :variable:`CMAKE_<LANG>_LINK_LIBRARY_USING_<FEATURE>_SUPPORTED` variable
  1291. is true, the ``feature`` must be defined by the corresponding
  1292. :variable:`CMAKE_<LANG>_LINK_LIBRARY_USING_<FEATURE>` variable.
  1293. 2. If no language-specific ``feature`` is supported, then the
  1294. :variable:`CMAKE_LINK_LIBRARY_USING_<FEATURE>_SUPPORTED` variable must be
  1295. true and the ``feature`` must be defined by the corresponding
  1296. :variable:`CMAKE_LINK_LIBRARY_USING_<FEATURE>` variable.
  1297. The following limitations should be noted:
  1298. * The ``library-list`` can specify CMake targets or libraries.
  1299. Any CMake target of type :ref:`OBJECT <Object Libraries>`
  1300. or :ref:`INTERFACE <Interface Libraries>` will ignore the feature aspect
  1301. of the expression and instead be linked in the standard way.
  1302. * The ``$<LINK_LIBRARY:...>`` generator expression can only be used to
  1303. specify link libraries. In practice, this means it can appear in the
  1304. :prop_tgt:`LINK_LIBRARIES`, :prop_tgt:`INTERFACE_LINK_LIBRARIES`, and
  1305. :prop_tgt:`INTERFACE_LINK_LIBRARIES_DIRECT` target properties, and be
  1306. specified in :command:`target_link_libraries` and :command:`link_libraries`
  1307. commands.
  1308. * If a ``$<LINK_LIBRARY:...>`` generator expression appears in the
  1309. :prop_tgt:`INTERFACE_LINK_LIBRARIES` property of a target, it will be
  1310. included in the imported target generated by a :command:`install(EXPORT)`
  1311. command. It is the responsibility of the environment consuming this
  1312. import to define the link feature used by this expression.
  1313. * Each target or library involved in the link step must have at most only
  1314. one kind of library feature. The absence of a feature is also incompatible
  1315. with all other features. For example:
  1316. .. code-block:: cmake
  1317. add_library(lib1 ...)
  1318. add_library(lib2 ...)
  1319. add_library(lib3 ...)
  1320. # lib1 will be associated with feature1
  1321. target_link_libraries(lib2 PUBLIC "$<LINK_LIBRARY:feature1,lib1>")
  1322. # lib1 is being linked with no feature here. This conflicts with the
  1323. # use of feature1 in the line above and would result in an error.
  1324. target_link_libraries(lib3 PRIVATE lib1 lib2)
  1325. Where it isn't possible to use the same feature throughout a build for a
  1326. given target or library, the :prop_tgt:`LINK_LIBRARY_OVERRIDE` and
  1327. :prop_tgt:`LINK_LIBRARY_OVERRIDE_<LIBRARY>` target properties can be
  1328. used to resolve such incompatibilities.
  1329. * The ``$<LINK_LIBRARY:...>`` generator expression does not guarantee
  1330. that the list of specified targets and libraries will be kept grouped
  1331. together. To manage constructs like ``--start-group`` and ``--end-group``,
  1332. as supported by the GNU ``ld`` linker, use the :genex:`LINK_GROUP`
  1333. generator expression instead.
  1334. .. genex:: $<LINK_GROUP:feature,library-list>
  1335. .. versionadded:: 3.24
  1336. Specify a group of libraries to link to a target, along with a ``feature``
  1337. which defines how that group should be linked. For example:
  1338. .. code-block:: cmake
  1339. add_library(lib1 STATIC ...)
  1340. add_library(lib2 ...)
  1341. target_link_libraries(lib2 PRIVATE "$<LINK_GROUP:RESCAN,lib1,external>")
  1342. This specifies that ``lib2`` should link to ``lib1`` and ``external``, and
  1343. that both of those two libraries should be included on the linker command
  1344. line according to the definition of the ``RESCAN`` feature.
  1345. Feature names are case-sensitive and may only contain letters, numbers and
  1346. underscores. Feature names defined in all uppercase are reserved for CMake's
  1347. own built-in features. Currently, there is only one pre-defined built-in
  1348. group feature:
  1349. .. include:: ../variable/include/LINK_GROUP_PREDEFINED_FEATURES.rst
  1350. Built-in and custom group features are defined in terms of the following
  1351. variables:
  1352. * :variable:`CMAKE_<LANG>_LINK_GROUP_USING_<FEATURE>_SUPPORTED`
  1353. * :variable:`CMAKE_<LANG>_LINK_GROUP_USING_<FEATURE>`
  1354. * :variable:`CMAKE_LINK_GROUP_USING_<FEATURE>_SUPPORTED`
  1355. * :variable:`CMAKE_LINK_GROUP_USING_<FEATURE>`
  1356. The value used for each of these variables is the value as set at the end of
  1357. the directory scope in which the target was created. The usage is as follows:
  1358. 1. If the language-specific
  1359. :variable:`CMAKE_<LANG>_LINK_GROUP_USING_<FEATURE>_SUPPORTED` variable
  1360. is true, the ``feature`` must be defined by the corresponding
  1361. :variable:`CMAKE_<LANG>_LINK_GROUP_USING_<FEATURE>` variable.
  1362. 2. If no language-specific ``feature`` is supported, then the
  1363. :variable:`CMAKE_LINK_GROUP_USING_<FEATURE>_SUPPORTED` variable must be
  1364. true and the ``feature`` must be defined by the corresponding
  1365. :variable:`CMAKE_LINK_GROUP_USING_<FEATURE>` variable.
  1366. The ``LINK_GROUP`` generator expression is compatible with the
  1367. :genex:`LINK_LIBRARY` generator expression. The libraries involved in a
  1368. group can be specified using the :genex:`LINK_LIBRARY` generator expression.
  1369. Each target or external library involved in the link step is allowed to be
  1370. part of multiple groups, but only if all the groups involved specify the
  1371. same ``feature``. Such groups will not be merged on the linker command line,
  1372. the individual groups will still be preserved. Mixing different group
  1373. features for the same target or library is forbidden.
  1374. .. code-block:: cmake
  1375. add_library(lib1 ...)
  1376. add_library(lib2 ...)
  1377. add_library(lib3 ...)
  1378. add_library(lib4 ...)
  1379. add_library(lib5 ...)
  1380. target_link_libraries(lib3 PUBLIC "$<LINK_GROUP:feature1,lib1,lib2>")
  1381. target_link_libraries(lib4 PRIVATE "$<LINK_GROUP:feature1,lib1,lib3>")
  1382. # lib4 will be linked with the groups {lib1,lib2} and {lib1,lib3}.
  1383. # Both groups specify the same feature, so this is fine.
  1384. target_link_libraries(lib5 PRIVATE "$<LINK_GROUP:feature2,lib1,lib3>")
  1385. # An error will be raised here because both lib1 and lib3 are part of two
  1386. # groups with different features.
  1387. When a target or an external library is involved in the link step as part of
  1388. a group and also as not part of any group, any occurrence of the non-group
  1389. link item will be replaced by the groups it belongs to.
  1390. .. code-block:: cmake
  1391. add_library(lib1 ...)
  1392. add_library(lib2 ...)
  1393. add_library(lib3 ...)
  1394. add_library(lib4 ...)
  1395. target_link_libraries(lib3 PUBLIC lib1)
  1396. target_link_libraries(lib4 PRIVATE lib3 "$<LINK_GROUP:feature1,lib1,lib2>")
  1397. # lib4 will only be linked with lib3 and the group {lib1,lib2}
  1398. Because ``lib1`` is part of the group defined for ``lib4``, that group then
  1399. gets applied back to the use of ``lib1`` for ``lib3``. The end result will
  1400. be as though the linking relationship for ``lib3`` had been specified as:
  1401. .. code-block:: cmake
  1402. target_link_libraries(lib3 PUBLIC "$<LINK_GROUP:feature1,lib1,lib2>")
  1403. Be aware that the precedence of the group over the non-group link item can
  1404. result in circular dependencies between groups. If this occurs, a fatal
  1405. error is raised because circular dependencies are not allowed for groups.
  1406. .. code-block:: cmake
  1407. add_library(lib1A ...)
  1408. add_library(lib1B ...)
  1409. add_library(lib2A ...)
  1410. add_library(lib2B ...)
  1411. add_library(lib3 ...)
  1412. # Non-group linking relationships, these are non-circular so far
  1413. target_link_libraries(lib1A PUBLIC lib2A)
  1414. target_link_libraries(lib2B PUBLIC lib1B)
  1415. # The addition of these groups creates circular dependencies
  1416. target_link_libraries(lib3 PRIVATE
  1417. "$<LINK_GROUP:feat,lib1A,lib1B>"
  1418. "$<LINK_GROUP:feat,lib2A,lib2B>"
  1419. )
  1420. Because of the groups defined for ``lib3``, the linking relationships for
  1421. ``lib1A`` and ``lib2B`` effectively get expanded to the equivalent of:
  1422. .. code-block:: cmake
  1423. target_link_libraries(lib1A PUBLIC "$<LINK_GROUP:feat,lib2A,lib2B>")
  1424. target_link_libraries(lib2B PUBLIC "$<LINK_GROUP:feat,lib1A,lib1B>")
  1425. This creates a circular dependency between groups:
  1426. ``lib1A --> lib2B --> lib1A``.
  1427. The following limitations should also be noted:
  1428. * The ``library-list`` can specify CMake targets or libraries.
  1429. Any CMake target of type :ref:`OBJECT <Object Libraries>`
  1430. or :ref:`INTERFACE <Interface Libraries>` will ignore the feature aspect
  1431. of the expression and instead be linked in the standard way.
  1432. * The ``$<LINK_GROUP:...>`` generator expression can only be used to
  1433. specify link libraries. In practice, this means it can appear in the
  1434. :prop_tgt:`LINK_LIBRARIES`, :prop_tgt:`INTERFACE_LINK_LIBRARIES`,and
  1435. :prop_tgt:`INTERFACE_LINK_LIBRARIES_DIRECT` target properties, and be
  1436. specified in :command:`target_link_libraries` and :command:`link_libraries`
  1437. commands.
  1438. * If a ``$<LINK_GROUP:...>`` generator expression appears in the
  1439. :prop_tgt:`INTERFACE_LINK_LIBRARIES` property of a target, it will be
  1440. included in the imported target generated by a :command:`install(EXPORT)`
  1441. command. It is the responsibility of the environment consuming this
  1442. import to define the link feature used by this expression.
  1443. Link Context
  1444. ^^^^^^^^^^^^
  1445. .. genex:: $<LINK_ONLY:...>
  1446. .. versionadded:: 3.1
  1447. Content of ``...``, except while collecting usage requirements from
  1448. :ref:`transitive compile properties <Transitive Compile Properties>`,
  1449. in which case it is the empty string. This is intended for use in an
  1450. :prop_tgt:`INTERFACE_LINK_LIBRARIES` target property, typically populated
  1451. via the :command:`target_link_libraries` command, to specify private link
  1452. dependencies without other usage requirements such as include directories or
  1453. compile options.
  1454. .. versionadded:: 3.24
  1455. ``LINK_ONLY`` may also be used in a :prop_tgt:`LINK_LIBRARIES` target
  1456. property. See policy :policy:`CMP0131`.
  1457. .. genex:: $<DEVICE_LINK:list>
  1458. .. versionadded:: 3.18
  1459. Returns the list if it is the device link step, an empty list otherwise.
  1460. The device link step is controlled by :prop_tgt:`CUDA_SEPARABLE_COMPILATION`
  1461. and :prop_tgt:`CUDA_RESOLVE_DEVICE_SYMBOLS` properties and
  1462. policy :policy:`CMP0105`. This expression can only be used to specify link
  1463. options.
  1464. .. genex:: $<HOST_LINK:list>
  1465. .. versionadded:: 3.18
  1466. Returns the list if it is the normal link step, an empty list otherwise.
  1467. This expression is mainly useful when a device link step is also involved
  1468. (see :genex:`$<DEVICE_LINK:list>` generator expression). This expression can
  1469. only be used to specify link options.
  1470. Linker ID and Frontend-Variant
  1471. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1472. See also the :variable:`CMAKE_<LANG>_COMPILER_LINKER_ID` and
  1473. :variable:`CMAKE_<LANG>_COMPILER_LINKER_FRONTEND_VARIANT` variables, which are
  1474. closely related to most of the expressions in this sub-section.
  1475. .. genex:: $<C_COMPILER_LINKER_ID>
  1476. .. versionadded:: 4.2
  1477. CMake's linker id of the C linker used.
  1478. .. genex:: $<C_COMPILER_LINKER_ID:linker_ids>
  1479. .. versionadded:: 4.2
  1480. where ``linker_ids`` is a comma-separated list.
  1481. ``1`` if CMake's linker id of the C linker matches any one
  1482. of the entries in ``linker_ids``, otherwise ``0``.
  1483. .. genex:: $<CXX_COMPILER_LINKER_ID>
  1484. .. versionadded:: 4.2
  1485. CMake's linker id of the C++ linker used.
  1486. .. genex:: $<CXX_COMPILER_LINKER_ID:linker_ids>
  1487. .. versionadded:: 4.2
  1488. where ``linker_ids`` is a comma-separated list.
  1489. ``1`` if CMake's linker id of the C++ linker matches any one
  1490. of the entries in ``linker_ids``, otherwise ``0``.
  1491. .. genex:: $<CUDA_COMPILER_LINKER_ID>
  1492. .. versionadded:: 4.2
  1493. CMake's linker id of the CUDA linker used.
  1494. .. genex:: $<CUDA_COMPILER_LINKER_ID:linker_ids>
  1495. .. versionadded:: 4.2
  1496. where ``linker_ids`` is a comma-separated list.
  1497. ``1`` if CMake's linker id of the CUDA linker matches any one
  1498. of the entries in ``linker_ids``, otherwise ``0``.
  1499. .. genex:: $<OBJC_COMPILER_LINKER_ID>
  1500. .. versionadded:: 4.2
  1501. CMake's linker id of the Objective-C linker used.
  1502. .. genex:: $<OBJC_COMPILER_LINKER_ID:linker_ids>
  1503. .. versionadded:: 4.2
  1504. where ``linker_ids`` is a comma-separated list.
  1505. ``1`` if CMake's linker id of the Objective-C linker matches any one
  1506. of the entries in ``linker_ids``, otherwise ``0``.
  1507. .. genex:: $<OBJCXX_COMPILER_LINKER_ID>
  1508. .. versionadded:: 4.2
  1509. CMake's linker id of the Objective-C++ linker used.
  1510. .. genex:: $<OBJCXX_COMPILER_LINKER_ID:linker_ids>
  1511. .. versionadded:: 4.2
  1512. where ``linker_ids`` is a comma-separated list.
  1513. ``1`` if CMake's linker id of the Objective-C++ linker matches any one
  1514. of the entries in ``linker_ids``, otherwise ``0``.
  1515. .. genex:: $<Fortran_COMPILER_LINKER_ID>
  1516. .. versionadded:: 4.2
  1517. CMake's linker id of the Fortran linker used.
  1518. .. genex:: $<Fortran_COMPILER_LINKER_ID:linker_ids>
  1519. .. versionadded:: 4.2
  1520. where ``linker_ids`` is a comma-separated list.
  1521. ``1`` if CMake's linker id of the Fortran linker matches any one
  1522. of the entries in ``linker_ids``, otherwise ``0``.
  1523. .. genex:: $<HIP_COMPILER_LINKER_ID>
  1524. .. versionadded:: 4.2
  1525. CMake's linker id of the HIP linker used.
  1526. .. genex:: $<HIP_COMPILER_LINKER_ID:linker_ids>
  1527. .. versionadded:: 4.2
  1528. where ``linker_ids`` is a comma-separated list.
  1529. ``1`` if CMake's linker id of the HIP linker matches any one
  1530. of the entries in ``linker_ids``, otherwise ``0``.
  1531. .. genex:: $<C_COMPILER_LINKER_FRONTEND_VARIANT>
  1532. .. versionadded:: 4.2
  1533. CMake's linker frontend variant of the C linker used.
  1534. .. genex:: $<C_COMPILER_LINKER_FRONTEND_VARIANT:variant_ids>
  1535. .. versionadded:: 4.2
  1536. where ``variant_ids`` is a comma-separated list.
  1537. ``1`` if CMake's linker frontend variant of the C linker matches any one
  1538. of the entries in ``variant_ids``, otherwise ``0``.
  1539. .. genex:: $<CXX_COMPILER_LINKER_FRONTEND_VARIANT>
  1540. .. versionadded:: 4.2
  1541. CMake's linker frontend variant of the C++ linker used.
  1542. .. genex:: $<CXX_COMPILER_LINKER_FRONTEND_VARIANT:variant_ids>
  1543. .. versionadded:: 4.2
  1544. where ``variant_ids`` is a comma-separated list.
  1545. ``1`` if CMake's linker frontend variant of the C++ linker matches any one
  1546. of the entries in ``variant_ids``, otherwise ``0``.
  1547. .. genex:: $<CUDA_COMPILER_LINKER_FRONTEND_VARIANT>
  1548. .. versionadded:: 4.2
  1549. CMake's linker frontend variant of the CUDA linker used.
  1550. .. genex:: $<CUDA_COMPILER_LINKER_FRONTEND_VARIANT:variant_ids>
  1551. .. versionadded:: 4.2
  1552. where ``variant_ids`` is a comma-separated list.
  1553. ``1`` if CMake's linker frontend variant of the CUDA linker matches any one
  1554. of the entries in ``variant_ids``, otherwise ``0``.
  1555. .. genex:: $<OBJC_COMPILER_LINKER_FRONTEND_VARIANT>
  1556. .. versionadded:: 4.2
  1557. CMake's linker frontend variant of the Objective-C linker used.
  1558. .. genex:: $<OBJC_COMPILER_LINKER_FRONTEND_VARIANT:variant_ids>
  1559. .. versionadded:: 4.2
  1560. where ``variant_ids`` is a comma-separated list.
  1561. ``1`` if CMake's linker frontend variant of the Objective-C linker matches
  1562. any one of the entries in ``variant_ids``, otherwise ``0``.
  1563. .. genex:: $<OBJCXX_COMPILER_LINKER_FRONTEND_VARIANT>
  1564. .. versionadded:: 4.2
  1565. CMake's linker frontend variant of the Objective-C++ linker used.
  1566. .. genex:: $<OBJCXX_COMPILER_LINKER_FRONTEND_VARIANT:variant_ids>
  1567. .. versionadded:: 4.2
  1568. where ``variant_ids`` is a comma-separated list.
  1569. ``1`` if CMake's linker frontend variant of the Objective-C++ linker matches
  1570. any one of the entries in ``variant_ids``, otherwise ``0``.
  1571. .. genex:: $<Fortran_COMPILER_LINKER_FRONTEND_VARIANT>
  1572. .. versionadded:: 4.2
  1573. CMake's linker frontend variant of the Fortran linker used.
  1574. .. genex:: $<Fortran_COMPILER_LINKER_FRONTEND_VARIANT:variant_ids>
  1575. .. versionadded:: 4.2
  1576. where ``variant_ids`` is a comma-separated list.
  1577. ``1`` if CMake's linker frontend variant of the Fortran linker matches
  1578. any one of the entries in ``variant_ids``, otherwise ``0``.
  1579. .. genex:: $<HIP_COMPILER_LINKER_FRONTEND_VARIANT>
  1580. .. versionadded:: 4.2
  1581. CMake's linker frontend variant of the HIP linker used.
  1582. .. genex:: $<HIP_COMPILER_LINKER_FRONTEND_VARIANT:variant_ids>
  1583. .. versionadded:: 4.2
  1584. where ``variant_ids`` is a comma-separated list.
  1585. ``1`` if CMake's linker frontend variant of the HIP linker matches
  1586. any one of the entries in ``variant_ids``, otherwise ``0``.
  1587. .. _`Target-Dependent Expressions`:
  1588. Target-Dependent Expressions
  1589. ----------------------------
  1590. Target Meta-Data
  1591. ^^^^^^^^^^^^^^^^
  1592. These expressions look up information about a target.
  1593. .. genex:: $<TARGET_EXISTS:tgt>
  1594. .. versionadded:: 3.12
  1595. ``1`` if ``tgt`` exists as a CMake target, else ``0``.
  1596. .. genex:: $<TARGET_NAME_IF_EXISTS:tgt>
  1597. .. versionadded:: 3.12
  1598. The target name ``tgt`` if the target exists, an empty string otherwise.
  1599. Note that ``tgt`` is not added as a dependency of the target this
  1600. expression is evaluated on.
  1601. .. genex:: $<TARGET_NAME:tgt>
  1602. The target name ``tgt`` as written. This marks ``tgt`` as being the name
  1603. of a target inside a larger expression, which is required if exporting
  1604. targets to multiple dependent export sets. The ``tgt`` text must be a
  1605. literal name of a target; it may not contain generator expressions.
  1606. The target does not have to exist.
  1607. .. genex:: $<TARGET_POLICY:policy>
  1608. ``1`` if the ``policy`` was ``NEW`` when the 'head' target was created,
  1609. else ``0``. If the ``policy`` was not set, the warning message for the policy
  1610. will be emitted. This generator expression only works for a subset of
  1611. policies.
  1612. Target Properties
  1613. ^^^^^^^^^^^^^^^^^
  1614. These expressions look up the values of
  1615. :ref:`target properties <Target Properties>`.
  1616. .. genex:: $<TARGET_PROPERTY:tgt,prop>
  1617. Value of the property ``prop`` on the target ``tgt``, or empty if
  1618. the property is not set.
  1619. Note that ``tgt`` is not added as a dependency of the target this
  1620. expression is evaluated on.
  1621. .. versionchanged:: 3.26
  1622. When encountered during evaluation of :ref:`Target Usage Requirements`,
  1623. typically in an ``INTERFACE_*`` target property, lookup of the ``tgt``
  1624. name occurs in the directory of the target specifying the requirement,
  1625. rather than the directory of the consuming target for which the
  1626. expression is being evaluated.
  1627. .. genex:: $<TARGET_PROPERTY:prop>
  1628. :target: TARGET_PROPERTY:prop
  1629. Value of the property ``prop`` on the target for which the expression
  1630. is being evaluated, or empty if the property is not set.
  1631. Note that for generator expressions in :ref:`Target Usage Requirements`
  1632. this is the consuming target rather than the target specifying the
  1633. requirement.
  1634. The expressions have special evaluation rules for some properties:
  1635. :ref:`Target Build Specification Properties <Target Build Specification>`
  1636. These evaluate as a :ref:`semicolon-separated list <CMake Language Lists>`
  1637. representing the union of the value on the target itself with the values
  1638. of the corresponding :ref:`Target Usage Requirements` on targets named by
  1639. the target's :prop_tgt:`LINK_LIBRARIES`:
  1640. * For :ref:`Target Compile Properties`, evaluation of corresponding usage
  1641. requirements is transitive over the closure of the linked targets'
  1642. :prop_tgt:`INTERFACE_LINK_LIBRARIES` *excluding* entries guarded by the
  1643. :genex:`LINK_ONLY` generator expression.
  1644. * For :ref:`Target Link Properties`, evaluation of corresponding usage
  1645. requirements is transitive over the closure of the linked targets'
  1646. :prop_tgt:`INTERFACE_LINK_LIBRARIES` *including* entries guarded by the
  1647. :genex:`LINK_ONLY` generator expression. See policy :policy:`CMP0166`.
  1648. .. versionchanged:: 4.1
  1649. Evaluation of :prop_tgt:`LINK_LIBRARIES` itself is now transitive.
  1650. See policy :policy:`CMP0189`.
  1651. :ref:`Target Usage Requirement Properties <Target Usage Requirements>`
  1652. These evaluate as a :ref:`semicolon-separated list <CMake Language Lists>`
  1653. representing the union of the value on the target itself with the values
  1654. of the same properties on targets named by the target's
  1655. :prop_tgt:`INTERFACE_LINK_LIBRARIES`:
  1656. * For :ref:`Transitive Compile Properties`, evaluation is transitive over
  1657. the closure of the target's :prop_tgt:`INTERFACE_LINK_LIBRARIES`
  1658. *excluding* entries guarded by the :genex:`LINK_ONLY` generator expression.
  1659. * For :ref:`Transitive Link Properties`, evaluation is transitive over
  1660. the closure of the target's :prop_tgt:`INTERFACE_LINK_LIBRARIES`
  1661. *including* entries guarded by the :genex:`LINK_ONLY` generator expression.
  1662. See policy :policy:`CMP0166`.
  1663. .. versionchanged:: 4.1
  1664. Evaluation of :prop_tgt:`INTERFACE_LINK_LIBRARIES` itself is now
  1665. transitive. See policy :policy:`CMP0189`.
  1666. :ref:`Custom Transitive Properties`
  1667. .. versionadded:: 3.30
  1668. These are processed during evaluation as follows:
  1669. * Evaluation of :genex:`$<TARGET_PROPERTY:tgt,PROP>` for some property
  1670. ``PROP``, named without an ``INTERFACE_`` prefix,
  1671. checks the :prop_tgt:`TRANSITIVE_COMPILE_PROPERTIES`
  1672. and :prop_tgt:`TRANSITIVE_LINK_PROPERTIES` properties on target ``tgt``,
  1673. on targets named by its :prop_tgt:`LINK_LIBRARIES`, and on the
  1674. transitive closure of targets named by the linked targets'
  1675. :prop_tgt:`INTERFACE_LINK_LIBRARIES`.
  1676. If ``PROP`` is listed by one of those properties, then it evaluates as
  1677. a :ref:`semicolon-separated list <CMake Language Lists>` representing
  1678. the union of the value on the target itself with the values of the
  1679. corresponding ``INTERFACE_PROP`` on targets named by the target's
  1680. :prop_tgt:`LINK_LIBRARIES`:
  1681. * If ``PROP`` is named by :prop_tgt:`TRANSITIVE_COMPILE_PROPERTIES`,
  1682. evaluation of the corresponding ``INTERFACE_PROP`` is transitive over
  1683. the closure of the linked targets' :prop_tgt:`INTERFACE_LINK_LIBRARIES`,
  1684. excluding entries guarded by the :genex:`LINK_ONLY` generator expression.
  1685. * If ``PROP`` is named by :prop_tgt:`TRANSITIVE_LINK_PROPERTIES`,
  1686. evaluation of the corresponding ``INTERFACE_PROP`` is transitive over
  1687. the closure of the linked targets' :prop_tgt:`INTERFACE_LINK_LIBRARIES`,
  1688. including entries guarded by the :genex:`LINK_ONLY` generator expression.
  1689. * Evaluation of :genex:`$<TARGET_PROPERTY:tgt,INTERFACE_PROP>` for some
  1690. property ``INTERFACE_PROP``, named with an ``INTERFACE_`` prefix,
  1691. checks the :prop_tgt:`TRANSITIVE_COMPILE_PROPERTIES`
  1692. and :prop_tgt:`TRANSITIVE_LINK_PROPERTIES` properties on target ``tgt``,
  1693. and on the transitive closure of targets named by its
  1694. :prop_tgt:`INTERFACE_LINK_LIBRARIES`.
  1695. If the corresponding ``PROP`` is listed by one of those properties,
  1696. then ``INTERFACE_PROP`` evaluates as a
  1697. :ref:`semicolon-separated list <CMake Language Lists>` representing the
  1698. union of the value on the target itself with the value of the same
  1699. property on targets named by the target's
  1700. :prop_tgt:`INTERFACE_LINK_LIBRARIES`:
  1701. * If ``PROP`` is named by :prop_tgt:`TRANSITIVE_COMPILE_PROPERTIES`,
  1702. evaluation of the corresponding ``INTERFACE_PROP`` is transitive over
  1703. the closure of the target's :prop_tgt:`INTERFACE_LINK_LIBRARIES`,
  1704. excluding entries guarded by the :genex:`LINK_ONLY` generator expression.
  1705. * If ``PROP`` is named by :prop_tgt:`TRANSITIVE_LINK_PROPERTIES`,
  1706. evaluation of the corresponding ``INTERFACE_PROP`` is transitive over
  1707. the closure of the target's :prop_tgt:`INTERFACE_LINK_LIBRARIES`,
  1708. including entries guarded by the :genex:`LINK_ONLY` generator expression.
  1709. If a ``PROP`` is named by both :prop_tgt:`TRANSITIVE_COMPILE_PROPERTIES`
  1710. and :prop_tgt:`TRANSITIVE_LINK_PROPERTIES`, the latter takes precedence.
  1711. :ref:`Compatible Interface Properties`
  1712. These evaluate as a single value combined from the target itself,
  1713. from targets named by the target's :prop_tgt:`LINK_LIBRARIES`, and
  1714. from the transitive closure of the linked targets'
  1715. :prop_tgt:`INTERFACE_LINK_LIBRARIES`. Values of a compatible
  1716. interface property from multiple targets combine based on the type
  1717. of compatibility required by the ``COMPATIBLE_INTERFACE_*`` property
  1718. defining it.
  1719. Target Artifacts
  1720. ^^^^^^^^^^^^^^^^
  1721. These expressions look up information about artifacts associated with
  1722. a given target ``tgt``. Unless otherwise stated, this can be any
  1723. runtime artifact, namely:
  1724. * An executable target created by :command:`add_executable`.
  1725. * A shared library target (``.so``, ``.dll`` but not their ``.lib`` import
  1726. library) created by :command:`add_library`.
  1727. * A static library target created by :command:`add_library`.
  1728. In the following, the phrase "the ``tgt`` filename" means the name of the
  1729. ``tgt`` binary file. This has to be distinguished from the phrase
  1730. "the target name", which is just the string ``tgt``.
  1731. .. genex:: $<TARGET_FILE:tgt>
  1732. Full path to the ``tgt`` binary file.
  1733. Note that ``tgt`` is not added as a dependency of the target this
  1734. expression is evaluated on, unless the expression is being used in
  1735. :command:`add_custom_command` or :command:`add_custom_target`.
  1736. .. genex:: $<TARGET_FILE_BASE_NAME:tgt[,POSTFIX:(INCLUDE|EXCLUDE)]>
  1737. .. versionadded:: 3.15
  1738. .. versionadded:: 4.2
  1739. The option ``POSTFIX``, which can be used to control the inclusion or not
  1740. of the :prop_tgt:`<CONFIG>_POSTFIX` target property value as part of the
  1741. base name. The default is ``POSTFIX:INCLUDE``.
  1742. Base name of ``tgt``, i.e. ``$<TARGET_FILE_NAME:tgt>`` without prefix and
  1743. suffix and, optionally, postfix.
  1744. For example, if the ``tgt`` filename is ``libbase_postfix.so``, the base name
  1745. is:
  1746. * ``base_postfix`` for ``$<TARGET_FILE_BASE_NAME:tgt>`` or
  1747. ``$<TARGET_FILE_BASE_NAME:tgt,POSTFIX:INCLUDE>``.
  1748. * ``base`` for ``$<TARGET_FILE_BASE_NAME:tgt,POSTFIX:EXCLUDE>``.
  1749. See also the :prop_tgt:`OUTPUT_NAME`, :prop_tgt:`ARCHIVE_OUTPUT_NAME`,
  1750. :prop_tgt:`LIBRARY_OUTPUT_NAME` and :prop_tgt:`RUNTIME_OUTPUT_NAME`
  1751. target properties, their configuration-specific variants
  1752. :prop_tgt:`OUTPUT_NAME_<CONFIG>`, :prop_tgt:`ARCHIVE_OUTPUT_NAME_<CONFIG>`,
  1753. :prop_tgt:`LIBRARY_OUTPUT_NAME_<CONFIG>` and
  1754. :prop_tgt:`RUNTIME_OUTPUT_NAME_<CONFIG>`, and
  1755. the :prop_tgt:`<CONFIG>_POSTFIX` and :prop_tgt:`DEBUG_POSTFIX` target
  1756. properties.
  1757. Note that ``tgt`` is not added as a dependency of the target this
  1758. expression is evaluated on.
  1759. .. genex:: $<TARGET_FILE_PREFIX:tgt>
  1760. .. versionadded:: 3.15
  1761. Prefix of the ``tgt`` filename (such as ``lib``).
  1762. See also the :prop_tgt:`PREFIX` target property.
  1763. Note that ``tgt`` is not added as a dependency of the target this
  1764. expression is evaluated on.
  1765. .. genex:: $<TARGET_FILE_SUFFIX:tgt>
  1766. .. versionadded:: 3.15
  1767. Suffix of the ``tgt`` filename (extension such as ``.so`` or ``.exe``).
  1768. See also the :prop_tgt:`SUFFIX` target property.
  1769. Note that ``tgt`` is not added as a dependency of the target this
  1770. expression is evaluated on.
  1771. .. genex:: $<TARGET_FILE_NAME:tgt>
  1772. The ``tgt`` filename.
  1773. Note that ``tgt`` is not added as a dependency of the target this
  1774. expression is evaluated on (see policy :policy:`CMP0112`).
  1775. .. genex:: $<TARGET_FILE_DIR:tgt>
  1776. Directory of the ``tgt`` binary file.
  1777. Note that ``tgt`` is not added as a dependency of the target this
  1778. expression is evaluated on (see policy :policy:`CMP0112`).
  1779. .. genex:: $<TARGET_IMPORT_FILE:tgt>
  1780. .. versionadded:: 3.27
  1781. Full path to the linker import file. On DLL platforms, it would be the
  1782. ``.lib`` file. For executables on AIX, and for shared libraries on macOS,
  1783. it could be, respectively, the ``.imp`` or ``.tbd`` import file,
  1784. depending on the value of the :prop_tgt:`ENABLE_EXPORTS` property.
  1785. This expands to an empty string when there is no import file associated
  1786. with the target.
  1787. .. genex:: $<TARGET_IMPORT_FILE_BASE_NAME:tgt[,POSTFIX:(INCLUDE|EXCLUDE)]>
  1788. .. versionadded:: 3.27
  1789. .. versionadded:: 4.2
  1790. The option ``POSTFIX``, which can be used to control the inclusion or not
  1791. of the :prop_tgt:`<CONFIG>_POSTFIX` target property value as part of the
  1792. base name. The default is ``POSTFIX:INCLUDE``.
  1793. Base name of the linker import file of the target ``tgt`` without prefix or
  1794. suffix and, optionally, postfix.
  1795. For example, if the target file name is ``libbase_postfix.tbd``, the base
  1796. name is:
  1797. * ``base_postfix`` for ``$<TARGET_IMPORT_FILE_BASE_NAME:tgt>`` or
  1798. ``$<TARGET_IMPORT_FILE_BASE_NAME:tgt,POSTFIX:INCLUDE>``.
  1799. * ``base`` for ``$<TARGET_IMPORT_FILE_BASE_NAME:tgt,POSTFIX:EXCLUDE>``.
  1800. See also the :prop_tgt:`OUTPUT_NAME` and :prop_tgt:`ARCHIVE_OUTPUT_NAME`
  1801. target properties, their configuration-specific variants
  1802. :prop_tgt:`OUTPUT_NAME_<CONFIG>` and
  1803. :prop_tgt:`ARCHIVE_OUTPUT_NAME_<CONFIG>`, and
  1804. the :prop_tgt:`<CONFIG>_POSTFIX` and :prop_tgt:`DEBUG_POSTFIX` target
  1805. properties.
  1806. Note that ``tgt`` is not added as a dependency of the target this
  1807. expression is evaluated on.
  1808. .. genex:: $<TARGET_IMPORT_FILE_PREFIX:tgt>
  1809. .. versionadded:: 3.27
  1810. Prefix of the import file of the target ``tgt``.
  1811. See also the :prop_tgt:`IMPORT_PREFIX` target property.
  1812. Note that ``tgt`` is not added as a dependency of the target this
  1813. expression is evaluated on.
  1814. .. genex:: $<TARGET_IMPORT_FILE_SUFFIX:tgt>
  1815. .. versionadded:: 3.27
  1816. Suffix of the import file of the target ``tgt``.
  1817. The suffix corresponds to the file extension (such as ``.lib`` or ``.tbd``).
  1818. See also the :prop_tgt:`IMPORT_SUFFIX` target property.
  1819. Note that ``tgt`` is not added as a dependency of the target this
  1820. expression is evaluated on.
  1821. .. genex:: $<TARGET_IMPORT_FILE_NAME:tgt>
  1822. .. versionadded:: 3.27
  1823. Name of the import file of the target ``tgt``.
  1824. Note that ``tgt`` is not added as a dependency of the target this
  1825. expression is evaluated on.
  1826. .. genex:: $<TARGET_IMPORT_FILE_DIR:tgt>
  1827. .. versionadded:: 3.27
  1828. Directory of the import file of the target ``tgt``.
  1829. Note that ``tgt`` is not added as a dependency of the target this
  1830. expression is evaluated on.
  1831. .. genex:: $<TARGET_LINKER_FILE:tgt>
  1832. File used when linking to the ``tgt`` target. This will usually
  1833. be the library that ``tgt`` represents (``.a``, ``.lib``, ``.so``),
  1834. but for a shared library on DLL platforms, it would be the ``.lib``
  1835. import library associated with the DLL.
  1836. .. versionadded:: 3.27
  1837. On macOS, it could be the ``.tbd`` import file associated with the shared
  1838. library, depending on the value of the :prop_tgt:`ENABLE_EXPORTS` property.
  1839. This generator expression is equivalent to
  1840. :genex:`$<TARGET_LINKER_LIBRARY_FILE>` or
  1841. :genex:`$<TARGET_LINKER_IMPORT_FILE>` generator expressions, depending on the
  1842. characteristics of the target and the platform.
  1843. .. genex:: $<TARGET_LINKER_FILE_BASE_NAME:tgt[,POSTFIX:(INCLUDE|EXCLUDE)]>
  1844. .. versionadded:: 3.15
  1845. .. versionadded:: 4.2
  1846. The option ``POSTFIX``, which can be used to control the inclusion or not
  1847. of the :prop_tgt:`<CONFIG>_POSTFIX` target property value as part of the
  1848. base name. The default is ``POSTFIX:INCLUDE``.
  1849. Base name of file used to link the target ``tgt``, i.e.
  1850. :genex:`$<TARGET_LINKER_FILE_NAME:tgt>` without prefix and suffix, and,
  1851. optionally, postfix.
  1852. For example, if target file name is ``libbase_postfix.a``, the base name is:
  1853. * ``base_postfix`` for ``$<TARGET_LINKER_FILE_BASE_NAME:tgt>`` or
  1854. ``$<TARGET_LINKER_FILE_BASE_NAME:tgt,POSTFIX:INCLUDE>``.
  1855. * ``base`` for ``$<TARGET_LINKER_FILE_BASE_NAME:tgt,POSTFIX:EXCLUDE>``.
  1856. See also the :prop_tgt:`OUTPUT_NAME`, :prop_tgt:`ARCHIVE_OUTPUT_NAME`,
  1857. and :prop_tgt:`LIBRARY_OUTPUT_NAME` target properties, their
  1858. configuration-specific variants :prop_tgt:`OUTPUT_NAME_<CONFIG>`,
  1859. :prop_tgt:`ARCHIVE_OUTPUT_NAME_<CONFIG>` and
  1860. :prop_tgt:`LIBRARY_OUTPUT_NAME_<CONFIG>`, and
  1861. the :prop_tgt:`<CONFIG>_POSTFIX` and :prop_tgt:`DEBUG_POSTFIX` target
  1862. properties.
  1863. Note that ``tgt`` is not added as a dependency of the target this
  1864. expression is evaluated on.
  1865. .. genex:: $<TARGET_LINKER_FILE_PREFIX:tgt>
  1866. .. versionadded:: 3.15
  1867. Prefix of file used to link target ``tgt``.
  1868. See also the :prop_tgt:`PREFIX` and :prop_tgt:`IMPORT_PREFIX` target
  1869. properties.
  1870. Note that ``tgt`` is not added as a dependency of the target this
  1871. expression is evaluated on.
  1872. .. genex:: $<TARGET_LINKER_FILE_SUFFIX:tgt>
  1873. .. versionadded:: 3.15
  1874. Suffix of file used to link where ``tgt`` is the name of a target.
  1875. The suffix corresponds to the file extension (such as ".so" or ".lib").
  1876. See also the :prop_tgt:`SUFFIX` and :prop_tgt:`IMPORT_SUFFIX` target
  1877. properties.
  1878. Note that ``tgt`` is not added as a dependency of the target this
  1879. expression is evaluated on.
  1880. .. genex:: $<TARGET_LINKER_FILE_NAME:tgt>
  1881. Name of file used to link target ``tgt``.
  1882. Note that ``tgt`` is not added as a dependency of the target this
  1883. expression is evaluated on (see policy :policy:`CMP0112`).
  1884. .. genex:: $<TARGET_LINKER_FILE_DIR:tgt>
  1885. Directory of file used to link target ``tgt``.
  1886. Note that ``tgt`` is not added as a dependency of the target this
  1887. expression is evaluated on (see policy :policy:`CMP0112`).
  1888. .. genex:: $<TARGET_LINKER_LIBRARY_FILE:tgt>
  1889. .. versionadded:: 3.27
  1890. File used when linking o the ``tgt`` target is done using directly the
  1891. library, and not an import file. This will usually be the library that
  1892. ``tgt`` represents (``.a``, ``.so``, ``.dylib``). So, on DLL platforms, it
  1893. will be an empty string.
  1894. .. genex:: $<TARGET_LINKER_LIBRARY_FILE_BASE_NAME:tgt[,POSTFIX:(INCLUDE|EXCLUDE)]>
  1895. .. versionadded:: 3.27
  1896. .. versionadded:: 4.2
  1897. The option ``POSTFIX``, which can be used to control the inclusion or not
  1898. of the :prop_tgt:`<CONFIG>_POSTFIX` target property value as part of the
  1899. base name. The default is ``POSTFIX:INCLUDE``.
  1900. Base name of library file used to link the target ``tgt``, i.e.
  1901. :genex:`$<TARGET_LINKER_LIBRARY_FILE_NAME:tgt>` without prefix and
  1902. suffix,and, optionally, postfix.
  1903. For example, if target file name is ``libbase_postfix.a``, the base name is:
  1904. * ``base_postfix`` for ``$<TARGET_LINKER_LIBRARY_FILE_BASE_NAME:tgt>`` or
  1905. ``$<TARGET_LINKER_LIBRARY_FILE_BASE_NAME:tgt,POSTFIX:INCLUDE>``.
  1906. * ``base`` for
  1907. ``$<TARGET_LINKER_LIBRARY_FILE_BASE_NAME:tgt,POSTFIX:EXCLUDE>``.
  1908. See also the :prop_tgt:`OUTPUT_NAME`, :prop_tgt:`ARCHIVE_OUTPUT_NAME`,
  1909. and :prop_tgt:`LIBRARY_OUTPUT_NAME` target properties, their
  1910. configuration-specific variants :prop_tgt:`OUTPUT_NAME_<CONFIG>`,
  1911. :prop_tgt:`ARCHIVE_OUTPUT_NAME_<CONFIG>` and
  1912. :prop_tgt:`LIBRARY_OUTPUT_NAME_<CONFIG>`, and
  1913. the :prop_tgt:`<CONFIG>_POSTFIX` and :prop_tgt:`DEBUG_POSTFIX` target
  1914. properties.
  1915. Note that ``tgt`` is not added as a dependency of the target this
  1916. expression is evaluated on.
  1917. .. genex:: $<TARGET_LINKER_LIBRARY_FILE_PREFIX:tgt>
  1918. .. versionadded:: 3.27
  1919. Prefix of the library file used to link target ``tgt``.
  1920. See also the :prop_tgt:`PREFIX` target property.
  1921. Note that ``tgt`` is not added as a dependency of the target this
  1922. expression is evaluated on.
  1923. .. genex:: $<TARGET_LINKER_LIBRARY_FILE_SUFFIX:tgt>
  1924. .. versionadded:: 3.27
  1925. Suffix of the library file used to link target ``tgt``.
  1926. The suffix corresponds to the file extension (such as ".a" or ".dylib").
  1927. See also the :prop_tgt:`SUFFIX` target property.
  1928. Note that ``tgt`` is not added as a dependency of the target this
  1929. expression is evaluated on.
  1930. .. genex:: $<TARGET_LINKER_LIBRARY_FILE_NAME:tgt>
  1931. .. versionadded:: 3.27
  1932. Name of the library file used to link target ``tgt``.
  1933. Note that ``tgt`` is not added as a dependency of the target this
  1934. expression is evaluated on.
  1935. .. genex:: $<TARGET_LINKER_LIBRARY_FILE_DIR:tgt>
  1936. .. versionadded:: 3.27
  1937. Directory of the library file used to link target ``tgt``.
  1938. Note that ``tgt`` is not added as a dependency of the target this
  1939. expression is evaluated on.
  1940. .. genex:: $<TARGET_LINKER_IMPORT_FILE:tgt>
  1941. .. versionadded:: 3.27
  1942. File used when linking to the ``tgt`` target is done using an import
  1943. file. This will usually be the import file that ``tgt`` represents
  1944. (``.lib``, ``.tbd``). So, when no import file is involved in the link step,
  1945. an empty string is returned.
  1946. .. genex:: $<TARGET_LINKER_IMPORT_FILE_BASE_NAME:tgt[,POSTFIX:(INCLUDE|EXCLUDE)]>
  1947. .. versionadded:: 3.27
  1948. .. versionadded:: 4.2
  1949. The option ``POSTFIX``, which can be used to control the inclusion or not
  1950. of the :prop_tgt:`<CONFIG>_POSTFIX` target property value as part of the
  1951. base name. The default is ``POSTFIX:INCLUDE``.
  1952. Base name of the import file used to link the target ``tgt``, i.e.
  1953. :genex:`$<TARGET_LINKER_IMPORT_FILE_NAME:tgt>` without prefix and suffix,
  1954. and, optionally, postfix.
  1955. For example, if target file name is ``libbase_postfix.tbd``, the base name is
  1956. * ``base_postfix`` for ``$<TARGET_LINKER_IMPORT_FILE_BASE_NAME:tgt>`` or
  1957. ``$<TARGET_LINKER_IMPORT_FILE_BASE_NAME:tgt,POSTFIX:INCLUDE>``.
  1958. * ``base`` for
  1959. ``$<TARGET_LINKER_IMPORT_FILE_BASE_NAME:tgt,POSTFIX:EXCLUDE>``.
  1960. See also the :prop_tgt:`OUTPUT_NAME` and :prop_tgt:`ARCHIVE_OUTPUT_NAME`,
  1961. target properties, their configuration-specific variants
  1962. :prop_tgt:`OUTPUT_NAME_<CONFIG>` and
  1963. :prop_tgt:`ARCHIVE_OUTPUT_NAME_<CONFIG>`, and
  1964. the :prop_tgt:`<CONFIG>_POSTFIX` and :prop_tgt:`DEBUG_POSTFIX` target
  1965. properties.
  1966. Note that ``tgt`` is not added as a dependency of the target this
  1967. expression is evaluated on.
  1968. .. genex:: $<TARGET_LINKER_IMPORT_FILE_PREFIX:tgt>
  1969. .. versionadded:: 3.27
  1970. Prefix of the import file used to link target ``tgt``.
  1971. See also the :prop_tgt:`IMPORT_PREFIX` target property.
  1972. Note that ``tgt`` is not added as a dependency of the target this
  1973. expression is evaluated on.
  1974. .. genex:: $<TARGET_LINKER_IMPORT_FILE_SUFFIX:tgt>
  1975. .. versionadded:: 3.27
  1976. Suffix of the import file used to link target ``tgt``.
  1977. The suffix corresponds to the file extension (such as ".lib" or ".tbd").
  1978. See also the :prop_tgt:`IMPORT_SUFFIX` target property.
  1979. Note that ``tgt`` is not added as a dependency of the target this
  1980. expression is evaluated on.
  1981. .. genex:: $<TARGET_LINKER_IMPORT_FILE_NAME:tgt>
  1982. .. versionadded:: 3.27
  1983. Name of the import file used to link target ``tgt``.
  1984. Note that ``tgt`` is not added as a dependency of the target this
  1985. expression is evaluated on.
  1986. .. genex:: $<TARGET_LINKER_IMPORT_FILE_DIR:tgt>
  1987. .. versionadded:: 3.27
  1988. Directory of the import file used to link target ``tgt``.
  1989. Note that ``tgt`` is not added as a dependency of the target this
  1990. expression is evaluated on.
  1991. .. genex:: $<TARGET_SONAME_FILE:tgt>
  1992. File with soname (``.so.3``) where ``tgt`` is the name of a target.
  1993. .. genex:: $<TARGET_SONAME_FILE_NAME:tgt>
  1994. Name of file with soname (``.so.3``).
  1995. Note that ``tgt`` is not added as a dependency of the target this
  1996. expression is evaluated on (see policy :policy:`CMP0112`).
  1997. .. genex:: $<TARGET_SONAME_FILE_DIR:tgt>
  1998. Directory of file with soname (``.so.3``).
  1999. Note that ``tgt`` is not added as a dependency of the target this
  2000. expression is evaluated on (see policy :policy:`CMP0112`).
  2001. .. genex:: $<TARGET_SONAME_IMPORT_FILE:tgt>
  2002. .. versionadded:: 3.27
  2003. Import file with soname (``.3.tbd``) where ``tgt`` is the name of a target.
  2004. .. genex:: $<TARGET_SONAME_IMPORT_FILE_NAME:tgt>
  2005. .. versionadded:: 3.27
  2006. Name of the import file with soname (``.3.tbd``).
  2007. Note that ``tgt`` is not added as a dependency of the target this
  2008. expression is evaluated on.
  2009. .. genex:: $<TARGET_SONAME_IMPORT_FILE_DIR:tgt>
  2010. .. versionadded:: 3.27
  2011. Directory of the import file with soname (``.3.tbd``).
  2012. Note that ``tgt`` is not added as a dependency of the target this
  2013. expression is evaluated on.
  2014. .. genex:: $<TARGET_PDB_FILE:tgt>
  2015. .. versionadded:: 3.1
  2016. Full path to the linker generated program database file (.pdb)
  2017. where ``tgt`` is the name of a target.
  2018. .. versionchanged:: 4.2
  2019. The postfix, as specified by :prop_tgt:`DEBUG_POSTFIX` or
  2020. :prop_tgt:`<CONFIG>_POSTFIX` target properties, is always included in the
  2021. ``PDB`` file name. See the policy :policy:`CMP0202`.
  2022. See also the :prop_tgt:`PDB_NAME` and :prop_tgt:`PDB_OUTPUT_DIRECTORY`
  2023. target properties and their configuration specific variants
  2024. :prop_tgt:`PDB_NAME_<CONFIG>` and :prop_tgt:`PDB_OUTPUT_DIRECTORY_<CONFIG>`.
  2025. .. genex:: $<TARGET_PDB_FILE_BASE_NAME:tgt[,POSTFIX:(INCLUDE|EXCLUDE)]>
  2026. .. versionadded:: 3.15
  2027. Base name of the linker generated program database file (.pdb)
  2028. where ``tgt`` is the name of a target.
  2029. .. versionadded:: 4.2
  2030. The option ``POSTFIX``, which can be used to control the inclusion or not
  2031. of the :prop_tgt:`<CONFIG>_POSTFIX` target property value as part of the
  2032. base name. The default is ``POSTFIX:INCLUDE``.
  2033. .. versionchanged:: 4.2
  2034. The postfix, as specified by :prop_tgt:`DEBUG_POSTFIX` or
  2035. :prop_tgt:`<CONFIG>_POSTFIX` target properties, is always included in the
  2036. ``PDB`` base name, except if option ``POSTFIX`` has value ``EXCLUDE``.
  2037. See the policy :policy:`CMP0202`.
  2038. The base name corresponds to the target PDB file name (see
  2039. ``$<TARGET_PDB_FILE_NAME:tgt>``) without prefix and suffix, and, optionally,
  2040. postfix. For example, if target file name is ``base_postfix.pdb``, the base
  2041. name is
  2042. * ``base_postfix`` for ``$<TARGET_PDB_FILE_BASE_NAME:tgt>`` or
  2043. ``$<TARGET_PDB_FILE_BASE_NAME:tgt,POSTFIX:INCLUDE>``.
  2044. * ``base`` for ``$<TARGET_PDB_FILE_BASE_NAME:tgt,POSTFIX:EXCLUDE>``.
  2045. See also the :prop_tgt:`OUTPUT_NAME`, :prop_tgt:`PDB_NAME` target properties,
  2046. and their configuration-specific variants :prop_tgt:`OUTPUT_NAME_<CONFIG>`
  2047. and :prop_tgt:`PDB_NAME_<CONFIG>`, and the :prop_tgt:`<CONFIG>_POSTFIX` and
  2048. :prop_tgt:`DEBUG_POSTFIX` target properties.
  2049. Note that ``tgt`` is not added as a dependency of the target this
  2050. expression is evaluated on.
  2051. .. genex:: $<TARGET_PDB_FILE_NAME:tgt>
  2052. .. versionadded:: 3.1
  2053. Name of the linker generated program database file (.pdb).
  2054. Note that ``tgt`` is not added as a dependency of the target this
  2055. expression is evaluated on (see policy :policy:`CMP0112`).
  2056. .. genex:: $<TARGET_PDB_FILE_DIR:tgt>
  2057. .. versionadded:: 3.1
  2058. Directory of the linker generated program database file (.pdb).
  2059. Note that ``tgt`` is not added as a dependency of the target this
  2060. expression is evaluated on (see policy :policy:`CMP0112`).
  2061. .. genex:: $<TARGET_BUNDLE_DIR:tgt>
  2062. .. versionadded:: 3.9
  2063. Full path to the bundle directory (``/path/to/my.app``,
  2064. ``/path/to/my.framework``, or ``/path/to/my.bundle``),
  2065. where ``tgt`` is the name of a target.
  2066. Note that ``tgt`` is not added as a dependency of the target this
  2067. expression is evaluated on (see policy :policy:`CMP0112`).
  2068. .. genex:: $<TARGET_BUNDLE_DIR_NAME:tgt>
  2069. .. versionadded:: 3.24
  2070. Name of the bundle directory (``my.app``, ``my.framework``, or
  2071. ``my.bundle``), where ``tgt`` is the name of a target.
  2072. Note that ``tgt`` is not added as a dependency of the target this
  2073. expression is evaluated on (see policy :policy:`CMP0112`).
  2074. .. genex:: $<TARGET_BUNDLE_CONTENT_DIR:tgt>
  2075. .. versionadded:: 3.9
  2076. Full path to the bundle content directory where ``tgt`` is the name of a
  2077. target. For the macOS SDK it leads to ``/path/to/my.app/Contents``,
  2078. ``/path/to/my.framework``, or ``/path/to/my.bundle/Contents``.
  2079. For all other SDKs (e.g. iOS) it leads to ``/path/to/my.app``,
  2080. ``/path/to/my.framework``, or ``/path/to/my.bundle`` due to the flat
  2081. bundle structure.
  2082. Note that ``tgt`` is not added as a dependency of the target this
  2083. expression is evaluated on (see policy :policy:`CMP0112`).
  2084. .. genex:: $<TARGET_OBJECTS:tgt>
  2085. .. versionadded:: 3.1
  2086. List of objects resulting from building ``tgt``. This would typically be
  2087. used on :ref:`object library <Object Libraries>` targets.
  2088. .. genex:: $<TARGET_RUNTIME_DLLS:tgt>
  2089. .. versionadded:: 3.21
  2090. List of DLLs that the target depends on at runtime. This is determined by
  2091. the locations of all the ``SHARED`` targets in the target's transitive
  2092. dependencies. If only the directories of the DLLs are needed, see the
  2093. :genex:`TARGET_RUNTIME_DLL_DIRS` generator expression.
  2094. Using this generator expression on targets other than
  2095. executables, ``SHARED`` libraries, and ``MODULE`` libraries is an error.
  2096. **On non-DLL platforms, this expression always evaluates to an empty string**.
  2097. This generator expression can be used to copy all of the DLLs that a target
  2098. depends on into its output directory in a ``POST_BUILD`` custom command using
  2099. the :option:`cmake -E copy -t <cmake-E copy>` command. For example:
  2100. .. code-block:: cmake
  2101. find_package(foo CONFIG REQUIRED) # package generated by install(EXPORT)
  2102. add_executable(exe main.c)
  2103. target_link_libraries(exe PRIVATE foo::foo foo::bar)
  2104. add_custom_command(TARGET exe POST_BUILD
  2105. COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR:exe> $<TARGET_RUNTIME_DLLS:exe>
  2106. COMMAND_EXPAND_LISTS
  2107. )
  2108. .. note::
  2109. :ref:`Imported Targets` are supported only if they know the location
  2110. of their ``.dll`` files. An imported ``SHARED`` library must have
  2111. :prop_tgt:`IMPORTED_LOCATION` set to its ``.dll`` file. See the
  2112. :ref:`add_library imported libraries <add_library imported libraries>`
  2113. section for details. Many :ref:`Find Modules` produce imported targets
  2114. with the ``UNKNOWN`` type and therefore will be ignored.
  2115. On platforms that support runtime paths (``RPATH``), refer to the
  2116. :prop_tgt:`INSTALL_RPATH` target property.
  2117. On Apple platforms, refer to the :prop_tgt:`INSTALL_NAME_DIR` target property.
  2118. .. genex:: $<TARGET_RUNTIME_DLL_DIRS:tgt>
  2119. .. versionadded:: 3.27
  2120. List of the directories which contain the DLLs that the target depends on at
  2121. runtime (see :genex:`TARGET_RUNTIME_DLLS`). This is determined by
  2122. the locations of all the ``SHARED`` targets in the target's transitive
  2123. dependencies. Using this generator expression on targets other than
  2124. executables, ``SHARED`` libraries, and ``MODULE`` libraries is an error.
  2125. **On non-DLL platforms, this expression always evaluates to an empty string**.
  2126. This generator expression can e.g. be used to create a batch file using
  2127. :command:`file(GENERATE)` which sets the PATH environment variable accordingly.
  2128. .. genex:: $<TARGET_INTERMEDIATE_DIR:tgt>
  2129. .. versionadded:: 4.2
  2130. The full path to the directory where intermediate target files, such as
  2131. object and dependency files, are stored.
  2132. Export And Install Expressions
  2133. ------------------------------
  2134. .. genex:: $<INSTALL_INTERFACE:...>
  2135. Content of ``...`` when the property is exported using
  2136. :command:`install(EXPORT)`, and empty otherwise.
  2137. .. genex:: $<BUILD_INTERFACE:...>
  2138. Content of ``...`` when the property is exported using :command:`export`, or
  2139. when the target is used by another target in the same buildsystem. Expands to
  2140. the empty string otherwise.
  2141. .. genex:: $<BUILD_LOCAL_INTERFACE:...>
  2142. .. versionadded:: 3.26
  2143. Content of ``...`` when the target is used by another target in the same
  2144. buildsystem. Expands to the empty string otherwise.
  2145. .. genex:: $<INSTALL_PREFIX>
  2146. Content of the install prefix when the target is exported via
  2147. :command:`install(EXPORT)`, or when evaluated in the
  2148. :prop_tgt:`INSTALL_NAME_DIR` property or the ``INSTALL_NAME_DIR`` argument of
  2149. :command:`install(RUNTIME_DEPENDENCY_SET)`, and empty otherwise.
  2150. .. versionchanged:: 3.27
  2151. Evaluates to the content of the install prefix
  2152. in the code argument of :command:`install(CODE)` or
  2153. the file argument of :command:`install(SCRIPT)`.
  2154. Multi-level Expression Evaluation
  2155. ---------------------------------
  2156. .. genex:: $<GENEX_EVAL:expr>
  2157. .. versionadded:: 3.12
  2158. Content of ``expr`` evaluated as a generator expression in the current
  2159. context. This enables consumption of generator expressions whose
  2160. evaluation results itself in generator expressions.
  2161. .. genex:: $<TARGET_GENEX_EVAL:tgt,expr>
  2162. .. versionadded:: 3.12
  2163. Content of ``expr`` evaluated as a generator expression in the context of
  2164. ``tgt`` target. This enables consumption of custom target properties that
  2165. themselves contain generator expressions.
  2166. Having the capability to evaluate generator expressions is very useful when
  2167. you want to manage custom properties supporting generator expressions.
  2168. For example:
  2169. .. code-block:: cmake
  2170. add_library(foo ...)
  2171. set_property(TARGET foo PROPERTY
  2172. CUSTOM_KEYS $<$<CONFIG:DEBUG>:FOO_EXTRA_THINGS>
  2173. )
  2174. add_custom_target(printFooKeys
  2175. COMMAND ${CMAKE_COMMAND} -E echo $<TARGET_PROPERTY:foo,CUSTOM_KEYS>
  2176. )
  2177. This naive implementation of the ``printFooKeys`` custom command is wrong
  2178. because ``CUSTOM_KEYS`` target property is not evaluated and the content
  2179. is passed as is (i.e. ``$<$<CONFIG:DEBUG>:FOO_EXTRA_THINGS>``).
  2180. To have the expected result (i.e. ``FOO_EXTRA_THINGS`` if config is
  2181. ``Debug``), it is required to evaluate the output of
  2182. ``$<TARGET_PROPERTY:foo,CUSTOM_KEYS>``:
  2183. .. code-block:: cmake
  2184. add_custom_target(printFooKeys
  2185. COMMAND ${CMAKE_COMMAND} -E
  2186. echo $<TARGET_GENEX_EVAL:foo,$<TARGET_PROPERTY:foo,CUSTOM_KEYS>>
  2187. )
  2188. Escaped Characters
  2189. ------------------
  2190. These expressions evaluate to specific string literals. Use them in place of
  2191. the actual string literal where you need to prevent them from having their
  2192. special meaning.
  2193. .. genex:: $<ANGLE-R>
  2194. A literal ``>``. Used for example to compare strings that contain a ``>``.
  2195. .. genex:: $<COMMA>
  2196. A literal ``,``. Used for example to compare strings which contain a ``,``.
  2197. .. genex:: $<SEMICOLON>
  2198. A literal ``;``. Used to prevent list expansion on an argument with ``;``.
  2199. .. genex:: $<QUOTE>
  2200. .. versionadded:: 3.30
  2201. A literal ``"``. Used to allow string literal quotes inside a generator expression.
  2202. Deprecated Expressions
  2203. ----------------------
  2204. .. genex:: $<CONFIGURATION>
  2205. Configuration name. Deprecated since CMake 3.0. Use :genex:`CONFIG` instead.