I have a project with the following directory structure
server
| daemon
| | src
| service
| | src
| commons
The daemon
is the linux version and service
contains the windows version. Originally, I made 2 separate cmake projects in those 2 folders and it worked. But I had to copy paste code between both projects. Now I want to move sources with common code into the commons
folder. So that each project includes the sources from the common folder instead of copy pasting code.
Within Code::Blocks, it works, I just add the commons files to the project and it works.
For CMake, it works only on header files using a command like:
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../commons)
in the scr
directory. Now the problem is when I want to include source files in the same directory. I cannot manage it to make it work, it does not find the source files. Adding a new sub directory does not work since it’s not a sub directory.
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../commons commons)
I don’t seem to be able to build the commons folder without using add_executable
or add_library
. Making a library could work, but I though generating a library would be an overkill since it will not be reused elsewhere than this project.
Then I though that maybe I could create the project in the root directory and add 2 projects for the whole tree structure. But adding 2 projects in the same file seems impossible. I also have the constraint that I don’t want to build every thing all the time. When I am in linux, I want to build daemon
and commons
while when I am in windows, I want to build service
and commons
.
The internet did not yield any good solution so far. So I am trying this forum:
Is it possible to add “out-of-tree” source files?
Else is it possible to have multiple projects in the same cmake file and only build a portion of the projects?
Else is there other solutions than building a static library?