build - Recursive CMake search for header and source files -


i new cmake , ask if can in following problem.

i have c++ source , header files in respective folders , now, want make cmake text file recursively searches them.

currently, doing in way:

cmake_minimum_required(version 2.8) project(cardetectordaisy)  file(glob_recurse srcs *.cpp) file(glob_recurse hdrs *.h)  add_executable(stereo_framework  ${srcs} ${hdrs}) target_link_libraries(stereo_framework)  

this creates cardetectordaisy.sln solution file , when try build it, shows error header files not found (no such file or directory).

it grateful if can please me. thanks.

you're missing 1 or more include_directories calls. adding headers list of files in add_executable call doesn't add compiler's search path - it's convenience feature whereby added project's folder structure in ides.

so, in root, have /my_lib/foo.h, , want include in source file as

#include "my_lib/foo.h" 

then in cmakelists.txt, need do:

include_directories(${cmake_source_dir}) 

if, instead want do

#include "foo.h" 

then in cmakelists.txt, do

include_directories(${cmake_source_dir}/my_lib) 


should mention file(glob...) not recommended way gather list of sources - should add each file explicitly in cmakelists.txt. doing this, if add or remove source file later, cmakelists.txt modified, , cmake automatically reruns next time try , build. docs file:

we not recommend using glob collect list of source files source tree. if no cmakelists.txt file changes when source added or removed generated build system cannot know when ask cmake regenerate.


Comments