1
我正在使用CMake和ExternalProject_Add構建一個外部庫。我使用的答案here生成以下(捕獲命令行輸入到CMake的,以便將其傳遞給ExternalProject_Add命令):將CMake變量傳遞給ExternalProject_Add
get_cmake_property(CACHE_VARS CACHE_VARIABLES)
foreach(CACHE_VAR ${CACHE_VARS})
get_property(CACHE_VAR_HELPSTRING CACHE ${CACHE_VAR} PROPERTY HELPSTRING)
if(CACHE_VAR_HELPSTRING STREQUAL "No help, variable specified on the command line.")
get_property(CACHE_VAR_TYPE CACHE ${CACHE_VAR} PROPERTY TYPE)
if(CACHE_VAR_TYPE STREQUAL "UNINITIALIZED")
set(CACHE_VAR_TYPE)
else()
set(CACHE_VAR_TYPE :${CACHE_VAR_TYPE})
endif()
set(CMAKE_ARGS "${CMAKE_ARGS} -D${CACHE_VAR}${CACHE_VAR_TYPE}=\"${${CACHE_VAR}}\"")
endif()
endforeach()
的ExternalProject_Add命令如下:
ExternalProject_Add(external_lib
URL ${EXTERNALLIB_SOURCE_DIR}
PREFIX ${EXTERNALLIB_PREFIX}
CMAKE_ARGS "${CMAKE_ARGS};-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
INSTALL_DIR ${EXTERNALLIB_INSTALL_DIR}
BINARY_DIR "${EXTERNALLIB_PREFIX}/lib"
)
我無法弄清楚如何正確地將CMAKE_ARGS變量傳遞給此命令。顯然,其他變量工作正常,但CMAKE_ARGS似乎沒有被正確擴展,因爲我知道它包含我想要它包含的內容。我在CMake語法上做錯了什麼?