I have a problem with my CMake build system. There are CMakeLists.txt
files defining runtimes or libraries or using ExternalProjects_Add()
to download and build external code. Because of dependencies, those projects have to find each other. Now I want to have a CMakeLists.txt
at the top level that builds all those at once. In order to find a project, is must be installed. But finding projects is already done at configuration time in CMake.
repository
├─project
│ ├─game (Depends on engine, uses EngineConfig.cmake once installed)
│ │ ├─CMakeLists.txt
│ │ ├─include
│ │ ├─src
│ │ └─textures
│ ├─engine (Depends on boost, uses built-in FindBoost.cmake)
│ │ ├─CMakeLists.txt
│ │ ├─include
│ │ └─src
│ ├─boost (Not the source code, just an ExternalProject_Add call)
│ : └─CMakeLists.txt
│
├─build
│ ├─game
│ ├─engine
│ ├─boost (Source will be downloaded and built here)
│ : ├─download
│ ├─source
│ :
│
├─install
│ ├─game
│ │ ├─bin
│ │ └─textures
│ ├─engine
│ │ ├─include
│ │ │ └─engine
│ │ │ ├─EngineConfig.cmake (Needed to find the library)
│ │ │ :
│ │ │
│ │ └─lib
│ ├─boost (Layout is up to the external library)
│ : └─ ...
│
└─CMakeLists.txt (Calls add_subdirectory for all inside the project folder)
Run a CMake process for every project: Using execute_process(${CMAKE_COMMAND} ...)
, I can configure and build each project after another at configure time. However, this means I always have to run CMake after editing the code and cannot compile from within the IDE I generated project files for.
Linking to CMake targets: Running a CMake process for all external libraries is okay since I don't work on them. My own libraries could be used by calling target_link_libraries()
with their target names. However, linking isn't enough. My libraries include directories of external libraries. Those must be made available to the using project, as well.
How can I use libraries within my CMake project that need to be installed first?