Reputation: 1358
TLDR: I would like to ask CMake to wait for ExternalProject_Add
to complete before it attempts to move on to the next subdirectory and build a library that happens to use one of the files of the external project. In other words, I like to declare an external project as a dependency for a shared library.
More Description:
Suppose that my CMake project has two directories: thirdparty
and src
. My top-level CMakeLists.txt
file has:
add_subdirectory(thirdparty)
add_subdirectory(src)
thirdparty/CMakeLists.txt
contains multiple ExternalProject_Add
commands. My original intention was to pull and build all these external projects and then move on to building my own libraries and executables in src
. Unfortunately, this didn't go as I planned:
One of my external projects is called libsvm
. And my src/CMakeLists.txt
has the following:
set(Libsvm_SOURCE_FILES
${PROJECT_BINARY_DIR}/thirdparty/libsvm/src/libsvm/svm.cpp
)
include_directories(
${Libsvm_INCLUDE_DIR}
)
add_library(
mysvm
SHARED
${Libsvm_SOURCE_FILES}
)
Now the problem I am facing with is that CMake is unable to find ${Libsvm_SOURCE_FILES}, apparently because this step is being executed before the ExternalProject_Add
in my thirdparty/CMakeLists.txt
file is executed.
I would like to declare this external project as a dependency for this library.
Broader Question: Is there a clean way to force CMake to finish everything in first subdirectory before moving on to the next? If not, do you recommend that I make any change in the hierarchy and organization of my CMakeLists files?
Thanks!
Upvotes: 2
Views: 1861
Reputation: 66288
CMake expects every source file, passed to add_library
or add_executable
, to be existed unless it is marked as GENERATED. This property is automatically set for files listed as OUTPUT for add_custom_command
. In other cases one need to set this property explicitly:
set_source_files_properties(${Libsvm_SOURCE_FILES} PROPERTIES GENERATED TRUE)
Upvotes: 2