[CMake] How to properly add include directories?
Fred Baksik
fdk17 at ftml.net
Mon Oct 21 11:09:48 EDT 2019
On Mon, Oct 21, 2019, at 10:16 AM, David Aldrich wrote:
> Hi again,
>
> My CMakeLists.txt file for my shared library contains:
>
> add_library(MyLib SHARED my_source.cpp etc.)
> target_include_directories( MyLib PRIVATE ../MyHeaders)
>
> The library builds ok, but there is no dependency on directory ../MyHeaders - touching a header file does not result in a re-compile of dependent source files.
>
> There's a discussion here:
>
> https://stackoverflow.com/questions/13703647/how-to-properly-add-include-directories-with-cmake
> Opinion seems divided over whether or not it is necessary to add the header files to the list of source files for the target, e.g.:
>
> set(SOURCES file.cpp file2.cpp ${YOUR_DIRECTORY}/file1.h ${YOUR_DIRECTORY}/file2.h)
> add_library(test ${SOURCES})
>
> Please will you tell me what is the best practice?
> --
>
What generator are you using?
That thread seems to contain a lot of misunderstandings about the issue.
If you are using the Makefile generator then refer to https://stackoverflow.com/questions/7461000/handling-header-files-dependencies-with-cmake. After building the project for the first time inspect the `depend.make files that are generated to verify if the headers are being picked up correctly as a dependency.`
`--`
`F`
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20191021/ba43a112/attachment.html>
More information about the CMake
mailing list