访问构建树中其他目标的属性

时间:2018-06-21 10:27:52

标签: cmake

我在同一构建树中都有目标Hello,它取决于提供程序。配置Hello时,我需要访问提供者的INCLUDE_DIRECTORIES属性。我知道CMake会在内部处理此问题,但是我需要所有INCLUDE_DIRECTORIES(包括依赖项的所有内容)用于外部脚本。

我的构建树:

-src
  -Providers
    -src
      -HelloProvider.cpp
      -WorldProvider.cpp
    -include/Providers
       -HelloProvider.h
       -WorldProvider.h
    -CMakeLists.txt
  -Hello
    -hello.cpp
    -CMakeLists.txt
  -CMakeLists.txt

Providers / CMakeLists.txt:

project(Providers VERSION 1.0 LANGUAGES CXX)

add_library(Providers src/HelloProvider.cpp src/WorldProvider.cpp)

target_include_directories(Providers
    PUBLIC
        include/Providers
)

Hello / CMakeLists.txt:

project(Hello VERSION 1.0 LANGUAGES CXX )

add_executable(Hello hello.cpp)

target_link_libraries(Hello
    PRIVATE
        Providers
)

在Hello目标中,我想做类似的事情

get_target_property(PROVIDERS_INCLUDES Providers INTERFACE_INCLUDE_DIRECTORIES)
message("calling doSomethingVeryImportant.py with ${PROVIDERS_INCLUDES}")
execute_process(COMMAND py doSomethingVeryImportant.py ${PROVIDERS_INCLUDES})

并期望输出

calling doSomethingVeryImportant.py with include/Providers

但我明白了

get_target_property() called with non-existent target "Providers"

我认为我需要将Providers导入Hello。我该如何做,最好以可扩展为任意数量的依赖关系的方式进行?

0 个答案:

没有答案