cmake - How can I build a C++ project with multiple interdependent subdirectories? -


i have c++ project i've used directories more of organizational element -- way 1 might use packages in java or directories in php. directories not intended self-sufficient elements, rather way of organizing whole of project , keeping me being overwhelmed sources. how can construct cmakelists.txt files deal this? making directories libraries doesn't seem fit here, since interdependent , not intended used way.

as related issue, of examples i've seen of multiple subdirectories in cmake (and there aren't many of those) have ignored or glossed on issue of setting include_directories, i've been having trouble with. short of combing source files determine file depends on , in directory, there anyway set directories under /src/ potential include directories , let cmake work out ones dependent?

here's example structure:

--src   --top1     --mid1       --bot1         --src1.cpp         --hdr1.h       --bot2         --src2.cpp         --hdr2.h     --mid2       --bot3         --src3.cpp         --src4.cpp         --hdr3.h   --top2     --mid3       --src5.cpp       --hdr4.h 

so on , forth. how can structure cmakelists.txt files handle sort of structure?

since directory structure in project there keep files organized, 1 approach have cmakelists.txt automatically finds sources files in src directory , adds directories include directories have header file in them. following cmake file may serve starting point:

project (foo)  file(glob_recurse foo_sources "src/*.cpp") file(glob_recurse foo_headers "src/*.h")  set (foo_include_dirs "") foreach (_headerfile ${foo_headers})     get_filename_component(_dir ${_headerfile} path)     list (append foo_include_dirs ${_dir}) endforeach() list(remove_duplicates foo_include_dirs)  include_directories(${foo_include_dirs}) add_executable (fooexe ${foo_sources}) 

the 2 file(glob_recurse ... commands determine set of source , header files. foreach loop computes set of include directories list of header files.

one drawback computing set of source files cmake not automatically detect when new files added source tree. manually have re-create build files then.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -