There are several other similar questions 1 2 3 4 5, but none answer this question / usecase. (I also heard about ExternalProject_Add, but what I heard suggested it wouldn't solve this find_package problem).
I have several 3rd party CMake/C++ libraries, which I'm to gather into one repo, and compile together. Ex:
CMakeLists.txt // add_subdirectory(foo)
// set(foo_DIR ${CMAKE_CURRENT_BINARY_DIR}/foo)
// add_subdirectory(bar)
| foo/
| | CMakeLists.txt
| | include/, src/, etc.
| bar/
| | CMakeLists.txt // find_package(foo)
| | include/, src/, etc.
This looks simple, but both foo
and bar
have large CMakeLists.txt's, find-pkg'ing several other libraries, and I have multiple libraries in this style, where I'd like to compile together. If possible, I'd prefer to only change the top-level CMakeLists.txt, and not change the subdirectories/projects.
If I compile this from a blank build/ dir, I get the error build/foo/foo-config.cmake
could not find the requested file build/foo/foo-targets.cmake
, from bar/CMakeLists.txt:38 find_package
(foo). Hoping this was just a build order issue, and specifying the foo_DIR was sufficient, I commented out the #add_subdirectory(bar)
, successfully built foo, then uncommented out addsubdirectory and successfully built bar. (This requires the set(foo_DIR)
, to find the output cmake file, which came from this question, but didn't fix the simultaneous compile).
Is there a way to control the subdirectory compilation order, or something, so dependent subprojects' find_package
still works unmodified?