3

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!

Tesla123
  • 319
  • 1
  • 7

1 Answers1

4

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}")
jpr42
  • 718
  • 3
  • 14
  • 1
    You're right thx ! I made a mistake because INCLUDE_DIRECTORIES is used in 3 different scopes "Source files", DIRECTORY and TARGET : https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html Not easy for a beginner to know which scope is correct. – Tesla123 Sep 13 '22 at 09:23