cmake-generator-expressions.7.rst 99 KB

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