CMake generator expression is not being evaluated

前端 未结 2 1989
情话喂你
情话喂你 2021-02-20 12:40

Due to the following warning:

CMake Error at test/CMakeLists.txt:29 (get_target_property):
  The LOCATION property may not be read from target \"my_exe\".  Use t         


        
2条回答
  •  后悔当初
    2021-02-20 13:05

    While generator expression is stored at configuration stage (when corresponded CMake command is executed), evaluation of generator expressions is performed at build stage.

    This is why message() command prints generator expression in non-dereferenced form: value denoted by the generator expression is not known at this stage.

    Moreover, CMake never dereferences generator expressions by itself. Instead, it generates appropriate string in the build file, which is then interpreted by build utility (make, Visual Studio, etc.).

    Note, that not every CMake command accepts generator expressions. Each possible usage of generator expressions is explicitely described in documentation for specific command. Moreover, different CMake command flows or different options have different policy about using of generator expressions.

    For example, command flow

    add_test(NAME  COMMAND )
    

    accepts generator expressions for COMMAND option,

    but command flow

    add_test( )
    

    doesn't!

    Another example of policies difference:

    install(DIRECTORY  DESTINATION )
    

    In this command flow generator expressions are allowed for DESTINATION, but not for DIRECTORY option.

    Again, read documentation carefully.

提交回复
热议问题