0

I am having the problem printing the variable like INTERFACE_INCLUDE_DIRECTORIES, I would show the simple CMakeLists.txt that I write:

cmake_minimum_required(VERSION 3.5)
project(Library)

add_library(hello src/hello.cpp)
target_include_directories(hello PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)

message(STATUS "The interface_include_directories : ${INTERFACE_INCLUDE_DIRECTORIES}")

As shown above, ${CMAKE_CURRENT_SOURCE_DIR}/include should be in the INTERFACE_INCLUDE_DIRECTORIES after target_include_directories, However, it prints an empty string instead.

I would like to know if there is anyway to print the include path that is related to specific library ,hello for example in this case.

Pro_gram_mer
  • 749
  • 3
  • 7
  • 20

1 Answers1

1

${CMAKE_CURRENT_SOURCE_DIR}/include should be in the INTERFACE_INCLUDE_DIRECTORIES after target_include_directories

It should be in a INTERFACE_INCLUDE_DIRECTORIES target property, not in a variable.

if there is anyway to print the include path that is related to specific library ,hello for example in this case.

get_target_property(var hello INTERFACE_INCLUDE_DIRECTORIES)
message(STATUS "${var}")
KamilCuk
  • 120,984
  • 8
  • 59
  • 111
  • Thanks, what if I want to print all the include path in cmake( including c++ standard ones) ? – Pro_gram_mer Jan 26 '22 at 08:42
  • eerrmm, what for? You have to find all variables with include paths and print them. You can compile in verbose to see what is passed to compiler. `c++ standard ones` there are no "standard ones", C++ standard does not mention any include paths. There are system specific, in case consult your operating system documentation (FHS and POSIX on linux), there are compiler specific include paths, in case consult compiler documentation (compile code with `gcc -v` on GCC to see what it includes). – KamilCuk Jan 26 '22 at 09:56
  • Because after using target_link_directories for marking library named hello with PUBLIC mode, in another folder, there is main.cpp uses this hello library ,when include the header file for hello library, I get to write #include instead of #include “hello.h” which I don’t understand. As far as I know the brackets one means it would search the path that is predefined by system or compiler, So I would like to know ,does target_link_directories makes some difference? – Pro_gram_mer Jan 26 '22 at 16:28
  • 1
    `which I don’t understand` I can only recommend a tutor or to read [some books](https://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list). `does target_link_directories makes some difference?` No, `target_link_directories` does not affect compiler include search paths, it adds a path to library search paths. `target_include_directories` adds a path to compiler include search paths, which affects both `#include ` and `#include "hello.h"`. – KamilCuk Jan 26 '22 at 16:38