Reputation: 107
I'd like to know how to get variables and options from an external project. For example, I'm using ExternalProject_Add
to add a library that my project depends on, the thing is that this dependency has some variables and options - some of them are on by default - I'm wondering, how to get them from my CMakeLists.txt
.
Upvotes: 8
Views: 3027
Reputation: 396
I parse for answer a question similar.
This work for me:
set(ZIP_DEP ${CMAKE_BINARY_DIR}/httpserver.zip)
if(NOT EXISTS ${ZIP_DEP})
file(DOWNLOAD https://github.com/d3roch4/httpserver/archive/master.zip
${ZIP_DEP})
execute_process(COMMAND unzip -o ${ZIP_DEP}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
RESULT_VARIABLE rv
)
if(NOT rv EQUAL 0)
message(FATAL_ERROR "error: extract of '${ZIP_DEP}' failed")
endif()
endif()
add_subdirectory(${CMAKE_BINARY_DIR}/httpserver-master)
Upvotes: 0
Reputation: 66288
All commands related with ExternalProject_Add
are executed at build stage, but your CMakeLists.txt
is interpreted at configure stage, when external library hasn't configured yet, so its variables and options are not defined.
More general, cmake variable from the external project can be extracted in two cases:
add_subdirectory
.Upvotes: 5