cmakecmake-language

Why my INCLUDE_DIRECTORIES and INTERFACE_INCLUDE_DIRECTORIES properties are empty in Cmake?


In this code, I add with target_include_directories the string "${PROJECT_BINARY_DIR}" in the properties INCLUDE_DIRECTORIES and INTERFACE_INCLUDE_DIRECTORIES. However, when I run Cmake I see with the message commands that these two properties are empty.

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}")

Anyone knows why ?

thx!


Solution

  • You are getting the DIRECTORY properties. You want the TARGET properties of your executable target.

    target_include_directories is TARGET based.

    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}")