How to build a multi-executable project

Hi everybody

My project is made of many executable binary files (namely “modules”).
My current directory structure is as follows :

scav is the name of the toplevel directory
It contains the directories src, bin, build and a CMakeLists.txt

 scav---|bin (the directory which is expected to contain the binary files of my three modules
        |build (the directory from wich I launch cmake..
        |CMakeLists.txt
        |src---|modmngr ==> content : a library (.cpp, ..h) used by the other modules)
               |modcam  ==> content a module  .cpp and .h
               |modobs  ==> content a module  .cpp and .h)
               |modcalc ==> content a module  .cpp and .h)      

In a fist step I have done separate CMakelists for each module.
For example to build modcam I have written the following CMakeLists.txt which is located in the modcam directory and it works perfectly. It generates an executable located also in the modcam directory/

cmake_minimum_required(VERSION 3.7.2)

# specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# set the project name
project(modcam)

#pass the version number to the source  code
#configure_file(tutorialConfig.h.in tutorialConfig.h)

#library
add_subdirectory(modmngr)

#add_executable(tutorial $(SRCS) $(HEADERS))
add_executable(modcam modcam.cpp)

#pass option
set(CMAKE_CXX_FLAGS "-pthread")

#libnkl to library
target_link_libraries(modcam PUBLIC modmngr)

# add the binary tree to the search path for include files
# so that we will find TutorialConfig.h
target_include_directories(modcam PUBLIC
                          "${PROJECT_BINARY_DIR}"
                          "${PROJECT_SOURCE_DIR}/modmngr"
)

But now I would like to build my three modules using a new CMakeLists.txt located on the toplevel directory which will build the three executable and records it in the bin directory.

I try many things without success (it seems that it conflicts with the CMakeLists.txt which are located in each modules directory). It is important for me to solve this issue because in the future I will have many modules (about twenty) and I don’t want to build them one after one … So with this toplevel MakeLists.txt I expect to generate a Makefile which will build (or rebuild in case of change) all my modules at the same time.

Thank you for your help
Regards

See the RUNTIME_OUTPUT_DIRECTORY target property.

I finally found a solution that I show below (hoping it will help people with the same issue to solve.)
Below is the CMakeLists.txt located in the scav directory (the toplevel directory):
cmake_minimum_required(VERSION 3.7.2)

set(CMAKE_BUILD_TYPE Release)

project(scav)

add_subdirectory(src/modmngr)
add_subdirectory(src/modcalc)
add_subdirectory(src/modcam)
add_subdirectory(src/modobs)

And below is the CMakeLists.txt located into each module directory (project name is different from one module to another, below is the example for module modobs)

cmake_minimum_required(VERSION 3.7.2)

# specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# set the project name
project(modobs)

# add the binary tree to the search path for include files
# so that we will find modmngr.h
 target_include_directories(modmngr PUBLIC
 #   "${PROJECT_BINARY_DIR}"
    "${PROJECT_SOURCE_DIR}/../modmngr"
 )

#pass the version number to the source  code
#configure_file(tutorialConfig.h.in tutorialConfig.h)

#add_executable(tutorial $(SRCS) $(HEADERS))
add_executable(modobs modobs.cpp)

#pass option
set(CMAKE_CXX_FLAGS "-pthread")

#libnkl to library
target_link_libraries(modobs PUBLIC modmngr)

#install in /usr/local/bin (on debian)
install (
   TARGETS modobs DESTINATION bin
)

Finally, is the CMakeLists.txt located in the directory which contains my library (modmngr)

add_library(modmngr modmngr.cpp)

file(
   GLOB
   headers
   *.h
)