I create software for each state. There is some state specific code, and some common code that runs on all the states. I have created the following directory structure:
common
foo
CMakeLists.txt
bar
CMakeLists.txt
State
AL
bin
src
build
CMakeLists.txt
DMV
CMakeLists.txt
ABC
CMakeLists.txt
AK
bin
src
build
CMakeLists.txt
DMV
CMakeLists.txt
ABC
CMakeLists.txt
CMakeList.txt in EACH state
set (COMMON "/home/me/common")
add_subdirectory(${COMMON}/foo {STATE_BIN_DIR})
add_subdirectory(${COMMON}/bar {STATE_BIN_DIR})
add_subdirectory(${DMV)
CMakeLists.txt in DMV directories (and ABC)
install(TARGETS dmv DESTINATION ${STATE_BIN_DIR})
CMakeLists.txt in Common foo directories (and bar)
install(TARGETS foo DESTINATION ${STATE_BIN_DIR})
cmake ERROR:
The binary directory
/home/me/State/AL/bin is already used to build a source directory. It cannot be used to build source directory
/home/me/common/bar
Specify a unique binary directory name.
It works fine if I am only building foo. When I try to build bar outside the directory structure, it fails. What I don't understand is ALL my binaries (in state and common) are going to the State's bin directory.
reading this: CMAKE add sub-directory which is not sub-directory on real directory
It says "CMake cannot have two different source directories mapping into the same build directory."
But all the differnt source ( DMV, ABC) all go to bin. It works here.
CMake's site doesn't specify https://cmake.org/cmake/help/v3.0/command/add_subdirectory.html
Is there any work around to do what I want?
I know I can create foo and bar drirectory under the States directory and just put a CMakeLisist.txt that points to the code in common.
That works. But I would like to keep the recipe with the code.
I think I can also create bin/foo and bin/bar to put those binaries in too. But some are shared libs that I would like in one place.
Any thoughts?
Thanks