cmake-generator-expressions.7.rst 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784
  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. A common mistake is to try to split a generator expression across multiple
  82. lines with indenting:
  83. .. code-block:: cmake
  84. # WRONG: New lines and spaces all treated as argument separators, so the
  85. # generator expression is split and not recognized correctly.
  86. target_compile_definitions(tgt PRIVATE
  87. $<$<AND:
  88. $<CXX_COMPILER_ID:GNU>,
  89. $<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,5>
  90. >:HAVE_5_OR_LATER>
  91. )
  92. Again, use helper variables with well-chosen names to build up a readable
  93. expression instead:
  94. .. code-block:: cmake
  95. set(is_gnu "$<CXX_COMPILER_ID:GNU>")
  96. set(v5_or_later "$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,5>")
  97. set(meet_requirements "$<AND:${is_gnu},${v5_or_later}>")
  98. target_compile_definitions(tgt PRIVATE
  99. "$<${meet_requirements}:HAVE_5_OR_LATER>"
  100. )
  101. Debugging
  102. =========
  103. Since generator expressions are evaluated during generation of the buildsystem,
  104. and not during processing of ``CMakeLists.txt`` files, it is not possible to
  105. inspect their result with the :command:`message()` command. One possible way
  106. to generate debug messages is to add a custom target:
  107. .. code-block:: cmake
  108. add_custom_target(genexdebug COMMAND ${CMAKE_COMMAND} -E echo "$<...>")
  109. After running ``cmake``, you can then build the ``genexdebug`` target to print
  110. the result of the ``$<...>`` expression (i.e. run the command
  111. ``cmake --build ... --target genexdebug``).
  112. Another way is to write debug messages to a file with :command:`file(GENERATE)`:
  113. .. code-block:: cmake
  114. file(GENERATE OUTPUT filename CONTENT "$<...>")
  115. Generator Expression Reference
  116. ==============================
  117. .. note::
  118. This reference deviates from most of the CMake documentation in that it
  119. omits angular brackets ``<...>`` around placeholders like ``condition``,
  120. ``string``, ``target``, etc. This is to prevent an opportunity for those
  121. placeholders to be misinterpreted as generator expressions.
  122. .. _`Conditional Generator Expressions`:
  123. Conditional Expressions
  124. -----------------------
  125. A fundamental category of generator expressions relates to conditional logic.
  126. Two forms of conditional generator expressions are supported:
  127. .. genex:: $<condition:true_string>
  128. Evaluates to ``true_string`` if ``condition`` is ``1``, or an empty string
  129. if ``condition`` evaluates to ``0``. Any other value for ``condition``
  130. results in an error.
  131. .. genex:: $<IF:condition,true_string,false_string>
  132. .. versionadded:: 3.8
  133. Evaluates to ``true_string`` if ``condition`` is ``1``, or ``false_string``
  134. if ``condition`` is ``0``. Any other value for ``condition`` results in an
  135. error.
  136. Typically, the ``condition`` is itself a generator expression. For instance,
  137. the following expression expands to ``DEBUG_MODE`` when the ``Debug``
  138. configuration is used, and the empty string for all other configurations:
  139. .. code-block:: cmake
  140. $<$<CONFIG:Debug>:DEBUG_MODE>
  141. Boolean-like ``condition`` values other than ``1`` or ``0`` can be handled
  142. by wrapping them with the ``$<BOOL:...>`` generator expression:
  143. .. genex:: $<BOOL:string>
  144. Converts ``string`` to ``0`` or ``1``. Evaluates to ``0`` if any of the
  145. following is true:
  146. * ``string`` is empty,
  147. * ``string`` is a case-insensitive equal of
  148. ``0``, ``FALSE``, ``OFF``, ``N``, ``NO``, ``IGNORE``, or ``NOTFOUND``, or
  149. * ``string`` ends in the suffix ``-NOTFOUND`` (case-sensitive).
  150. Otherwise evaluates to ``1``.
  151. The ``$<BOOL:...>`` generator expression is often used when a ``condition``
  152. is provided by a CMake variable:
  153. .. code-block:: cmake
  154. $<$<BOOL:${HAVE_SOME_FEATURE}>:-DENABLE_SOME_FEATURE>
  155. .. _`Boolean Generator Expressions`:
  156. Logical Operators
  157. -----------------
  158. The common boolean logic operators are supported:
  159. .. genex:: $<AND:conditions>
  160. where ``conditions`` is a comma-separated list of boolean expressions,
  161. all of which must evaluate to either ``1`` or ``0``. The whole expression
  162. evaluates to ``1`` if all conditions are ``1``. If any condition is ``0``,
  163. the whole expression evaluates to ``0``.
  164. .. genex:: $<OR:conditions>
  165. where ``conditions`` is a comma-separated list of boolean expressions.
  166. all of which must evaluate to either ``1`` or ``0``. The whole expression
  167. evaluates to ``1`` if at least one of the ``conditions`` is ``1``. If all
  168. ``conditions`` evaluate to ``0``, the whole expression evaluates to ``0``.
  169. .. genex:: $<NOT:condition>
  170. ``condition`` must be ``0`` or ``1``. The result of the expression is
  171. ``0`` if ``condition`` is ``1``, else ``1``.
  172. .. _`Comparison Expressions`:
  173. Primary Comparison Expressions
  174. ------------------------------
  175. CMake supports a variety of generator expressions that compare things.
  176. This section covers the primary and most widely used comparison types.
  177. Other more specific comparison types are documented in their own separate
  178. sections further below.
  179. String Comparisons
  180. ^^^^^^^^^^^^^^^^^^
  181. .. genex:: $<STREQUAL:string1,string2>
  182. ``1`` if ``string1`` and ``string2`` are equal, else ``0``.
  183. The comparison is case-sensitive. For a case-insensitive comparison,
  184. combine with a :ref:`string transforming generator expression
  185. <String Transforming Generator Expressions>`. For example, the following
  186. evaluates to ``1`` if ``${foo}`` is any of ``BAR``, ``Bar``, ``bar``, etc.
  187. .. code-block:: cmake
  188. $<STREQUAL:$<UPPER_CASE:${foo}>,BAR>
  189. .. genex:: $<EQUAL:value1,value2>
  190. ``1`` if ``value1`` and ``value2`` are numerically equal, else ``0``.
  191. Version Comparisons
  192. ^^^^^^^^^^^^^^^^^^^
  193. .. genex:: $<VERSION_LESS:v1,v2>
  194. ``1`` if ``v1`` is a version less than ``v2``, else ``0``.
  195. .. genex:: $<VERSION_GREATER:v1,v2>
  196. ``1`` if ``v1`` is a version greater than ``v2``, else ``0``.
  197. .. genex:: $<VERSION_EQUAL:v1,v2>
  198. ``1`` if ``v1`` is the same version as ``v2``, else ``0``.
  199. .. genex:: $<VERSION_LESS_EQUAL:v1,v2>
  200. .. versionadded:: 3.7
  201. ``1`` if ``v1`` is a version less than or equal to ``v2``, else ``0``.
  202. .. genex:: $<VERSION_GREATER_EQUAL:v1,v2>
  203. .. versionadded:: 3.7
  204. ``1`` if ``v1`` is a version greater than or equal to ``v2``, else ``0``.
  205. .. _`String Transforming Generator Expressions`:
  206. String Transformations
  207. ----------------------
  208. .. genex:: $<LOWER_CASE:string>
  209. Content of ``string`` converted to lower case.
  210. .. genex:: $<UPPER_CASE:string>
  211. Content of ``string`` converted to upper case.
  212. .. genex:: $<MAKE_C_IDENTIFIER:...>
  213. Content of ``...`` converted to a C identifier. The conversion follows the
  214. same behavior as :command:`string(MAKE_C_IDENTIFIER)`.
  215. List Expressions
  216. ----------------
  217. .. genex:: $<IN_LIST:string,list>
  218. .. versionadded:: 3.12
  219. ``1`` if ``string`` is an item in the semicolon-separated ``list``, else ``0``.
  220. It uses case-sensitive comparisons.
  221. .. genex:: $<JOIN:list,string>
  222. Joins the list with the content of ``string`` inserted between each item.
  223. .. genex:: $<REMOVE_DUPLICATES:list>
  224. .. versionadded:: 3.15
  225. Removes duplicated items in the given ``list``. The relative order of items
  226. is preserved, but if duplicates are encountered, only the first instance is
  227. preserved.
  228. .. genex:: $<FILTER:list,INCLUDE|EXCLUDE,regex>
  229. .. versionadded:: 3.15
  230. Includes or removes items from ``list`` that match the regular expression
  231. ``regex``.
  232. Path Expressions
  233. ----------------
  234. Most of the expressions in this section are closely associated with the
  235. :command:`cmake_path` command, providing the same capabilities, but in
  236. the form of a generator expression.
  237. For all generator expressions in this section, paths are expected to be in
  238. cmake-style format. The :ref:`$\<PATH:CMAKE_PATH\> <GenEx PATH-CMAKE_PATH>`
  239. generator expression can be used to convert a native path to a cmake-style
  240. one.
  241. .. _GenEx Path Comparisons:
  242. Path Comparisons
  243. ^^^^^^^^^^^^^^^^
  244. .. genex:: $<PATH_EQUAL:path1,path2>
  245. .. versionadded:: 3.24
  246. Compares the lexical representations of two paths. No normalization is
  247. performed on either path. Returns ``1`` if the paths are equal, ``0``
  248. otherwise.
  249. See :ref:`cmake_path(COMPARE) <Path COMPARE>` for more details.
  250. .. _GenEx Path Queries:
  251. Path Queries
  252. ^^^^^^^^^^^^
  253. These expressions provide the generation-time capabilities equivalent to the
  254. :ref:`Query <Path Query>` options of the :command:`cmake_path` command.
  255. All paths are expected to be in cmake-style format.
  256. .. genex:: $<PATH:HAS_*,path>
  257. .. versionadded:: 3.24
  258. The following operations return ``1`` if the particular path component is
  259. present, ``0`` otherwise. See :ref:`Path Structure And Terminology` for the
  260. meaning of each path component.
  261. ::
  262. $<PATH:HAS_ROOT_NAME,path>
  263. $<PATH:HAS_ROOT_DIRECTORY,path>
  264. $<PATH:HAS_ROOT_PATH,path>
  265. $<PATH:HAS_FILENAME,path>
  266. $<PATH:HAS_EXTENSION,path>
  267. $<PATH:HAS_STEM,path>
  268. $<PATH:HAS_RELATIVE_PART,path>
  269. $<PATH:HAS_PARENT_PATH,path>
  270. Note the following special cases:
  271. * For ``HAS_ROOT_PATH``, a true result will only be returned if at least one
  272. of ``root-name`` or ``root-directory`` is non-empty.
  273. * For ``HAS_PARENT_PATH``, the root directory is also considered to have a
  274. parent, which will be itself. The result is true except if the path
  275. consists of just a :ref:`filename <FILENAME_DEF>`.
  276. .. genex:: $<PATH:IS_ABSOLUTE,path>
  277. .. versionadded:: 3.24
  278. Returns ``1`` if the path is :ref:`absolute <IS_ABSOLUTE>`, ``0`` otherwise.
  279. .. genex:: $<PATH:IS_RELATIVE,path>
  280. .. versionadded:: 3.24
  281. This will return the opposite of ``IS_ABSOLUTE``.
  282. .. genex:: $<PATH:IS_PREFIX[,NORMALIZE],path,input>
  283. .. versionadded:: 3.24
  284. Returns ``1`` if ``path`` is the prefix of ``input``, ``0`` otherwise.
  285. When the ``NORMALIZE`` option is specified, ``path`` and ``input`` are
  286. :ref:`normalized <Normalization>` before the check.
  287. .. _GenEx Path Decomposition:
  288. Path Decomposition
  289. ^^^^^^^^^^^^^^^^^^
  290. These expressions provide the generation-time capabilities equivalent to the
  291. :ref:`Decomposition <Path Decomposition>` options of the :command:`cmake_path`
  292. command. All paths are expected to be in cmake-style format.
  293. .. genex:: $<PATH:GET_*,...>
  294. .. versionadded:: 3.24
  295. The following operations retrieve a different component or group of
  296. components from a path. See :ref:`Path Structure And Terminology` for the
  297. meaning of each path component.
  298. ::
  299. $<PATH:GET_ROOT_NAME,path>
  300. $<PATH:GET_ROOT_DIRECTORY,path>
  301. $<PATH:GET_ROOT_PATH,path>
  302. $<PATH:GET_FILENAME,path>
  303. $<PATH:GET_EXTENSION[,LAST_ONLY],path>
  304. $<PATH:GET_STEM[,LAST_ONLY],path>
  305. $<PATH:GET_RELATIVE_PART,path>
  306. $<PATH:GET_PARENT_PATH,path>
  307. If a requested component is not present in the path, an empty string is
  308. returned.
  309. .. _GenEx Path Transformations:
  310. Path Transformations
  311. ^^^^^^^^^^^^^^^^^^^^
  312. These expressions provide the generation-time capabilities equivalent to the
  313. :ref:`Modification <Path Modification>` and :ref:`Generation <Path Generation>`
  314. options of the :command:`cmake_path` command. All paths are expected to be
  315. in cmake-style format.
  316. .. _GenEx PATH-CMAKE_PATH:
  317. .. genex:: $<PATH:CMAKE_PATH[,NORMALIZE],path>
  318. .. versionadded:: 3.24
  319. Returns ``path``. If ``path`` is a native path, it is converted into a
  320. cmake-style path with forward-slashes (``/``). On Windows, the long filename
  321. marker is taken into account.
  322. When the ``NORMALIZE`` option is specified, the path is :ref:`normalized
  323. <Normalization>` after the conversion.
  324. .. genex:: $<PATH:APPEND,path,input,...>
  325. .. versionadded:: 3.24
  326. Returns all the ``input`` arguments appended to ``path`` using ``/`` as the
  327. ``directory-separator``. Depending on the ``input``, the value of ``path``
  328. may be discarded.
  329. See :ref:`cmake_path(APPEND) <APPEND>` for more details.
  330. .. genex:: $<PATH:REMOVE_FILENAME,path>
  331. .. versionadded:: 3.24
  332. Returns ``path`` with filename component (as returned by
  333. ``$<PATH:GET_FILENAME>``) removed. After removal, any trailing
  334. ``directory-separator`` is left alone, if present.
  335. See :ref:`cmake_path(REMOVE_FILENAME) <REMOVE_FILENAME>` for more details.
  336. .. genex:: $<PATH:REPLACE_FILENAME,path,input>
  337. .. versionadded:: 3.24
  338. Returns ``path`` with the filename component replaced by ``input``. If
  339. ``path`` has no filename component (i.e. ``$<PATH:HAS_FILENAME>`` returns
  340. ``0``), ``path`` is unchanged.
  341. See :ref:`cmake_path(REPLACE_FILENAME) <REPLACE_FILENAME>` for more details.
  342. .. genex:: $<PATH:REMOVE_EXTENSION[,LAST_ONLY],path>
  343. .. versionadded:: 3.24
  344. Returns ``path`` with the :ref:`extension <EXTENSION_DEF>` removed, if any.
  345. See :ref:`cmake_path(REMOVE_EXTENSION) <REMOVE_EXTENSION>` for more details.
  346. .. genex:: $<PATH:REPLACE_EXTENSION[,LAST_ONLY],path,input>
  347. .. versionadded:: 3.24
  348. Returns ``path`` with the :ref:`extension <EXTENSION_DEF>` replaced by
  349. ``input``, if any.
  350. See :ref:`cmake_path(REPLACE_EXTENSION) <REPLACE_EXTENSION>` for more details.
  351. .. genex:: $<PATH:NORMAL_PATH,path>
  352. .. versionadded:: 3.24
  353. Returns ``path`` normalized according to the steps described in
  354. :ref:`Normalization`.
  355. .. genex:: $<PATH:RELATIVE_PATH,path,base_directory>
  356. .. versionadded:: 3.24
  357. Returns ``path``, modified to make it relative to the ``base_directory``
  358. argument.
  359. See :ref:`cmake_path(RELATIVE_PATH) <cmake_path-RELATIVE_PATH>` for more
  360. details.
  361. .. genex:: $<PATH:ABSOLUTE_PATH[,NORMALIZE],path,base_directory>
  362. .. versionadded:: 3.24
  363. Returns ``path`` as absolute. If ``path`` is a relative path
  364. (``$<PATH:IS_RELATIVE>`` returns ``1``), it is evaluated relative to the
  365. given base directory specified by ``base_directory`` argument.
  366. When the ``NORMALIZE`` option is specified, the path is
  367. :ref:`normalized <Normalization>` after the path computation.
  368. See :ref:`cmake_path(ABSOLUTE_PATH) <ABSOLUTE_PATH>` for more details.
  369. Shell Paths
  370. ^^^^^^^^^^^
  371. .. genex:: $<SHELL_PATH:...>
  372. .. versionadded:: 3.4
  373. Content of ``...`` converted to shell path style. For example, slashes are
  374. converted to backslashes in Windows shells and drive letters are converted
  375. to posix paths in MSYS shells. The ``...`` must be an absolute path.
  376. .. versionadded:: 3.14
  377. The ``...`` may be a :ref:`semicolon-separated list <CMake Language Lists>`
  378. of paths, in which case each path is converted individually and a result
  379. list is generated using the shell path separator (``:`` on POSIX and
  380. ``;`` on Windows). Be sure to enclose the argument containing this genex
  381. in double quotes in CMake source code so that ``;`` does not split arguments.
  382. Configuration Expressions
  383. -------------------------
  384. .. genex:: $<CONFIG>
  385. Configuration name. Use this instead of the deprecated :genex:`CONFIGURATION`
  386. generator expression.
  387. .. genex:: $<CONFIG:cfgs>
  388. ``1`` if config is any one of the entries in comma-separated list
  389. ``cfgs``, else ``0``. This is a case-insensitive comparison. The mapping in
  390. :prop_tgt:`MAP_IMPORTED_CONFIG_<CONFIG>` is also considered by this
  391. expression when it is evaluated on a property of an :prop_tgt:`IMPORTED`
  392. target.
  393. .. versionchanged:: 3.19
  394. Multiple configurations can be specified for ``cfgs``.
  395. CMake 3.18 and earlier only accepted a single configuration.
  396. .. genex:: $<OUTPUT_CONFIG:...>
  397. .. versionadded:: 3.20
  398. Only valid in :command:`add_custom_command` and :command:`add_custom_target`
  399. as the outer-most generator expression in an argument.
  400. With the :generator:`Ninja Multi-Config` generator, generator expressions
  401. in ``...`` are evaluated using the custom command's "output config".
  402. With other generators, the content of ``...`` is evaluated normally.
  403. .. genex:: $<COMMAND_CONFIG:...>
  404. .. versionadded:: 3.20
  405. Only valid in :command:`add_custom_command` and :command:`add_custom_target`
  406. as the outer-most generator expression in an argument.
  407. With the :generator:`Ninja Multi-Config` generator, generator expressions
  408. in ``...`` are evaluated using the custom command's "command config".
  409. With other generators, the content of ``...`` is evaluated normally.
  410. Toolchain And Language Expressions
  411. ----------------------------------
  412. Platform
  413. ^^^^^^^^
  414. .. genex:: $<PLATFORM_ID>
  415. The current system's CMake platform id.
  416. See also the :variable:`CMAKE_SYSTEM_NAME` variable.
  417. .. genex:: $<PLATFORM_ID:platform_ids>
  418. where ``platform_ids`` is a comma-separated list.
  419. ``1`` if CMake's platform id matches any one of the entries in
  420. ``platform_ids``, otherwise ``0``.
  421. See also the :variable:`CMAKE_SYSTEM_NAME` variable.
  422. Compiler Version
  423. ^^^^^^^^^^^^^^^^
  424. See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable, which is
  425. closely related to the expressions in this sub-section.
  426. .. genex:: $<C_COMPILER_VERSION>
  427. The version of the C compiler used.
  428. .. genex:: $<C_COMPILER_VERSION:version>
  429. ``1`` if the version of the C compiler matches ``version``, otherwise ``0``.
  430. .. genex:: $<CXX_COMPILER_VERSION>
  431. The version of the CXX compiler used.
  432. .. genex:: $<CXX_COMPILER_VERSION:version>
  433. ``1`` if the version of the CXX compiler matches ``version``, otherwise ``0``.
  434. .. genex:: $<CUDA_COMPILER_VERSION>
  435. .. versionadded:: 3.15
  436. The version of the CUDA compiler used.
  437. .. genex:: $<CUDA_COMPILER_VERSION:version>
  438. .. versionadded:: 3.15
  439. ``1`` if the version of the CXX compiler matches ``version``, otherwise ``0``.
  440. .. genex:: $<OBJC_COMPILER_VERSION>
  441. .. versionadded:: 3.16
  442. The version of the OBJC compiler used.
  443. .. genex:: $<OBJC_COMPILER_VERSION:version>
  444. .. versionadded:: 3.16
  445. ``1`` if the version of the OBJC compiler matches ``version``, otherwise ``0``.
  446. .. genex:: $<OBJCXX_COMPILER_VERSION>
  447. .. versionadded:: 3.16
  448. The version of the OBJCXX compiler used.
  449. .. genex:: $<OBJCXX_COMPILER_VERSION:version>
  450. .. versionadded:: 3.16
  451. ``1`` if the version of the OBJCXX compiler matches ``version``, otherwise ``0``.
  452. .. genex:: $<Fortran_COMPILER_VERSION>
  453. The version of the Fortran compiler used.
  454. .. genex:: $<Fortran_COMPILER_VERSION:version>
  455. ``1`` if the version of the Fortran compiler matches ``version``, otherwise ``0``.
  456. .. genex:: $<HIP_COMPILER_VERSION>
  457. .. versionadded:: 3.21
  458. The version of the HIP compiler used.
  459. .. genex:: $<HIP_COMPILER_VERSION:version>
  460. .. versionadded:: 3.21
  461. ``1`` if the version of the HIP compiler matches ``version``, otherwise ``0``.
  462. .. genex:: $<ISPC_COMPILER_VERSION>
  463. .. versionadded:: 3.19
  464. The version of the ISPC compiler used.
  465. .. genex:: $<ISPC_COMPILER_VERSION:version>
  466. .. versionadded:: 3.19
  467. ``1`` if the version of the ISPC compiler matches ``version``, otherwise ``0``.
  468. Compiler Language And ID
  469. ^^^^^^^^^^^^^^^^^^^^^^^^
  470. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable, which is closely
  471. related to most of the expressions in this sub-section.
  472. .. genex:: $<C_COMPILER_ID>
  473. CMake's compiler id of the C compiler used.
  474. .. genex:: $<C_COMPILER_ID:compiler_ids>
  475. where ``compiler_ids`` is a comma-separated list.
  476. ``1`` if CMake's compiler id of the C compiler matches any one
  477. of the entries in ``compiler_ids``, otherwise ``0``.
  478. .. genex:: $<CXX_COMPILER_ID>
  479. CMake's compiler id of the CXX compiler used.
  480. .. genex:: $<CXX_COMPILER_ID:compiler_ids>
  481. where ``compiler_ids`` is a comma-separated list.
  482. ``1`` if CMake's compiler id of the CXX compiler matches any one
  483. of the entries in ``compiler_ids``, otherwise ``0``.
  484. .. genex:: $<CUDA_COMPILER_ID>
  485. .. versionadded:: 3.15
  486. CMake's compiler id of the CUDA compiler used.
  487. .. genex:: $<CUDA_COMPILER_ID:compiler_ids>
  488. .. versionadded:: 3.15
  489. where ``compiler_ids`` is a comma-separated list.
  490. ``1`` if CMake's compiler id of the CUDA compiler matches any one
  491. of the entries in ``compiler_ids``, otherwise ``0``.
  492. .. genex:: $<OBJC_COMPILER_ID>
  493. .. versionadded:: 3.16
  494. CMake's compiler id of the OBJC compiler used.
  495. .. genex:: $<OBJC_COMPILER_ID:compiler_ids>
  496. .. versionadded:: 3.16
  497. where ``compiler_ids`` is a comma-separated list.
  498. ``1`` if CMake's compiler id of the Objective-C compiler matches any one
  499. of the entries in ``compiler_ids``, otherwise ``0``.
  500. .. genex:: $<OBJCXX_COMPILER_ID>
  501. .. versionadded:: 3.16
  502. CMake's compiler id of the OBJCXX compiler used.
  503. .. genex:: $<OBJCXX_COMPILER_ID:compiler_ids>
  504. .. versionadded:: 3.16
  505. where ``compiler_ids`` is a comma-separated list.
  506. ``1`` if CMake's compiler id of the Objective-C++ compiler matches any one
  507. of the entries in ``compiler_ids``, otherwise ``0``.
  508. .. genex:: $<Fortran_COMPILER_ID>
  509. CMake's compiler id of the Fortran compiler used.
  510. .. genex:: $<Fortran_COMPILER_ID:compiler_ids>
  511. where ``compiler_ids`` is a comma-separated list.
  512. ``1`` if CMake's compiler id of the Fortran compiler matches any one
  513. of the entries in ``compiler_ids``, otherwise ``0``.
  514. .. genex:: $<HIP_COMPILER_ID>
  515. .. versionadded:: 3.21
  516. CMake's compiler id of the HIP compiler used.
  517. .. genex:: $<HIP_COMPILER_ID:compiler_ids>
  518. .. versionadded:: 3.21
  519. where ``compiler_ids`` is a comma-separated list.
  520. ``1`` if CMake's compiler id of the HIP compiler matches any one
  521. of the entries in ``compiler_ids``, otherwise ``0``.
  522. .. genex:: $<ISPC_COMPILER_ID>
  523. .. versionadded:: 3.19
  524. CMake's compiler id of the ISPC compiler used.
  525. .. genex:: $<ISPC_COMPILER_ID:compiler_ids>
  526. .. versionadded:: 3.19
  527. where ``compiler_ids`` is a comma-separated list.
  528. ``1`` if CMake's compiler id of the ISPC compiler matches any one
  529. of the entries in ``compiler_ids``, otherwise ``0``.
  530. .. genex:: $<COMPILE_LANGUAGE>
  531. .. versionadded:: 3.3
  532. The compile language of source files when evaluating compile options.
  533. See :ref:`the related boolean expression
  534. <Boolean COMPILE_LANGUAGE Generator Expression>`
  535. ``$<COMPILE_LANGUAGE:language>``
  536. for notes about the portability of this generator expression.
  537. .. _`Boolean COMPILE_LANGUAGE Generator Expression`:
  538. .. genex:: $<COMPILE_LANGUAGE:languages>
  539. .. versionadded:: 3.3
  540. ``1`` when the language used for compilation unit matches any of the entries
  541. in ``languages``, otherwise ``0``. This expression may be used to specify
  542. compile options, compile definitions, and include directories for source
  543. files of a particular language in a target. For example:
  544. .. code-block:: cmake
  545. add_executable(myapp main.cpp foo.c bar.cpp zot.cu)
  546. target_compile_options(myapp
  547. PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
  548. )
  549. target_compile_definitions(myapp
  550. PRIVATE $<$<COMPILE_LANGUAGE:CXX>:COMPILING_CXX>
  551. $<$<COMPILE_LANGUAGE:CUDA>:COMPILING_CUDA>
  552. )
  553. target_include_directories(myapp
  554. PRIVATE $<$<COMPILE_LANGUAGE:CXX,CUDA>:/opt/foo/headers>
  555. )
  556. This specifies the use of the ``-fno-exceptions`` compile option,
  557. ``COMPILING_CXX`` compile definition, and ``cxx_headers`` include
  558. directory for C++ only (compiler id checks elided). It also specifies
  559. a ``COMPILING_CUDA`` compile definition for CUDA.
  560. Note that with :ref:`Visual Studio Generators` and :generator:`Xcode` there
  561. is no way to represent target-wide compile definitions or include directories
  562. separately for ``C`` and ``CXX`` languages.
  563. Also, with :ref:`Visual Studio Generators` there is no way to represent
  564. target-wide flags separately for ``C`` and ``CXX`` languages. Under these
  565. generators, expressions for both C and C++ sources will be evaluated
  566. using ``CXX`` if there are any C++ sources and otherwise using ``C``.
  567. A workaround is to create separate libraries for each source file language
  568. instead:
  569. .. code-block:: cmake
  570. add_library(myapp_c foo.c)
  571. add_library(myapp_cxx bar.cpp)
  572. target_compile_options(myapp_cxx PUBLIC -fno-exceptions)
  573. add_executable(myapp main.cpp)
  574. target_link_libraries(myapp myapp_c myapp_cxx)
  575. .. genex:: $<COMPILE_LANG_AND_ID:language,compiler_ids>
  576. .. versionadded:: 3.15
  577. ``1`` when the language used for compilation unit matches ``language`` and
  578. CMake's compiler id of the ``language`` compiler matches any one of the
  579. entries in ``compiler_ids``, otherwise ``0``. This expression is a short form
  580. for the combination of ``$<COMPILE_LANGUAGE:language>`` and
  581. ``$<LANG_COMPILER_ID:compiler_ids>``. This expression may be used to specify
  582. compile options, compile definitions, and include directories for source
  583. files of a particular language and compiler combination in a target.
  584. For example:
  585. .. code-block:: cmake
  586. add_executable(myapp main.cpp foo.c bar.cpp zot.cu)
  587. target_compile_definitions(myapp
  588. PRIVATE $<$<COMPILE_LANG_AND_ID:CXX,AppleClang,Clang>:COMPILING_CXX_WITH_CLANG>
  589. $<$<COMPILE_LANG_AND_ID:CXX,Intel>:COMPILING_CXX_WITH_INTEL>
  590. $<$<COMPILE_LANG_AND_ID:C,Clang>:COMPILING_C_WITH_CLANG>
  591. )
  592. This specifies the use of different compile definitions based on both
  593. the compiler id and compilation language. This example will have a
  594. ``COMPILING_CXX_WITH_CLANG`` compile definition when Clang is the CXX
  595. compiler, and ``COMPILING_CXX_WITH_INTEL`` when Intel is the CXX compiler.
  596. Likewise, when the C compiler is Clang, it will only see the
  597. ``COMPILING_C_WITH_CLANG`` definition.
  598. Without the ``COMPILE_LANG_AND_ID`` generator expression, the same logic
  599. would be expressed as:
  600. .. code-block:: cmake
  601. target_compile_definitions(myapp
  602. PRIVATE $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:AppleClang,Clang>>:COMPILING_CXX_WITH_CLANG>
  603. $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:Intel>>:COMPILING_CXX_WITH_INTEL>
  604. $<$<AND:$<COMPILE_LANGUAGE:C>,$<C_COMPILER_ID:Clang>>:COMPILING_C_WITH_CLANG>
  605. )
  606. Compile Features
  607. ^^^^^^^^^^^^^^^^
  608. .. genex:: $<COMPILE_FEATURES:features>
  609. .. versionadded:: 3.1
  610. where ``features`` is a comma-separated list.
  611. Evaluates to ``1`` if all of the ``features`` are available for the 'head'
  612. target, and ``0`` otherwise. If this expression is used while evaluating
  613. the link implementation of a target and if any dependency transitively
  614. increases the required :prop_tgt:`C_STANDARD` or :prop_tgt:`CXX_STANDARD`
  615. for the 'head' target, an error is reported. See the
  616. :manual:`cmake-compile-features(7)` manual for information on
  617. compile features and a list of supported compilers.
  618. Linker Language And ID
  619. ^^^^^^^^^^^^^^^^^^^^^^
  620. .. genex:: $<LINK_LANGUAGE>
  621. .. versionadded:: 3.18
  622. The link language of the target when evaluating link options.
  623. See :ref:`the related boolean expression
  624. <Boolean LINK_LANGUAGE Generator Expression>` ``$<LINK_LANGUAGE:languages>``
  625. for notes about the portability of this generator expression.
  626. .. note::
  627. This generator expression is not supported by the link libraries
  628. properties to avoid side-effects due to the double evaluation of
  629. these properties.
  630. .. _`Boolean LINK_LANGUAGE Generator Expression`:
  631. .. genex:: $<LINK_LANGUAGE:languages>
  632. .. versionadded:: 3.18
  633. ``1`` when the language used for link step matches any of the entries
  634. in ``languages``, otherwise ``0``. This expression may be used to specify
  635. link libraries, link options, link directories and link dependencies of a
  636. particular language in a target. For example:
  637. .. code-block:: cmake
  638. add_library(api_C ...)
  639. add_library(api_CXX ...)
  640. add_library(api INTERFACE)
  641. target_link_options(api INTERFACE $<$<LINK_LANGUAGE:C>:-opt_c>
  642. $<$<LINK_LANGUAGE:CXX>:-opt_cxx>)
  643. target_link_libraries(api INTERFACE $<$<LINK_LANGUAGE:C>:api_C>
  644. $<$<LINK_LANGUAGE:CXX>:api_CXX>)
  645. add_executable(myapp1 main.c)
  646. target_link_options(myapp1 PRIVATE api)
  647. add_executable(myapp2 main.cpp)
  648. target_link_options(myapp2 PRIVATE api)
  649. This specifies to use the ``api`` target for linking targets ``myapp1`` and
  650. ``myapp2``. In practice, ``myapp1`` will link with target ``api_C`` and
  651. option ``-opt_c`` because it will use ``C`` as link language. And ``myapp2``
  652. will link with ``api_CXX`` and option ``-opt_cxx`` because ``CXX`` will be
  653. the link language.
  654. .. _`Constraints LINK_LANGUAGE Generator Expression`:
  655. .. note::
  656. To determine the link language of a target, it is required to collect,
  657. transitively, all the targets which will be linked to it. So, for link
  658. libraries properties, a double evaluation will be done. During the first
  659. evaluation, ``$<LINK_LANGUAGE:..>`` expressions will always return ``0``.
  660. The link language computed after this first pass will be used to do the
  661. second pass. To avoid inconsistency, it is required that the second pass
  662. do not change the link language. Moreover, to avoid unexpected
  663. side-effects, it is required to specify complete entities as part of the
  664. ``$<LINK_LANGUAGE:..>`` expression. For example:
  665. .. code-block:: cmake
  666. add_library(lib STATIC file.cxx)
  667. add_library(libother STATIC file.c)
  668. # bad usage
  669. add_executable(myapp1 main.c)
  670. target_link_libraries(myapp1 PRIVATE lib$<$<LINK_LANGUAGE:C>:other>)
  671. # correct usage
  672. add_executable(myapp2 main.c)
  673. target_link_libraries(myapp2 PRIVATE $<$<LINK_LANGUAGE:C>:libother>)
  674. In this example, for ``myapp1``, the first pass will, unexpectedly,
  675. determine that the link language is ``CXX`` because the evaluation of the
  676. generator expression will be an empty string so ``myapp1`` will depends on
  677. target ``lib`` which is ``C++``. On the contrary, for ``myapp2``, the first
  678. evaluation will give ``C`` as link language, so the second pass will
  679. correctly add target ``libother`` as link dependency.
  680. .. genex:: $<LINK_LANG_AND_ID:language,compiler_ids>
  681. .. versionadded:: 3.18
  682. ``1`` when the language used for link step matches ``language`` and the
  683. CMake's compiler id of the language linker matches any one of the entries
  684. in ``compiler_ids``, otherwise ``0``. This expression is a short form for the
  685. combination of ``$<LINK_LANGUAGE:language>`` and
  686. ``$<LANG_COMPILER_ID:compiler_ids>``. This expression may be used to specify
  687. link libraries, link options, link directories and link dependencies of a
  688. particular language and linker combination in a target. For example:
  689. .. code-block:: cmake
  690. add_library(libC_Clang ...)
  691. add_library(libCXX_Clang ...)
  692. add_library(libC_Intel ...)
  693. add_library(libCXX_Intel ...)
  694. add_executable(myapp main.c)
  695. if (CXX_CONFIG)
  696. target_sources(myapp PRIVATE file.cxx)
  697. endif()
  698. target_link_libraries(myapp
  699. PRIVATE $<$<LINK_LANG_AND_ID:CXX,Clang,AppleClang>:libCXX_Clang>
  700. $<$<LINK_LANG_AND_ID:C,Clang,AppleClang>:libC_Clang>
  701. $<$<LINK_LANG_AND_ID:CXX,Intel>:libCXX_Intel>
  702. $<$<LINK_LANG_AND_ID:C,Intel>:libC_Intel>)
  703. This specifies the use of different link libraries based on both the
  704. compiler id and link language. This example will have target ``libCXX_Clang``
  705. as link dependency when ``Clang`` or ``AppleClang`` is the ``CXX``
  706. linker, and ``libCXX_Intel`` when ``Intel`` is the ``CXX`` linker.
  707. Likewise when the ``C`` linker is ``Clang`` or ``AppleClang``, target
  708. ``libC_Clang`` will be added as link dependency and ``libC_Intel`` when
  709. ``Intel`` is the ``C`` linker.
  710. See :ref:`the note related to
  711. <Constraints LINK_LANGUAGE Generator Expression>`
  712. ``$<LINK_LANGUAGE:language>`` for constraints about the usage of this
  713. generator expression.
  714. Link Features
  715. ^^^^^^^^^^^^^
  716. .. genex:: $<LINK_LIBRARY:feature,library-list>
  717. .. versionadded:: 3.24
  718. Specify a set of libraries to link to a target, along with a ``feature``
  719. which provides details about *how* they should be linked. For example:
  720. .. code-block:: cmake
  721. add_library(lib1 STATIC ...)
  722. add_library(lib2 ...)
  723. target_link_libraries(lib2 PRIVATE "$<LINK_LIBRARY:WHOLE_ARCHIVE,lib1>")
  724. This specifies that ``lib2`` should link to ``lib1`` and use the
  725. ``WHOLE_ARCHIVE`` feature when doing so.
  726. Feature names are case-sensitive and may only contain letters, numbers and
  727. underscores. Feature names defined in all uppercase are reserved for CMake's
  728. own built-in features. The pre-defined built-in library features are:
  729. .. include:: ../variable/LINK_LIBRARY_PREDEFINED_FEATURES.txt
  730. Built-in and custom library features are defined in terms of the following
  731. variables:
  732. * :variable:`CMAKE_<LANG>_LINK_LIBRARY_USING_<FEATURE>_SUPPORTED`
  733. * :variable:`CMAKE_<LANG>_LINK_LIBRARY_USING_<FEATURE>`
  734. * :variable:`CMAKE_LINK_LIBRARY_USING_<FEATURE>_SUPPORTED`
  735. * :variable:`CMAKE_LINK_LIBRARY_USING_<FEATURE>`
  736. The value used for each of these variables is the value as set at the end of
  737. the directory scope in which the target was created. The usage is as follows:
  738. 1. If the language-specific
  739. :variable:`CMAKE_<LANG>_LINK_LIBRARY_USING_<FEATURE>_SUPPORTED` variable
  740. is true, the ``feature`` must be defined by the corresponding
  741. :variable:`CMAKE_<LANG>_LINK_LIBRARY_USING_<FEATURE>` variable.
  742. 2. If no language-specific ``feature`` is supported, then the
  743. :variable:`CMAKE_LINK_LIBRARY_USING_<FEATURE>_SUPPORTED` variable must be
  744. true and the ``feature`` must be defined by the corresponding
  745. :variable:`CMAKE_LINK_LIBRARY_USING_<FEATURE>` variable.
  746. The following limitations should be noted:
  747. * The ``library-list`` can specify CMake targets or libraries.
  748. Any CMake target of type :ref:`OBJECT <Object Libraries>`
  749. or :ref:`INTERFACE <Interface Libraries>` will ignore the feature aspect
  750. of the expression and instead be linked in the standard way.
  751. * The ``$<LINK_LIBRARY:...>`` generator expression can only be used to
  752. specify link libraries. In practice, this means it can appear in the
  753. :prop_tgt:`LINK_LIBRARIES`, :prop_tgt:`INTERFACE_LINK_LIBRARIES`, and
  754. :prop_tgt:`INTERFACE_LINK_LIBRARIES_DIRECT` target properties, and be
  755. specified in :command:`target_link_libraries` and :command:`link_libraries`
  756. commands.
  757. * If a ``$<LINK_LIBRARY:...>`` generator expression appears in the
  758. :prop_tgt:`INTERFACE_LINK_LIBRARIES` property of a target, it will be
  759. included in the imported target generated by a :command:`install(EXPORT)`
  760. command. It is the responsibility of the environment consuming this
  761. import to define the link feature used by this expression.
  762. * Each target or library involved in the link step must have at most only
  763. one kind of library feature. The absence of a feature is also incompatible
  764. with all other features. For example:
  765. .. code-block:: cmake
  766. add_library(lib1 ...)
  767. add_library(lib2 ...)
  768. add_library(lib3 ...)
  769. # lib1 will be associated with feature1
  770. target_link_libraries(lib2 PUBLIC "$<LINK_LIBRARY:feature1,lib1>")
  771. # lib1 is being linked with no feature here. This conflicts with the
  772. # use of feature1 in the line above and would result in an error.
  773. target_link_libraries(lib3 PRIVATE lib1 lib2)
  774. Where it isn't possible to use the same feature throughout a build for a
  775. given target or library, the :prop_tgt:`LINK_LIBRARY_OVERRIDE` and
  776. :prop_tgt:`LINK_LIBRARY_OVERRIDE_<LIBRARY>` target properties can be
  777. used to resolve such incompatibilities.
  778. * The ``$<LINK_LIBRARY:...>`` generator expression does not guarantee
  779. that the list of specified targets and libraries will be kept grouped
  780. together. To manage constructs like ``--start-group`` and ``--end-group``,
  781. as supported by the GNU ``ld`` linker, use the :genex:`LINK_GROUP`
  782. generator expression instead.
  783. .. genex:: $<LINK_GROUP:feature,library-list>
  784. .. versionadded:: 3.24
  785. Specify a group of libraries to link to a target, along with a ``feature``
  786. which defines how that group should be linked. For example:
  787. .. code-block:: cmake
  788. add_library(lib1 STATIC ...)
  789. add_library(lib2 ...)
  790. target_link_libraries(lib2 PRIVATE "$<LINK_GROUP:RESCAN,lib1,external>")
  791. This specifies that ``lib2`` should link to ``lib1`` and ``external``, and
  792. that both of those two libraries should be included on the linker command
  793. line according to the definition of the ``RESCAN`` feature.
  794. Feature names are case-sensitive and may only contain letters, numbers and
  795. underscores. Feature names defined in all uppercase are reserved for CMake's
  796. own built-in features. Currently, there is only one pre-defined built-in
  797. group feature:
  798. .. include:: ../variable/LINK_GROUP_PREDEFINED_FEATURES.txt
  799. Built-in and custom group features are defined in terms of the following
  800. variables:
  801. * :variable:`CMAKE_<LANG>_LINK_GROUP_USING_<FEATURE>_SUPPORTED`
  802. * :variable:`CMAKE_<LANG>_LINK_GROUP_USING_<FEATURE>`
  803. * :variable:`CMAKE_LINK_GROUP_USING_<FEATURE>_SUPPORTED`
  804. * :variable:`CMAKE_LINK_GROUP_USING_<FEATURE>`
  805. The value used for each of these variables is the value as set at the end of
  806. the directory scope in which the target was created. The usage is as follows:
  807. 1. If the language-specific
  808. :variable:`CMAKE_<LANG>_LINK_GROUP_USING_<FEATURE>_SUPPORTED` variable
  809. is true, the ``feature`` must be defined by the corresponding
  810. :variable:`CMAKE_<LANG>_LINK_GROUP_USING_<FEATURE>` variable.
  811. 2. If no language-specific ``feature`` is supported, then the
  812. :variable:`CMAKE_LINK_GROUP_USING_<FEATURE>_SUPPORTED` variable must be
  813. true and the ``feature`` must be defined by the corresponding
  814. :variable:`CMAKE_LINK_GROUP_USING_<FEATURE>` variable.
  815. The ``LINK_GROUP`` generator expression is compatible with the
  816. :genex:`LINK_LIBRARY` generator expression. The libraries involved in a
  817. group can be specified using the :genex:`LINK_LIBRARY` generator expression.
  818. Each target or external library involved in the link step is allowed to be
  819. part of multiple groups, but only if all the groups involved specify the
  820. same ``feature``. Such groups will not be merged on the linker command line,
  821. the individual groups will still be preserved. Mixing different group
  822. features for the same target or library is forbidden.
  823. .. code-block:: cmake
  824. add_library(lib1 ...)
  825. add_library(lib2 ...)
  826. add_library(lib3 ...)
  827. add_library(lib4 ...)
  828. add_library(lib5 ...)
  829. target_link_libraries(lib3 PUBLIC "$<LINK_GROUP:feature1,lib1,lib2>")
  830. target_link_libraries(lib4 PRIVATE "$<LINK_GROUP:feature1,lib1,lib3>")
  831. # lib4 will be linked with the groups {lib1,lib2} and {lib1,lib3}.
  832. # Both groups specify the same feature, so this is fine.
  833. target_link_libraries(lib5 PRIVATE "$<LINK_GROUP:feature2,lib1,lib3>")
  834. # An error will be raised here because both lib1 and lib3 are part of two
  835. # groups with different features.
  836. When a target or an external library is involved in the link step as part of
  837. a group and also as not part of any group, any occurrence of the non-group
  838. link item will be replaced by the groups it belongs to.
  839. .. code-block:: cmake
  840. add_library(lib1 ...)
  841. add_library(lib2 ...)
  842. add_library(lib3 ...)
  843. add_library(lib4 ...)
  844. target_link_libraries(lib3 PUBLIC lib1)
  845. target_link_libraries(lib4 PRIVATE lib3 "$<LINK_GROUP:feature1,lib1,lib2>")
  846. # lib4 will only be linked with lib3 and the group {lib1,lib2}
  847. Because ``lib1`` is part of the group defined for ``lib4``, that group then
  848. gets applied back to the use of ``lib1`` for ``lib3``. The end result will
  849. be as though the linking relationship for ``lib3`` had been specified as:
  850. .. code-block:: cmake
  851. target_link_libraries(lib3 PUBLIC "$<LINK_GROUP:feature1,lib1,lib2>")
  852. Be aware that the precedence of the group over the non-group link item can
  853. result in circular dependencies between groups. If this occurs, a fatal
  854. error is raised because circular dependencies are not allowed for groups.
  855. .. code-block:: cmake
  856. add_library(lib1A ...)
  857. add_library(lib1B ...)
  858. add_library(lib2A ...)
  859. add_library(lib2B ...)
  860. add_library(lib3 ...)
  861. # Non-group linking relationships, these are non-circular so far
  862. target_link_libraries(lib1A PUBLIC lib2A)
  863. target_link_libraries(lib2B PUBLIC lib1B)
  864. # The addition of these groups creates circular dependencies
  865. target_link_libraries(lib3 PRIVATE
  866. "$<LINK_GROUP:feat,lib1A,lib1B>"
  867. "$<LINK_GROUP:feat,lib2A,lib2B>"
  868. )
  869. Because of the groups defined for ``lib3``, the linking relationships for
  870. ``lib1A`` and ``lib2B`` effectively get expanded to the equivalent of:
  871. .. code-block:: cmake
  872. target_link_libraries(lib1A PUBLIC "$<LINK_GROUP:feat,lib2A,lib2B>")
  873. target_link_libraries(lib2B PUBLIC "$<LINK_GROUP:feat,lib1A,lib1B>")
  874. This creates a circular dependency between groups:
  875. ``lib1A --> lib2B --> lib1A``.
  876. The following limitations should also be noted:
  877. * The ``library-list`` can specify CMake targets or libraries.
  878. Any CMake target of type :ref:`OBJECT <Object Libraries>`
  879. or :ref:`INTERFACE <Interface Libraries>` will ignore the feature aspect
  880. of the expression and instead be linked in the standard way.
  881. * The ``$<LINK_GROUP:...>`` generator expression can only be used to
  882. specify link libraries. In practice, this means it can appear in the
  883. :prop_tgt:`LINK_LIBRARIES`, :prop_tgt:`INTERFACE_LINK_LIBRARIES`,and
  884. :prop_tgt:`INTERFACE_LINK_LIBRARIES_DIRECT` target properties, and be
  885. specified in :command:`target_link_libraries` and :command:`link_libraries`
  886. commands.
  887. * If a ``$<LINK_GROUP:...>`` generator expression appears in the
  888. :prop_tgt:`INTERFACE_LINK_LIBRARIES` property of a target, it will be
  889. included in the imported target generated by a :command:`install(EXPORT)`
  890. command. It is the responsibility of the environment consuming this
  891. import to define the link feature used by this expression.
  892. Link Context
  893. ^^^^^^^^^^^^
  894. .. genex:: $<LINK_ONLY:...>
  895. .. versionadded:: 3.1
  896. Content of ``...``, except while collecting :ref:`Target Usage Requirements`,
  897. in which case it is the empty string. This is intended for use in an
  898. :prop_tgt:`INTERFACE_LINK_LIBRARIES` target property, typically populated
  899. via the :command:`target_link_libraries` command, to specify private link
  900. dependencies without other usage requirements.
  901. .. versionadded:: 3.24
  902. ``LINK_ONLY`` may also be used in a :prop_tgt:`LINK_LIBRARIES` target
  903. property. See policy :policy:`CMP0131`.
  904. .. genex:: $<DEVICE_LINK:list>
  905. .. versionadded:: 3.18
  906. Returns the list if it is the device link step, an empty list otherwise.
  907. The device link step is controlled by :prop_tgt:`CUDA_SEPARABLE_COMPILATION`
  908. and :prop_tgt:`CUDA_RESOLVE_DEVICE_SYMBOLS` properties and
  909. policy :policy:`CMP0105`. This expression can only be used to specify link
  910. options.
  911. .. genex:: $<HOST_LINK:list>
  912. .. versionadded:: 3.18
  913. Returns the list if it is the normal link step, an empty list otherwise.
  914. This expression is mainly useful when a device link step is also involved
  915. (see :genex:`$<DEVICE_LINK:list>` generator expression). This expression can
  916. only be used to specify link options.
  917. .. _`Target-Dependent Queries`:
  918. Target-Dependent Expressions
  919. ----------------------------
  920. These queries refer to a target ``tgt``. Unless otherwise stated, this can
  921. be any runtime artifact, namely:
  922. * An executable target created by :command:`add_executable`.
  923. * A shared library target (``.so``, ``.dll`` but not their ``.lib`` import
  924. library) created by :command:`add_library`.
  925. * A static library target created by :command:`add_library`.
  926. In the following, the phrase "the ``tgt`` filename" means the name of the
  927. ``tgt`` binary file. This has to be distinguished from the phrase
  928. "the target name", which is just the string ``tgt``.
  929. .. genex:: $<TARGET_EXISTS:tgt>
  930. .. versionadded:: 3.12
  931. ``1`` if ``tgt`` exists as a CMake target, else ``0``.
  932. .. genex:: $<TARGET_NAME_IF_EXISTS:tgt>
  933. .. versionadded:: 3.12
  934. The target name ``tgt`` if the target exists, an empty string otherwise.
  935. Note that ``tgt`` is not added as a dependency of the target this
  936. expression is evaluated on.
  937. .. genex:: $<TARGET_NAME:...>
  938. Marks ``...`` as being the name of a target. This is required if exporting
  939. targets to multiple dependent export sets. The ``...`` must be a literal
  940. name of a target, it may not contain generator expressions.
  941. .. genex:: $<TARGET_PROPERTY:tgt,prop>
  942. Value of the property ``prop`` on the target ``tgt``.
  943. Note that ``tgt`` is not added as a dependency of the target this
  944. expression is evaluated on.
  945. .. genex:: $<TARGET_PROPERTY:prop>
  946. Value of the property ``prop`` on the target for which the expression
  947. is being evaluated. Note that for generator expressions in
  948. :ref:`Target Usage Requirements` this is the consuming target rather
  949. than the target specifying the requirement.
  950. .. genex:: $<TARGET_OBJECTS:tgt>
  951. .. versionadded:: 3.1
  952. List of objects resulting from building ``tgt``. This would typically be
  953. used on :ref:`object library <Object Libraries>` targets.
  954. .. genex:: $<TARGET_POLICY:policy>
  955. ``1`` if the ``policy`` was ``NEW`` when the 'head' target was created,
  956. else ``0``. If the ``policy`` was not set, the warning message for the policy
  957. will be emitted. This generator expression only works for a subset of
  958. policies.
  959. .. genex:: $<TARGET_FILE:tgt>
  960. Full path to the ``tgt`` binary file.
  961. Note that ``tgt`` is not added as a dependency of the target this
  962. expression is evaluated on, unless the expression is being used in
  963. :command:`add_custom_command` or :command:`add_custom_target`.
  964. .. genex:: $<TARGET_FILE_BASE_NAME:tgt>
  965. .. versionadded:: 3.15
  966. Base name of ``tgt``, i.e. ``$<TARGET_FILE_NAME:tgt>`` without prefix and
  967. suffix.
  968. For example, if the ``tgt`` filename is ``libbase.so``, the base name is ``base``.
  969. See also the :prop_tgt:`OUTPUT_NAME`, :prop_tgt:`ARCHIVE_OUTPUT_NAME`,
  970. :prop_tgt:`LIBRARY_OUTPUT_NAME` and :prop_tgt:`RUNTIME_OUTPUT_NAME`
  971. target properties and their configuration specific variants
  972. :prop_tgt:`OUTPUT_NAME_<CONFIG>`, :prop_tgt:`ARCHIVE_OUTPUT_NAME_<CONFIG>`,
  973. :prop_tgt:`LIBRARY_OUTPUT_NAME_<CONFIG>` and
  974. :prop_tgt:`RUNTIME_OUTPUT_NAME_<CONFIG>`.
  975. The :prop_tgt:`<CONFIG>_POSTFIX` and :prop_tgt:`DEBUG_POSTFIX` target
  976. properties can also be considered.
  977. Note that ``tgt`` is not added as a dependency of the target this
  978. expression is evaluated on.
  979. .. genex:: $<TARGET_FILE_PREFIX:tgt>
  980. .. versionadded:: 3.15
  981. Prefix of the ``tgt`` filename (such as ``lib``).
  982. See also the :prop_tgt:`PREFIX` target property.
  983. Note that ``tgt`` is not added as a dependency of the target this
  984. expression is evaluated on.
  985. .. genex:: $<TARGET_FILE_SUFFIX:tgt>
  986. .. versionadded:: 3.15
  987. Suffix of the ``tgt`` filename (extension such as ``.so`` or ``.exe``).
  988. See also the :prop_tgt:`SUFFIX` target property.
  989. Note that ``tgt`` is not added as a dependency of the target this
  990. expression is evaluated on.
  991. .. genex:: $<TARGET_FILE_NAME:tgt>
  992. The ``tgt`` filename.
  993. Note that ``tgt`` is not added as a dependency of the target this
  994. expression is evaluated on (see policy :policy:`CMP0112`).
  995. .. genex:: $<TARGET_FILE_DIR:tgt>
  996. Directory of the ``tgt`` binary file.
  997. Note that ``tgt`` is not added as a dependency of the target this
  998. expression is evaluated on (see policy :policy:`CMP0112`).
  999. .. genex:: $<TARGET_LINKER_FILE:tgt>
  1000. File used when linking to the ``tgt`` target. This will usually
  1001. be the library that ``tgt`` represents (``.a``, ``.lib``, ``.so``),
  1002. but for a shared library on DLL platforms, it would be the ``.lib``
  1003. import library associated with the DLL.
  1004. .. genex:: $<TARGET_LINKER_FILE_BASE_NAME:tgt>
  1005. .. versionadded:: 3.15
  1006. Base name of file used to link the target ``tgt``, i.e.
  1007. ``$<TARGET_LINKER_FILE_NAME:tgt>`` without prefix and suffix. For example,
  1008. if target file name is ``libbase.a``, the base name is ``base``.
  1009. See also the :prop_tgt:`OUTPUT_NAME`, :prop_tgt:`ARCHIVE_OUTPUT_NAME`,
  1010. and :prop_tgt:`LIBRARY_OUTPUT_NAME` target properties and their configuration
  1011. specific variants :prop_tgt:`OUTPUT_NAME_<CONFIG>`,
  1012. :prop_tgt:`ARCHIVE_OUTPUT_NAME_<CONFIG>` and
  1013. :prop_tgt:`LIBRARY_OUTPUT_NAME_<CONFIG>`.
  1014. The :prop_tgt:`<CONFIG>_POSTFIX` and :prop_tgt:`DEBUG_POSTFIX` target
  1015. properties can also be considered.
  1016. Note that ``tgt`` is not added as a dependency of the target this
  1017. expression is evaluated on.
  1018. .. genex:: $<TARGET_LINKER_FILE_PREFIX:tgt>
  1019. .. versionadded:: 3.15
  1020. Prefix of file used to link target ``tgt``.
  1021. See also the :prop_tgt:`PREFIX` and :prop_tgt:`IMPORT_PREFIX` target
  1022. properties.
  1023. Note that ``tgt`` is not added as a dependency of the target this
  1024. expression is evaluated on.
  1025. .. genex:: $<TARGET_LINKER_FILE_SUFFIX:tgt>
  1026. .. versionadded:: 3.15
  1027. Suffix of file used to link where ``tgt`` is the name of a target.
  1028. The suffix corresponds to the file extension (such as ".so" or ".lib").
  1029. See also the :prop_tgt:`SUFFIX` and :prop_tgt:`IMPORT_SUFFIX` target
  1030. properties.
  1031. Note that ``tgt`` is not added as a dependency of the target this
  1032. expression is evaluated on.
  1033. .. genex:: $<TARGET_LINKER_FILE_NAME:tgt>
  1034. Name of file used to link target ``tgt``.
  1035. Note that ``tgt`` is not added as a dependency of the target this
  1036. expression is evaluated on (see policy :policy:`CMP0112`).
  1037. .. genex:: $<TARGET_LINKER_FILE_DIR:tgt>
  1038. Directory of file used to link target ``tgt``.
  1039. Note that ``tgt`` is not added as a dependency of the target this
  1040. expression is evaluated on (see policy :policy:`CMP0112`).
  1041. .. genex:: $<TARGET_SONAME_FILE:tgt>
  1042. File with soname (``.so.3``) where ``tgt`` is the name of a target.
  1043. .. genex:: $<TARGET_SONAME_FILE_NAME:tgt>
  1044. Name of file with soname (``.so.3``).
  1045. Note that ``tgt`` is not added as a dependency of the target this
  1046. expression is evaluated on (see policy :policy:`CMP0112`).
  1047. .. genex:: $<TARGET_SONAME_FILE_DIR:tgt>
  1048. Directory of with soname (``.so.3``).
  1049. Note that ``tgt`` is not added as a dependency of the target this
  1050. expression is evaluated on (see policy :policy:`CMP0112`).
  1051. .. genex:: $<TARGET_PDB_FILE:tgt>
  1052. .. versionadded:: 3.1
  1053. Full path to the linker generated program database file (.pdb)
  1054. where ``tgt`` is the name of a target.
  1055. See also the :prop_tgt:`PDB_NAME` and :prop_tgt:`PDB_OUTPUT_DIRECTORY`
  1056. target properties and their configuration specific variants
  1057. :prop_tgt:`PDB_NAME_<CONFIG>` and :prop_tgt:`PDB_OUTPUT_DIRECTORY_<CONFIG>`.
  1058. .. genex:: $<TARGET_PDB_FILE_BASE_NAME:tgt>
  1059. .. versionadded:: 3.15
  1060. Base name of the linker generated program database file (.pdb)
  1061. where ``tgt`` is the name of a target.
  1062. The base name corresponds to the target PDB file name (see
  1063. ``$<TARGET_PDB_FILE_NAME:tgt>``) without prefix and suffix. For example,
  1064. if target file name is ``base.pdb``, the base name is ``base``.
  1065. See also the :prop_tgt:`PDB_NAME` target property and its configuration
  1066. specific variant :prop_tgt:`PDB_NAME_<CONFIG>`.
  1067. The :prop_tgt:`<CONFIG>_POSTFIX` and :prop_tgt:`DEBUG_POSTFIX` target
  1068. properties can also be considered.
  1069. Note that ``tgt`` is not added as a dependency of the target this
  1070. expression is evaluated on.
  1071. .. genex:: $<TARGET_PDB_FILE_NAME:tgt>
  1072. .. versionadded:: 3.1
  1073. Name of the linker generated program database file (.pdb).
  1074. Note that ``tgt`` is not added as a dependency of the target this
  1075. expression is evaluated on (see policy :policy:`CMP0112`).
  1076. .. genex:: $<TARGET_PDB_FILE_DIR:tgt>
  1077. .. versionadded:: 3.1
  1078. Directory of the linker generated program database file (.pdb).
  1079. Note that ``tgt`` is not added as a dependency of the target this
  1080. expression is evaluated on (see policy :policy:`CMP0112`).
  1081. .. genex:: $<TARGET_BUNDLE_DIR:tgt>
  1082. .. versionadded:: 3.9
  1083. Full path to the bundle directory (``/path/to/my.app``,
  1084. ``/path/to/my.framework``, or ``/path/to/my.bundle``),
  1085. where ``tgt`` is the name of a target.
  1086. Note that ``tgt`` is not added as a dependency of the target this
  1087. expression is evaluated on (see policy :policy:`CMP0112`).
  1088. .. genex:: $<TARGET_BUNDLE_DIR_NAME:tgt>
  1089. .. versionadded:: 3.24
  1090. Name of the bundle directory (``my.app``, ``my.framework``, or
  1091. ``my.bundle``), where ``tgt`` is the name of a target.
  1092. Note that ``tgt`` is not added as a dependency of the target this
  1093. expression is evaluated on (see policy :policy:`CMP0112`).
  1094. .. genex:: $<TARGET_BUNDLE_CONTENT_DIR:tgt>
  1095. .. versionadded:: 3.9
  1096. Full path to the bundle content directory where ``tgt`` is the name of a
  1097. target. For the macOS SDK it leads to ``/path/to/my.app/Contents``,
  1098. ``/path/to/my.framework``, or ``/path/to/my.bundle/Contents``.
  1099. For all other SDKs (e.g. iOS) it leads to ``/path/to/my.app``,
  1100. ``/path/to/my.framework``, or ``/path/to/my.bundle`` due to the flat
  1101. bundle structure.
  1102. Note that ``tgt`` is not added as a dependency of the target this
  1103. expression is evaluated on (see policy :policy:`CMP0112`).
  1104. .. genex:: $<TARGET_RUNTIME_DLLS:tgt>
  1105. .. versionadded:: 3.21
  1106. List of DLLs that the target depends on at runtime. This is determined by
  1107. the locations of all the ``SHARED`` targets in the target's transitive
  1108. dependencies. Using this generator expression on targets other than
  1109. executables, ``SHARED`` libraries, and ``MODULE`` libraries is an error.
  1110. **On non-DLL platforms, this expression always evaluates to an empty string**.
  1111. This generator expression can be used to copy all of the DLLs that a target
  1112. depends on into its output directory in a ``POST_BUILD`` custom command. For
  1113. example:
  1114. .. code-block:: cmake
  1115. find_package(foo CONFIG REQUIRED) # package generated by install(EXPORT)
  1116. add_executable(exe main.c)
  1117. target_link_libraries(exe PRIVATE foo::foo foo::bar)
  1118. add_custom_command(TARGET exe POST_BUILD
  1119. COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:exe> $<TARGET_FILE_DIR:exe>
  1120. COMMAND_EXPAND_LISTS
  1121. )
  1122. .. note::
  1123. :ref:`Imported Targets` are supported only if they know the location
  1124. of their ``.dll`` files. An imported ``SHARED`` library must have
  1125. :prop_tgt:`IMPORTED_LOCATION` set to its ``.dll`` file. See the
  1126. :ref:`add_library imported libraries <add_library imported libraries>`
  1127. section for details. Many :ref:`Find Modules` produce imported targets
  1128. with the ``UNKNOWN`` type and therefore will be ignored.
  1129. Export And Install Expressions
  1130. ------------------------------
  1131. .. genex:: $<INSTALL_INTERFACE:...>
  1132. Content of ``...`` when the property is exported using
  1133. :command:`install(EXPORT)`, and empty otherwise.
  1134. .. genex:: $<BUILD_INTERFACE:...>
  1135. Content of ``...`` when the property is exported using :command:`export`, or
  1136. when the target is used by another target in the same buildsystem. Expands to
  1137. the empty string otherwise.
  1138. .. genex:: $<INSTALL_PREFIX>
  1139. Content of the install prefix when the target is exported via
  1140. :command:`install(EXPORT)`, or when evaluated in the
  1141. :prop_tgt:`INSTALL_NAME_DIR` property or the ``INSTALL_NAME_DIR`` argument of
  1142. :command:`install(RUNTIME_DEPENDENCY_SET)`, and empty otherwise.
  1143. Multi-level Expression Evaluation
  1144. ---------------------------------
  1145. .. genex:: $<GENEX_EVAL:expr>
  1146. .. versionadded:: 3.12
  1147. Content of ``expr`` evaluated as a generator expression in the current
  1148. context. This enables consumption of generator expressions whose
  1149. evaluation results itself in generator expressions.
  1150. .. genex:: $<TARGET_GENEX_EVAL:tgt,expr>
  1151. .. versionadded:: 3.12
  1152. Content of ``expr`` evaluated as a generator expression in the context of
  1153. ``tgt`` target. This enables consumption of custom target properties that
  1154. themselves contain generator expressions.
  1155. Having the capability to evaluate generator expressions is very useful when
  1156. you want to manage custom properties supporting generator expressions.
  1157. For example:
  1158. .. code-block:: cmake
  1159. add_library(foo ...)
  1160. set_property(TARGET foo PROPERTY
  1161. CUSTOM_KEYS $<$<CONFIG:DEBUG>:FOO_EXTRA_THINGS>
  1162. )
  1163. add_custom_target(printFooKeys
  1164. COMMAND ${CMAKE_COMMAND} -E echo $<TARGET_PROPERTY:foo,CUSTOM_KEYS>
  1165. )
  1166. This naive implementation of the ``printFooKeys`` custom command is wrong
  1167. because ``CUSTOM_KEYS`` target property is not evaluated and the content
  1168. is passed as is (i.e. ``$<$<CONFIG:DEBUG>:FOO_EXTRA_THINGS>``).
  1169. To have the expected result (i.e. ``FOO_EXTRA_THINGS`` if config is
  1170. ``Debug``), it is required to evaluate the output of
  1171. ``$<TARGET_PROPERTY:foo,CUSTOM_KEYS>``:
  1172. .. code-block:: cmake
  1173. add_custom_target(printFooKeys
  1174. COMMAND ${CMAKE_COMMAND} -E
  1175. echo $<TARGET_GENEX_EVAL:foo,$<TARGET_PROPERTY:foo,CUSTOM_KEYS>>
  1176. )
  1177. Escaped Characters
  1178. ------------------
  1179. These expressions evaluate to specific string literals. Use them in place of
  1180. the actual string literal where you need to prevent them from having their
  1181. special meaning.
  1182. .. genex:: $<ANGLE-R>
  1183. A literal ``>``. Used for example to compare strings that contain a ``>``.
  1184. .. genex:: $<COMMA>
  1185. A literal ``,``. Used for example to compare strings which contain a ``,``.
  1186. .. genex:: $<SEMICOLON>
  1187. A literal ``;``. Used to prevent list expansion on an argument with ``;``.
  1188. Deprecated Expressions
  1189. ----------------------
  1190. .. genex:: $<CONFIGURATION>
  1191. Configuration name. Deprecated since CMake 3.0. Use :genex:`CONFIG` instead.