生成器表达式的值在构建(build)阶段才能得到。生成器表达式可用于根据某些条件设置某些变量和编译选项。 Generator expressions may be used to enable conditional linking, conditional definitions used when compiling, conditional include directories and more. The conditions may be based on the build configuration, target properties, platform information or any other queryable information.
CMake Help 系列基于CMake Tutorial 本文基于Step 2: Adding a Library Rather than placing all of the source files in one directory, we can organize our project with one or more subdirectories. In this case, we will create a subdirectory specifically for our library. Here, we can add a new CMakeLists.txt file and one or more source files. In the top level CMakeLists.txt file, we will use the add_subdirectory() command to add the subdirectory to the build. Once the library is created, it is connected to our executable target with target_include_directories() and target_link_libraries().