vixu
vixu

Reputation: 119

CMake header file that includes header files from other directory

Given this tree:

project
 + lib
    + include
        + include_both.h
    + source
        + file1.cpp
        + file1.h
        + file2.cpp
        + file2.h
 + main_dir
    + main.cpp

After linking lib to main_dir with CMake, I would like header files file1.h and file2.h to not to be visible from main.cpp. I want the library to be include-able only by the include_both.h header file. How can this be done and should I even do it?

Upvotes: 0

Views: 436

Answers (1)

Kevin
Kevin

Reputation: 18243

You might try making the include directory a PUBLIC one, so it is visible to consumers of the library, but keep the source directory private:

add_library(MyLib SHARED 
    source/file1.cpp
    source/file2.cpp
)

target_include_directories(MyLib 
    PUBLIC  include
    PRIVATE source
)

Upvotes: 1

Related Questions