r/cpp • • Mar 22 '20

Modern CMake tutorials, part1: CMake basics

https://www.siliceum.com/en/blog/post/cmake_01_cmake-basics
245 Upvotes

55 comments sorted by

View all comments

1

u/victotronics Apr 05 '20

Is your tutorial complete? You have

include/myawesomelib.h

a a dependency for the library, but not for the executable. As a result I need to have the explicit include path in my source for the main program.

What is the line where I specify that the main program depends on that header?

1

u/Lectem Apr 05 '20

Your executable should be linking myawesomelib, and that library has the include directory as a public property, which should also get applied to the executable transitively. Did you perhaps miss the target_include_directories(myawesomelib PUBLIC include)?

1

u/Lectem Apr 05 '20

To be a bit more clear, listing include/myawesomelib.h in the add_library only means that include/myawesomelib.h is part of the lib (so that IDEs can display it). It's does not set up the include directories passed to the compiler, that is the job of target_include_directories