c++ - Cmake generator expressions -


i'm trying long time understand benefit of generator expressions such $<xxx:yy> in cmake, when , how use them. can explain examples. many thank in advance

cmake first parse cmakelists.txt files in project - named "configuration phase" - , generates build environment - named "generation phase".

so generator expressions generator know:

  • the name , path of target outputs (mainly when cross-compiling , in multi-configuration environments)
  • or more target property generator evaluates mingle compiler/linker calls

here examples use generator expressions in project:

  1. copying files next executable (in multi-configuration environments can't use variables cmake_current_binary_dir)

    add_custom_command(     target library1      post_build     command ${cmake_command} -e copy         "$<target_file:library1>"         "$<target_file_dir:mainproject>/$<target_file_name:library1>" ) 

    cmake post-build-event: copy compiled libraries

    add_custom_command(     target mybinary      post_build         command ${cmake_command} -e copy                        "${cmake_current_source_dir}/mytest.txt"                       "$<target_file_dir:mybinary>/mytest.txt" ) 

    how add external test files cmake project

  2. differentiate e.g. debug or release configurations

    add_compile_options("$<$<config:debug>:/mdd>") 

    for cmake, can modify release/debug compiler flags `add_compiler_flags()` command?

    modern way set compiler flags in cross-platform cmake project

  3. with target_property generator expression lot of things e.g.

    file(generate      output "includes.txt"      content "$<target_property:motor,include_directories>\n" ) 

    cmake doesn't pick interface_include_directories of linked library


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -