Aut*_*hre 3 cmake cmake-language
target_include_directories
在此代码中,我在属性 INCLUDE_DIRECTORIES 和 INTERFACE_INCLUDE_DIRECTORIES 中添加字符串“${PROJECT_BINARY_DIR}”。但是,当我运行 Cmake 时,我发现命令中message
这两个属性为空。
cmake_minimum_required(VERSION 3.10)
# set the project name and version
project(Tutorial VERSION 1.0)
# specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# configure a header file to pass some of the CMake settings
# to the source code
configure_file(TutorialConfig.h.in TutorialConfig.h)
# add the executable
add_executable(Tutorial tutorial.cxx)
# add the binary tree to the search path for include files
# so that we will find TutorialConfig.h
target_include_directories(Tutorial
PUBLIC "${PROJECT_BINARY_DIR}"
)
get_property(inc_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
message("INCLUDE_DIRECTORIES = ${inc_dirs}")
get_property(interface_inc_dirs DIRECTORY PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
message("INTERFACE_INCLUDE_DIRECTORIES = ${interface_inc_dirs}")
Run Code Online (Sandbox Code Playgroud)
有人知道为什么吗?
谢谢!
您正在获取DIRECTORY
属性。您需要TARGET
可执行目标的属性。
target_include_directories
基于TARGET
。
get_target_property(inc_dirs Tutorial INCLUDE_DIRECTORIES)
message("INCLUDE_DIRECTORIES = ${inc_dirs}")
get_target_property(interface_inc_dirs Tutorial INTERFACE_INCLUDE_DIRECTORIES)
message("INTERFACE_INCLUDE_DIRECTORIES = ${interface_inc_dirs}")
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
318 次 |
最近记录: |