<!DOCTYPE html><html><head><title></title><style type="text/css">p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div><br></div><div><br></div><div>On Mon, Oct 21, 2019, at 10:16 AM, David Aldrich wrote:<br></div><blockquote type="cite" id="qt"><div dir="ltr"><div>Hi again,<br></div><div><br></div><div>My CMakeLists.txt file for my shared library contains:<br></div><div><br></div><div>add_library(MyLib SHARED my_source.cpp etc.)<br></div><div>target_include_directories( MyLib PRIVATE ../MyHeaders)<br></div><div><br></div><div>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.<br></div><div><br></div><div>There's a discussion here:<br></div><div><br></div><div><a href="https://stackoverflow.com/questions/13703647/how-to-properly-add-include-directories-with-cmake">https://stackoverflow.com/questions/13703647/how-to-properly-add-include-directories-with-cmake</a>  <br></div><div>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.:<br></div><div><br></div><div>set(SOURCES file.cpp file2.cpp ${YOUR_DIRECTORY}/file1.h ${YOUR_DIRECTORY}/file2.h)<br></div><div>add_library(test ${SOURCES})<br></div><div><br></div><div>Please will you tell me what is the best practice?<br></div></div><div>-- <br></div><div><br></div></blockquote><div><br></div><div>What generator are you using?<br></div><div>That thread seems to contain a lot of misunderstandings about the issue.<br></div><div><br></div><div>If you are using the Makefile generator then refer to <a href="https://stackoverflow.com/questions/7461000/handling-header-files-dependencies-with-cmake">https://stackoverflow.com/questions/7461000/handling-header-files-dependencies-with-cmake</a>. After building the project for the first time inspect the <code>depend.make files that are generated to verify if the headers are being picked up correctly as a dependency.</code><br></div><div><br></div><div><code>--</code><br></div><div><code>F</code><br></div></body></html>