I am very new to CMake. In fact, I am trying it through Kdevelop4 widh C++.
I have the habit of creating subdirs for every namespace I create, even if all the sources must be compiled and linked into a single executable. Well, when i create a directory under kdevelop, it updates CMakeLists.txt with a add_subdirectory command and creates a new CMakeLists.txt under it, but that alone does not add the sources under it to the compilation list.
I have the root CMakeLists.txt as follows:
project(gear2d) add_executable(gear2d object.cc main.cc) add_subdirectory(component)
Under component/ I have the sources I want to be compiled and linked to produce the gear2d executables. How can I accomplish that?
CMake FAQ have this entry but if thats the answer I’d rather stay with plain Makefiles.
Is there a way of doing this?
Adding a subdirectory does not do much more than specify to CMake that it should enter the directory and look for another CMakeLists.txt there. You still need to create a library with the source files with add_library and link it to your executable with target_link_libraries. Something like the following:
In the subdir CMakeLists.txt
Top-dir CMakeLists.txt