1CMAKE-GENERATOR-EXPRESSIONS(7)       CMake      CMAKE-GENERATOR-EXPRESSIONS(7)
2
3
4

NAME

6       cmake-generator-expressions - CMake Generator Expressions
7

INTRODUCTION

9       Generator  expressions  are evaluated during build system generation to
10       produce information specific to each build configuration.
11
12       Generator expressions are allowed in the context of many target proper‐
13       ties,  such as LINK_LIBRARIES, INCLUDE_DIRECTORIES, COMPILE_DEFINITIONS
14       and others.  They may also be used  when  using  commands  to  populate
15       those     properties,    such    as    target_link_libraries(),    tar‐
16       get_include_directories(), target_compile_definitions() and others.
17
18       They enable conditional linking, conditional definitions used when com‐
19       piling,  conditional include directories, and more.  The conditions may
20       be based on the build configuration, target properties, platform infor‐
21       mation or any other queryable information.
22
23       Generator  expressions  have the form $<...>.  To avoid confusion, this
24       page deviates from most of the CMake documentation  in  that  it  omits
25       angular brackets <...> around placeholders like condition, string, tar‐
26       get, among others.
27
28       Generator expressions can be nested, as shown in most of  the  examples
29       below.
30

BOOLEAN GENERATOR EXPRESSIONS

32       Boolean expressions evaluate to either 0 or 1.  They are typically used
33       to construct the condition in a conditional generator expression.
34
35       Available boolean expressions are:
36
37   Logical Operators
38       $<BOOL:string>
39              Converts string to 0 or 1. Evaluates to 0 if any of the  follow‐
40              ing is true:
41
42              · string is empty,
43
44              · string  is  a  case-insensitive equal of 0, FALSE, OFF, N, NO,
45                IGNORE, or NOTFOUND, or
46
47              · string ends in the suffix -NOTFOUND (case-sensitive).
48
49              Otherwise evaluates to 1.
50
51       $<AND:conditions>
52              where conditions is a comma-separated list  of  boolean  expres‐
53              sions.  Evaluates to 1 if all conditions are 1.  Otherwise eval‐
54              uates to 0.
55
56       $<OR:conditions>
57              where conditions is a comma-separated list  of  boolean  expres‐
58              sions.   Evaluates  to 1 if at least one of the conditions is 1.
59              Otherwise evaluates to 0.
60
61       $<NOT:condition>
62              0 if condition is 1, else 1.
63
64   String Comparisons
65       $<STREQUAL:string1,string2>
66              1 if string1 and string2 are equal, else 0.  The  comparison  is
67              case-sensitive.  For a case-insensitive comparison, combine with
68              a string transforming generator expression,
69
70                 $<STREQUAL:$<UPPER_CASE:${foo}>,"BAR"> # "1" if ${foo} is any of "BAR", "Bar", "bar", ...
71
72       $<EQUAL:value1,value2>
73              1 if value1 and value2 are numerically equal, else 0.
74
75       $<IN_LIST:string,list>
76              1 if string is member of the semicolon-separated list,  else  0.
77              Uses case-sensitive comparisons.
78
79       $<VERSION_LESS:v1,v2>
80              1 if v1 is a version less than v2, else 0.
81
82       $<VERSION_GREATER:v1,v2>
83              1 if v1 is a version greater than v2, else 0.
84
85       $<VERSION_EQUAL:v1,v2>
86              1 if v1 is the same version as v2, else 0.
87
88       $<VERSION_LESS_EQUAL:v1,v2>
89              1 if v1 is a version less than or equal to v2, else 0.
90
91       $<VERSION_GREATER_EQUAL:v1,v2>
92              1 if v1 is a version greater than or equal to v2, else 0.
93
94   Variable Queries
95       $<TARGET_EXISTS:target>
96              1 if target exists, else 0.
97
98       $<CONFIG:cfgs>
99              1 if config is any one of the entries in cfgs, else 0. This is a
100              case-insensitive comparison. The  mapping  in  MAP_IMPORTED_CON‐
101              FIG_<CONFIG>  is  also  considered by this expression when it is
102              evaluated on a property on an IMPORTED target.
103
104       $<PLATFORM_ID:platform_ids>
105              where platform_ids is a comma-separated list.  1 if the  CMake’s
106              platform id matches any one of the entries in platform_ids, oth‐
107              erwise 0.  See also the CMAKE_SYSTEM_NAME variable.
108
109       $<C_COMPILER_ID:compiler_ids>
110              where compiler_ids is a comma-separated list.  1 if the  CMake’s
111              compiler  id of the C compiler matches any one of the entries in
112              compiler_ids,  otherwise  0.   See  also  the  CMAKE_<LANG>_COM‐
113              PILER_ID variable.
114
115       $<CXX_COMPILER_ID:compiler_ids>
116              where  compiler_ids is a comma-separated list.  1 if the CMake’s
117              compiler id of the CXX compiler matches any one of  the  entries
118              in  compiler_ids,  otherwise  0.  See also the CMAKE_<LANG>_COM‐
119              PILER_ID variable.
120
121       $<CUDA_COMPILER_ID:compiler_ids>
122              where compiler_ids is a comma-separated list.  1 if the  CMake’s
123              compiler  id of the CUDA compiler matches any one of the entries
124              in compiler_ids, otherwise 0.  See  also  the  CMAKE_<LANG>_COM‐
125              PILER_ID variable.
126
127       $<OBJC_COMPILER_ID:compiler_ids>
128              where  compiler_ids is a comma-separated list.  1 if the CMake’s
129              compiler id of the Objective-C compiler matches any one  of  the
130              entries   in   compiler_ids,   otherwise   0.    See   also  the
131              CMAKE_<LANG>_COMPILER_ID variable.
132
133       $<OBJCXX_COMPILER_ID:compiler_ids>
134              where compiler_ids is a comma-separated list.  1 if the  CMake’s
135              compiler id of the Objective-C++ compiler matches any one of the
136              entries  in   compiler_ids,   otherwise   0.    See   also   the
137              CMAKE_<LANG>_COMPILER_ID variable.
138
139       $<Fortran_COMPILER_ID:compiler_ids>
140              where  compiler_ids is a comma-separated list.  1 if the CMake’s
141              compiler id of the Fortran  compiler  matches  any  one  of  the
142              entries   in   compiler_ids,   otherwise   0.    See   also  the
143              CMAKE_<LANG>_COMPILER_ID variable.
144
145       $<ISPC_COMPILER_ID:compiler_ids>
146              where compiler_ids is a comma-separated list.  1 if the  CMake’s
147              compiler  id of the ISPC compiler matches any one of the entries
148              in compiler_ids, otherwise 0.  See  also  the  CMAKE_<LANG>_COM‐
149              PILER_ID variable.
150
151       $<C_COMPILER_VERSION:version>
152              1 if the version of the C compiler matches version, otherwise 0.
153              See also the CMAKE_<LANG>_COMPILER_VERSION variable.
154
155       $<CXX_COMPILER_VERSION:version>
156              1 if the version of the CXX compiler matches version,  otherwise
157              0.  See also the CMAKE_<LANG>_COMPILER_VERSION variable.
158
159       $<CUDA_COMPILER_VERSION:version>
160              1  if the version of the CXX compiler matches version, otherwise
161              0.  See also the CMAKE_<LANG>_COMPILER_VERSION variable.
162
163       $<OBJC_COMPILER_VERSION:version>
164              1 if the version of the OBJC compiler matches version, otherwise
165              0.  See also the CMAKE_<LANG>_COMPILER_VERSION variable.
166
167       $<OBJCXX_COMPILER_VERSION:version>
168              1  if the version of the OBJCXX compiler matches version, other‐
169              wise 0.  See also the CMAKE_<LANG>_COMPILER_VERSION variable.
170
171       $<Fortran_COMPILER_VERSION:version>
172              1 if the version of the Fortran compiler matches version, other‐
173              wise 0.  See also the CMAKE_<LANG>_COMPILER_VERSION variable.
174
175       $<ISPC_COMPILER_VERSION:version>
176              1 if the version of the ISPC compiler matches version, otherwise
177              0.  See also the CMAKE_<LANG>_COMPILER_VERSION variable.
178
179       $<TARGET_POLICY:policy>
180              1 if the policy was NEW when the ‘head’ target was created, else
181              0.   If the policy was not set, the warning message for the pol‐
182              icy will be emitted. This generator expression only works for  a
183              subset of policies.
184
185       $<COMPILE_FEATURES:features>
186              where features is a comma-spearated list.  Evaluates to 1 if all
187              of the features are available for the ‘head’ target, and 0  oth‐
188              erwise.  If  this  expression  is used while evaluating the link
189              implementation of a target and if  any  dependency  transitively
190              increases the required C_STANDARD or CXX_STANDARD for the ‘head’
191              target, an error is reported.  See the cmake-compile-features(7)
192              manual  for  information  on compile features and a list of sup‐
193              ported compilers.
194
195       $<COMPILE_LANG_AND_ID:language,compiler_ids>
196              1 when the language used for compilation unit  matches  language
197              and the CMake’s compiler id of the language compiler matches any
198              one of the entries in compiler_ids, otherwise 0. This expression
199              is  a  short form for the combination of $<COMPILE_LANGUAGE:lan‐
200              guage> and $<LANG_COMPILER_ID:compiler_ids>. This expression may
201              be  used  to  specify  compile options, compile definitions, and
202              include directories for source files of  a  particular  language
203              and compiler combination in a target. For example:
204
205                 add_executable(myapp main.cpp foo.c bar.cpp zot.cu)
206                 target_compile_definitions(myapp
207                   PRIVATE $<$<COMPILE_LANG_AND_ID:CXX,AppleClang,Clang>:COMPILING_CXX_WITH_CLANG>
208                           $<$<COMPILE_LANG_AND_ID:CXX,Intel>:COMPILING_CXX_WITH_INTEL>
209                           $<$<COMPILE_LANG_AND_ID:C,Clang>:COMPILING_C_WITH_CLANG>
210                 )
211
212              This specifies the use of different compile definitions based on
213              both the compiler id and compilation language. This example will
214              have a COMPILING_CXX_WITH_CLANG compile definition when Clang is
215              the CXX compiler, and COMPILING_CXX_WITH_INTEL when Intel is the
216              CXX  compiler.   Likewise  when  the C compiler is Clang it will
217              only see the  COMPILING_C_WITH_CLANG definition.
218
219              Without the COMPILE_LANG_AND_ID generator  expression  the  same
220              logic would be expressed as:
221
222                 target_compile_definitions(myapp
223                   PRIVATE $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:AppleClang,Clang>>:COMPILING_CXX_WITH_CLANG>
224                           $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:Intel>>:COMPILING_CXX_WITH_INTEL>
225                           $<$<AND:$<COMPILE_LANGUAGE:C>,$<C_COMPILER_ID:Clang>>:COMPILING_C_WITH_CLANG>
226                 )
227
228       $<COMPILE_LANGUAGE:languages>
229              1 when the language used for compilation unit matches any of the
230              entries in languages, otherwise 0.  This expression may be  used
231              to  specify  compile  options,  compile definitions, and include
232              directories for source files of a particular language in a  tar‐
233              get. For example:
234
235                 add_executable(myapp main.cpp foo.c bar.cpp zot.cu)
236                 target_compile_options(myapp
237                   PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
238                 )
239                 target_compile_definitions(myapp
240                   PRIVATE $<$<COMPILE_LANGUAGE:CXX>:COMPILING_CXX>
241                           $<$<COMPILE_LANGUAGE:CUDA>:COMPILING_CUDA>
242                 )
243                 target_include_directories(myapp
244                   PRIVATE $<$<COMPILE_LANGUAGE:CXX,CUDA>:/opt/foo/headers>
245                 )
246
247              This  specifies  the  use of the -fno-exceptions compile option,
248              COMPILING_CXX compile definition, and cxx_headers include direc‐
249              tory  for  C++ only (compiler id checks elided).  It also speci‐
250              fies a COMPILING_CUDA compile definition for CUDA.
251
252              Note that with Visual Studio Generators and Xcode  there  is  no
253              way  to  represent  target-wide  compile  definitions or include
254              directories separately for C and CXX languages.  Also, with Vis‐
255              ual  Studio  Generators there is no way to represent target-wide
256              flags separately for C and CXX languages.  Under  these  genera‐
257              tors,  expressions  for both C and C++ sources will be evaluated
258              using CXX if there are any C++ sources and otherwise using C.  A
259              workaround  is to create separate libraries for each source file
260              language instead:
261
262                 add_library(myapp_c foo.c)
263                 add_library(myapp_cxx bar.cpp)
264                 target_compile_options(myapp_cxx PUBLIC -fno-exceptions)
265                 add_executable(myapp main.cpp)
266                 target_link_libraries(myapp myapp_c myapp_cxx)
267
268       $<LINK_LANG_AND_ID:language,compiler_ids>
269              1 when the language used for link step matches language and  the
270              CMake’s  compiler  id  of the language linker matches any one of
271              the entries in compiler_ids, otherwise 0. This expression  is  a
272              short  form for the combination of $<LINK_LANGUAGE:language> and
273              $<LANG_COMPILER_ID:compiler_ids>. This expression may be used to
274              specify  link libraries, link options, link directories and link
275              dependencies of a particular language and linker combination  in
276              a target. For example:
277
278                 add_library(libC_Clang ...)
279                 add_library(libCXX_Clang ...)
280                 add_library(libC_Intel ...)
281                 add_library(libCXX_Intel ...)
282
283                 add_executable(myapp main.c)
284                 if (CXX_CONFIG)
285                   target_sources(myapp PRIVATE file.cxx)
286                 endif()
287                 target_link_libraries(myapp
288                   PRIVATE $<$<LINK_LANG_AND_ID:CXX,Clang,AppleClang>:libCXX_Clang>
289                           $<$<LINK_LANG_AND_ID:C,Clang,AppleClang>:libC_Clang>
290                           $<$<LINK_LANG_AND_ID:CXX,Intel>:libCXX_Intel>
291                           $<$<LINK_LANG_AND_ID:C,Intel>:libC_Intel>)
292
293              This specifies the use of different link libraries based on both
294              the compiler id and link language. This example will have target
295              libCXX_Clang  as link dependency when Clang or AppleClang is the
296              CXX linker, and libCXX_Intel  when  Intel  is  the  CXX  linker.
297              Likewise  when  the  C  linker  is  Clang  or AppleClang, target
298              libC_Clang will be added as link dependency and libC_Intel  when
299              Intel is the C linker.
300
301              See  the  note  related  to  $<LINK_LANGUAGE:language>  for con‐
302              straints about the usage of this generator expression.
303
304       $<LINK_LANGUAGE:languages>
305              1 when the language used  for  link  step  matches  any  of  the
306              entries  in languages, otherwise 0.  This expression may be used
307              to specify link libraries, link options,  link  directories  and
308              link  dependencies  of  a  particular  language in a target. For
309              example:
310
311                 add_library(api_C ...)
312                 add_library(api_CXX ...)
313                 add_library(api INTERFACE)
314                 target_link_options(api INTERFACE $<$<LINK_LANGUAGE:C>:-opt_c>
315                                                     $<$<LINK_LANGUAGE:CXX>:-opt_cxx>)
316                 target_link_libraries(api INTERFACE $<$<LINK_LANGUAGE:C>:api_C>
317                                                     $<$<LINK_LANGUAGE:CXX>:api_CXX>)
318
319                 add_executable(myapp1 main.c)
320                 target_link_options(myapp1 PRIVATE api)
321
322                 add_executable(myapp2 main.cpp)
323                 target_link_options(myapp2 PRIVATE api)
324
325              This specifies to use the api target for linking targets  myapp1
326              and  myapp2. In practice, myapp1 will link with target api_C and
327              option -opt_c because it will use C as link language. And myapp2
328              will  link  with api_CXX and option -opt_cxx because CXX will be
329              the link language.
330
331              NOTE:
332                 To determine the link language of a target, it is required to
333                 collect,  transitively,  all the targets which will be linked
334                 to it. So, for link libraries properties, a double evaluation
335                 will  be  done.  During  the  first  evaluation,  $<LINK_LAN‐
336                 GUAGE:..> expressions will always return 0.   The  link  lan‐
337                 guage  computed  after this first pass will be used to do the
338                 second pass. To avoid inconsistency, it is required that  the
339                 second  pass  do  not  change the link language. Moreover, to
340                 avoid unexpected side-effects, it is required to specify com‐
341                 plete entities as part of the $<LINK_LANGUAGE:..> expression.
342                 For example:
343
344                     add_library(lib STATIC file.cxx)
345                     add_library(libother STATIC file.c)
346
347                     # bad usage
348                     add_executable(myapp1 main.c)
349                     target_link_libraries(myapp1 PRIVATE lib$<$<LINK_LANGUAGE:C>:other>)
350
351                     # correct usage
352                     add_executable(myapp2 main.c)
353                     target_link_libraries(myapp2 PRIVATE $<$<LINK_LANGUAGE:C>:libother>)
354
355                 In this example, for myapp1, the first pass  will,  unexpect‐
356                 edly,  determine  that  the  link language is CXX because the
357                 evaluation of the  generator  expression  will  be  an  empty
358                 string  so myapp1 will depends on target lib which is C++. On
359                 the contrary, for myapp2, the first evaluation will give C as
360                 link  language,  so the second pass will correctly add target
361                 libother as link dependency.
362
363       $<DEVICE_LINK:list>
364              Returns the list if it is the device link step,  an  empty  list
365              otherwise.   The  device link step is controlled by CUDA_SEPARA‐
366              BLE_COMPILATION and CUDA_RESOLVE_DEVICE_SYMBOLS  properties  and
367              policy CMP0105. This expression can only be used to specify link
368              options.
369
370       $<HOST_LINK:list>
371              Returns the list if it is the normal link step,  an  empty  list
372              otherwise.   This expression is mainly useful when a device link
373              step is also involved (see $<DEVICE_LINK:list> generator expres‐
374              sion). This expression can only be used to specify link options.
375

