cmake-generator-expressions.7.rst 57 KB

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