[CMake] Best practice for static libraries and include files

Matthew Woehlke matthew.woehlke at kitware.com
Fri Mar 8 15:43:31 EST 2013


On 2013-03-08 15:19, Alexander Neundorf wrote:
> There is no need to overengineer it.
> Just do
> include_directories(${CMAKE_SOURCE_DIR}/lib1/src)
> in CMakeLists.txt (3). No need to put it in the cache or something.

This can break if your current project tree ever lands in a larger tree. 
In general I prefer to avoid ${CMAKE_SOURCE_DIR} in favor of 
${<project>_SOURCE_DIR} instead.

Even better, if each of your libraries declares a project, you can use 
${lib1_SOURCE_DIR}/src, and you won't have to change it if you later 
move lib1 to a different place in the source tree.

(I've seen legitimate uses of defining variables for libraries' 
interface properties, e.g. include directories, but all of this is about 
to become properly supported :-), and anyway isn't something I would 
recommend trying to emulate in a young project.)

-- 
Matthew



More information about the CMake mailing list