STRING-VALUED GENERATOR EXPRESSIONS

377       These expressions expand to some string.  For example,
378
379          include_directories(/usr/include/$<CXX_COMPILER_ID>/)
380
381       expands  to  /usr/include/GNU/ or /usr/include/Clang/ etc, depending on
382       the compiler identifier.
383
384       String-valued expressions may also be combined with other  expressions.
385       Here an example for a string-valued expression within a boolean expres‐
386       sions within a conditional expression:
387
388          $<$<VERSION_LESS:$<CXX_COMPILER_VERSION>,4.2.0>:OLD_COMPILER>
389
390       expands to OLD_COMPILER if the CMAKE_CXX_COMPILER_VERSION is less  than
391       4.2.0.
392
393       And here two nested string-valued expressions:
394
395          -I$<JOIN:$<TARGET_PROPERTY:INCLUDE_DIRECTORIES>, -I>
396
397       generates  a  string  of  the entries in the INCLUDE_DIRECTORIES target
398       property with each entry preceded by -I.
399
400       Expanding on the previous example, if one first wants to check  if  the
401       INCLUDE_DIRECTORIES  property  is  non-empty,  then  it is advisable to
402       introduce a helper variable to keep the code readable:
403
404          set(prop "$<TARGET_PROPERTY:INCLUDE_DIRECTORIES>") # helper variable
405          $<$<BOOL:${prop}>:-I$<JOIN:${prop}, -I>>
406
407       The following string-valued generator expressions are available:
408
409   Escaped Characters
410       String literals to escape the special meaning a character would  other‐
411       wise have:
412
413       $<ANGLE-R>
414              A  literal >. Used for example to compare strings that contain a
415              >.
416
417       $<COMMA>
418              A literal ,. Used for example to compare strings which contain a
419              ,.
420
421       $<SEMICOLON>
422              A  literal ;. Used to prevent list expansion on an argument with
423              ;.
424
425   Conditional Expressions
426       Conditional generator expressions depend on a  boolean  condition  that
427       must be 0 or 1.
428
429       $<condition:true_string>
430              Evaluates to true_string if condition is 1.  Otherwise evaluates
431              to the empty string.
432
433       $<IF:condition,true_string,false_string>
434              Evaluates to true_string if condition is 1.  Otherwise evaluates
435              to false_string.
436
437       Typically,  the  condition  is  a  boolean  generator  expression.  For
438       instance,
439
440          $<$<CONFIG:Debug>:DEBUG_MODE>
441
442       expands to DEBUG_MODE when the Debug configuration is used, and  other‐
443       wise expands to the empty string.
444
445   String Transformations
446       $<JOIN:list,string>
447              Joins the list with the content of string.
448
449       $<REMOVE_DUPLICATES:list>
450              Removes duplicated items in the given list.
451
452       $<FILTER:list,INCLUDE|EXCLUDE,regex>
453              Includes  or  removes  items  from  list  that match the regular
454              expression regex.
455
456       $<LOWER_CASE:string>
457              Content of string converted to lower case.
458
459       $<UPPER_CASE:string>
460              Content of string converted to upper case.
461
462       $<GENEX_EVAL:expr>
463              Content of expr evaluated as a generator expression in the  cur‐
464              rent  context. This enables consumption of generator expressions
465              whose evaluation results itself in generator expressions.
466
467       $<TARGET_GENEX_EVAL:tgt,expr>
468              Content of expr evaluated as a generator expression in the  con‐
469              text  of  tgt  target. This enables consumption of custom target
470              properties that themselves contain generator expressions.
471
472              Having the capability to evaluate generator expressions is  very
473              useful when you want to manage custom properties supporting gen‐
474              erator expressions.  For example:
475
476                 add_library(foo ...)
477
478                 set_property(TARGET foo PROPERTY
479                   CUSTOM_KEYS $<$<CONFIG:DEBUG>:FOO_EXTRA_THINGS>
480                 )
481
482                 add_custom_target(printFooKeys
483                   COMMAND ${CMAKE_COMMAND} -E echo $<TARGET_PROPERTY:foo,CUSTOM_KEYS>
484                 )
485
486              This naive implementation of the printFooKeys custom command  is
487              wrong  because  CUSTOM_KEYS target property is not evaluated and
488              the    content    is    passed    as    is    (i.e.     $<$<CON‐
489              FIG:DEBUG>:FOO_EXTRA_THINGS>).
490
491              To  have the expected result (i.e. FOO_EXTRA_THINGS if config is
492              Debug), it is required to evaluate the output of  $<TARGET_PROP‐
493              ERTY:foo,CUSTOM_KEYS>:
494
495                 add_custom_target(printFooKeys
496                   COMMAND ${CMAKE_COMMAND} -E
497                     echo $<TARGET_GENEX_EVAL:foo,$<TARGET_PROPERTY:foo,CUSTOM_KEYS>>
498                 )
499
500   Variable Queries
501       $<CONFIG>
502              Configuration name.
503
504       $<CONFIGURATION>
505              Configuration  name.  Deprecated  since  CMake  3.0.  Use CONFIG
506              instead.
507
508       $<PLATFORM_ID>
509              The current system’s CMake platform id.  See also the CMAKE_SYS‐
510              TEM_NAME variable.
511
512       $<C_COMPILER_ID>
513              The  CMake’s  compiler  id of the C compiler used.  See also the
514              CMAKE_<LANG>_COMPILER_ID variable.
515
516       $<CXX_COMPILER_ID>
517              The CMake’s compiler id of the CXX compiler used.  See also  the
518              CMAKE_<LANG>_COMPILER_ID variable.
519
520       $<CUDA_COMPILER_ID>
521              The CMake’s compiler id of the CUDA compiler used.  See also the
522              CMAKE_<LANG>_COMPILER_ID variable.
523
524       $<OBJC_COMPILER_ID>
525              The CMake’s compiler id of the OBJC compiler used.  See also the
526              CMAKE_<LANG>_COMPILER_ID variable.
527
528       $<OBJCXX_COMPILER_ID>
529              The  CMake’s  compiler id of the OBJCXX compiler used.  See also
530              the CMAKE_<LANG>_COMPILER_ID variable.
531
532       $<Fortran_COMPILER_ID>
533              The CMake’s compiler id of the Fortran compiler used.  See  also
534              the CMAKE_<LANG>_COMPILER_ID variable.
535
536       $<ISPC_COMPILER_ID>
537              The CMake’s compiler id of the ISPC compiler used.  See also the
538              CMAKE_<LANG>_COMPILER_ID variable.
539
540       $<C_COMPILER_VERSION>
541              The  version  of  the   C   compiler   used.    See   also   the
542              CMAKE_<LANG>_COMPILER_VERSION variable.
543
544       $<CXX_COMPILER_VERSION>
545              The   version   of   the   CXX  compiler  used.   See  also  the
546              CMAKE_<LANG>_COMPILER_VERSION variable.
547
548       $<CUDA_COMPILER_VERSION>
549              The  version  of  the  CUDA  compiler  used.    See   also   the
550              CMAKE_<LANG>_COMPILER_VERSION variable.
551
552       $<OBJC_COMPILER_VERSION>
553              The   version   of   the  OBJC  compiler  used.   See  also  the
554              CMAKE_<LANG>_COMPILER_VERSION variable.
555
556       $<OBJCXX_COMPILER_VERSION>
557              The  version  of  the  OBJCXX  compiler  used.   See  also   the
558              CMAKE_<LANG>_COMPILER_VERSION variable.
559
560       $<Fortran_COMPILER_VERSION>
561              The  version  of  the  Fortran  compiler  used.   See  also  the
562              CMAKE_<LANG>_COMPILER_VERSION variable.
563
564       $<ISPC_COMPILER_VERSION>
565              The  version  of  the  ISPC  compiler  used.    See   also   the
566              CMAKE_<LANG>_COMPILER_VERSION variable.
567
568       $<COMPILE_LANGUAGE>
569              The  compile  language  of  source files when evaluating compile
570              options.  See  the  related  boolean  expression  $<COMPILE_LAN‐
571              GUAGE:language>  for notes about the portability of this genera‐
572              tor expression.
573
574       $<LINK_LANGUAGE>
575              The link language of target when evaluating link  options.   See
576              the  related  boolean  expression  $<LINK_LANGUAGE:language> for
577              notes about the portability of this generator expression.
578
579              NOTE:
580                 This generator  expression  is  not  supported  by  the  link
581                 libraries  properties to avoid side-effects due to the double
582                 evaluation of these properties.
583
584   Target-Dependent Queries
585       These queries refer to a target tgt. This can be any runtime  artifact,
586       namely:
587
588       · an executable target created by add_executable()
589
590       · a shared library target (.so, .dll but not their .lib import library)
591         created by add_library()
592
593       · a static library target created by add_library()
594
595       In the following, “the tgt filename” means the name of the  tgt  binary
596       file.  This  has  to  be distinguished from “the target name”, which is
597       just the string tgt.
598
599       $<TARGET_NAME_IF_EXISTS:tgt>
600              The target name tgt if the target exists, an empty string other‐
601              wise.
602
603              Note  that  tgt  is not added as a dependency of the target this
604              expression is evaluated on.
605
606       $<TARGET_FILE:tgt>
607              Full path to the tgt binary file.
608
609       $<TARGET_FILE_BASE_NAME:tgt>
610              Base name of tgt, i.e.  $<TARGET_FILE_NAME:tgt>  without  prefix
611              and suffix.  For example, if the tgt filename is libbase.so, the
612              base name is base.
613
614              See  also  the  OUTPUT_NAME,  ARCHIVE_OUTPUT_NAME,  LIBRARY_OUT‐
615              PUT_NAME  and  RUNTIME_OUTPUT_NAME  target  properties and their
616              configuration  specific   variants   OUTPUT_NAME_<CONFIG>,   AR‐
617              CHIVE_OUTPUT_NAME_<CONFIG>,   LIBRARY_OUTPUT_NAME_<CONFIG>   and
618              RUNTIME_OUTPUT_NAME_<CONFIG>.
619
620              The <CONFIG>_POSTFIX and  DEBUG_POSTFIX  target  properties  can
621              also be considered.
622
623              Note  that  tgt  is not added as a dependency of the target this
624              expression is evaluated on.
625
626       $<TARGET_FILE_PREFIX:tgt>
627              Prefix of the tgt filename (such as lib).
628
629              See also the PREFIX target property.
630
631              Note that tgt is not added as a dependency of  the  target  this
632              expression is evaluated on.
633
634       $<TARGET_FILE_SUFFIX:tgt>
635              Suffix of the tgt filename (extension such as .so or .exe).
636
637              See also the SUFFIX target property.
638
639              Note  that  tgt  is not added as a dependency of the target this
640              expression is evaluated on.
641
642       $<TARGET_FILE_NAME:tgt>
643              The tgt filename.
644
645              Note that tgt is not added as a dependency of  the  target  this
646              expression is evaluated on (see policy CMP0112).
647
648       $<TARGET_FILE_DIR:tgt>
649              Directory of the tgt binary file.
650
651              Note  that  tgt  is not added as a dependency of the target this
652              expression is evaluated on (see policy CMP0112).
653
654       $<TARGET_LINKER_FILE:tgt>
655              File used when linking to the tgt target.  This will usually  be
656              the  library  that  tgt  represents  (.a,  .lib, .so), but for a
657              shared library on DLL platforms, it would  be  the  .lib  import
658              library associated with the DLL.
659
660       $<TARGET_LINKER_FILE_BASE_NAME:tgt>
661              Base  name  of  file  used  to link the target tgt, i.e.  $<TAR‐
662              GET_LINKER_FILE_NAME:tgt> without prefix and suffix.  For  exam‐
663              ple, if target file name is libbase.a, the base name is base.
664
665              See  also the OUTPUT_NAME, ARCHIVE_OUTPUT_NAME, and LIBRARY_OUT‐
666              PUT_NAME target  properties  and  their  configuration  specific
667              variants  OUTPUT_NAME_<CONFIG>, ARCHIVE_OUTPUT_NAME_<CONFIG> and
668              LIBRARY_OUTPUT_NAME_<CONFIG>.
669
670              The <CONFIG>_POSTFIX and  DEBUG_POSTFIX  target  properties  can
671              also be considered.
672
673              Note  that  tgt  is not added as a dependency of the target this
674              expression is evaluated on.
675
676       $<TARGET_LINKER_FILE_PREFIX:tgt>
677              Prefix of file used to link target tgt.
678
679              See also the PREFIX and IMPORT_PREFIX target properties.
680
681              Note that tgt is not added as a dependency of  the  target  this
682              expression is evaluated on.
683
684       $<TARGET_LINKER_FILE_SUFFIX:tgt>
685              Suffix of file used to link where tgt is the name of a target.
686
687              The  suffix  corresponds to the file extension (such as “.so” or
688              “.lib”).
689
690              See also the SUFFIX and IMPORT_SUFFIX target properties.
691
692              Note that tgt is not added as a dependency of  the  target  this
693              expression is evaluated on.
694
695       $<TARGET_LINKER_FILE_NAME:tgt>
696              Name of file used to link target tgt.
697
698              Note  that  tgt  is not added as a dependency of the target this
699              expression is evaluated on (see policy CMP0112).
700
701       $<TARGET_LINKER_FILE_DIR:tgt>
702              Directory of file used to link target tgt.
703
704              Note that tgt is not added as a dependency of  the  target  this
705              expression is evaluated on (see policy CMP0112).
706
707       $<TARGET_SONAME_FILE:tgt>
708              File with soname (.so.3) where tgt is the name of a target.
709
710       $<TARGET_SONAME_FILE_NAME:tgt>
711              Name of file with soname (.so.3).
712
713              Note  that  tgt  is not added as a dependency of the target this
714              expression is evaluated on (see policy CMP0112).
715
716       $<TARGET_SONAME_FILE_DIR:tgt>
717              Directory of with soname (.so.3).
718
719              Note that tgt is not added as a dependency of  the  target  this
720              expression is evaluated on (see policy CMP0112).
721
722       $<TARGET_PDB_FILE:tgt>
723              Full  path  to the linker generated program database file (.pdb)
724              where tgt is the name of a target.
725
726              See also the PDB_NAME and PDB_OUTPUT_DIRECTORY target properties
727              and  their configuration specific variants PDB_NAME_<CONFIG> and
728              PDB_OUTPUT_DIRECTORY_<CONFIG>.
729
730       $<TARGET_PDB_FILE_BASE_NAME:tgt>
731              Base name of the linker generated program database  file  (.pdb)
732              where tgt is the name of a target.
733
734              The  base  name  corresponds  to  the  target PDB file name (see
735              $<TARGET_PDB_FILE_NAME:tgt>)  without  prefix  and  suffix.  For
736              example, if target file name is base.pdb, the base name is base.
737
738              See also the PDB_NAME target property and its configuration spe‐
739              cific variant PDB_NAME_<CONFIG>.
740
741              The <CONFIG>_POSTFIX and  DEBUG_POSTFIX  target  properties  can
742              also be considered.
743
744              Note  that  tgt  is not added as a dependency of the target this
745              expression is evaluated on.
746
747       $<TARGET_PDB_FILE_NAME:tgt>
748              Name of the linker generated program database file (.pdb).
749
750              Note that tgt is not added as a dependency of  the  target  this
751              expression is evaluated on (see policy CMP0112).
752
753       $<TARGET_PDB_FILE_DIR:tgt>
754              Directory of the linker generated program database file (.pdb).
755
756              Note  that  tgt  is not added as a dependency of the target this
757              expression is evaluated on (see policy CMP0112).
758
759       $<TARGET_BUNDLE_DIR:tgt>
760              Full path to the  bundle  directory  (my.app,  my.framework,  or
761              my.bundle) where tgt is the name of a target.
762
763              Note  that  tgt  is not added as a dependency of the target this
764              expression is evaluated on (see policy CMP0112).
765
766       $<TARGET_BUNDLE_CONTENT_DIR:tgt>
767              Full path to the bundle content directory where tgt is the  name
768              of  a  target.  For  the  macOS SDK it leads to my.app/Contents,
769              my.framework, or my.bundle/Contents. For all  other  SDKs  (e.g.
770              iOS)  it  leads to my.app, my.framework, or my.bundle due to the
771              flat bundle structure.
772
773              Note that tgt is not added as a dependency of  the  target  this
774              expression is evaluated on (see policy CMP0112).
775
776       $<TARGET_PROPERTY:tgt,prop>
777              Value of the property prop on the target tgt.
778
779              Note  that  tgt  is not added as a dependency of the target this
780              expression is evaluated on.
781
782       $<TARGET_PROPERTY:prop>
783              Value of the property prop on the target for which  the  expres‐
784              sion  is being evaluated. Note that for generator expressions in
785              Target Usage Requirements this is the  consuming  target  rather
786              than the target specifying the requirement.
787
788       $<INSTALL_PREFIX>
789              Content  of  the  install prefix when the target is exported via
790              install(EXPORT), or  when  evaluated  in  INSTALL_NAME_DIR,  and
791              empty otherwise.
792
793   Output-Related Expressions
794       $<TARGET_NAME:...>
795              Marks  ...  as  being the name of a target.  This is required if
796              exporting targets to multiple dependent export  sets.   The  ...
797              must be a literal name of a target- it may not contain generator
798              expressions.
799
800       $<LINK_ONLY:...>
801              Content of ... except when evaluated in a link  interface  while
802              propagating  Target  Usage Requirements, in which case it is the
803              empty  string.    Intended   for   use   only   in   an   INTER‐
804              FACE_LINK_LIBRARIES   target  property,  perhaps  via  the  tar‐
805              get_link_libraries() command, to specify private link  dependen‐
806              cies without other usage requirements.
807
808       $<INSTALL_INTERFACE:...>
809              Content   of   ...   when   the   property   is  exported  using
810              install(EXPORT), and empty otherwise.
811
812       $<BUILD_INTERFACE:...>
813              Content of ... when the property is exported using export(),  or
814              when  the target is used by another target in the same buildsys‐
815              tem. Expands to the empty string otherwise.
816
817       $<MAKE_C_IDENTIFIER:...>
818              Content of ... converted to a C identifier.  The conversion fol‐
819              lows the same behavior as string(MAKE_C_IDENTIFIER).
820
821       $<TARGET_OBJECTS:objLib>
822              List of objects resulting from build of objLib.
823
824       $<SHELL_PATH:...>
825              Content  of  ...  converted  to  shell  path style. For example,
826              slashes are converted to backslashes in Windows shells and drive
827              letters  are  converted  to  posix paths in MSYS shells. The ...
828              must be an absolute path.  The ... may be a  semicolon-separated
829              list of paths, in which case each path is converted individually
830              and a result list is generated using the shell path separator (:
831              on  POSIX  and  ;  on Windows).  Be sure to enclose the argument
832              containing this genex in double quotes in CMake source  code  so
833              that ; does not split arguments.
834

DEBUGGING

836       Since  generator  expressions  are  evaluated  during generation of the
837       buildsystem, and not during processing of CMakeLists.txt files,  it  is
838       not possible to inspect their result with the message() command.
839
840       One possible way to generate debug messages is to add a custom target,
841
842          add_custom_target(genexdebug COMMAND ${CMAKE_COMMAND} -E echo "$<...>")
843
844       The  shell  command  make genexdebug (invoked after execution of cmake)
845       would then print the result of $<...>.
846
847       Another way is to write debug messages to a file:
848
849          file(GENERATE OUTPUT filename CONTENT "$<...>")
850
852       2000-2021 Kitware, Inc. and Contributors
853
854
855
856
8573.19.7                           Mar 15, 2021   CMAKE-GENERATOR-EXPRESSIONS(7)
Impressum