我正在尝试使用ExternalProject_Add将外部项目作为库添加到我的项目中:
ExternalProject_Add(
xgboost
GIT_REPOSITORY https://github.com/dmlc/xgboost.git
GIT_TAG v0.60
PREFIX ${CMAKE_CURRENT_BINARY_DIR}
INSTALL_COMMAND ""
)
另外,我正在定义库目标并将外部项目添加为依赖项:
set(XGBOOST_PREFIX_PATH "${CMAKE_CURRENT_BINARY_DIR}/src")
set(XGBOOST_BINARY_PATH "${XGBOOST_PREFIX_PATH}/xgboost-build")
set(XGBOOST_BINARY_INCLUDE "${XGBOOST_PREFIX_PATH}/xgboost/include;${XGBOOST_PREFIX_PATH}/xgboost/dmlc-core/include;${XGBOOST_PREFIX_PATH}/xgboost/rabit/include")
add_library(libxgboost IMPORTED STATIC GLOBAL)
add_dependencies(libxgboost xgboost)
set_target_properties(libxgboost PROPERTIES
"IMPORTED_LOCATION" "${XGBOOST_BINARY_PATH}/liblibxgboost.dylib"
"IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}"
"INTERFACE_INCLUDE_DIRECTORIES" "${XGBOOST_BINARY_INCLUDE}"
)
在另一个CMakeLists.txt文件中:
add_library(somelib STATIC SomeLib.cpp)
target_include_directories(somelib PUBLIC libxgboost)
target_link_libraries(somelib libxgboost)
问题在于CMake的INTERFACE_INCLUDE_DIRECTORIES无法导出不存在的包含目录。
是否有其他方法可以使所有依赖于libxgboost的目标自动包含头文件?
更新:
错误消息:
CMake Error in somelib/CMakeLists.txt:
Imported target "libxgboost" includes non-existent path
"build/xgboost/src/xgboost/include"
in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:
* The path was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and references files it does not
provide.
IMPORTED_LINK_INTERFACE_LIBRARIES
已经过时,建议使用INTERFACE_LINK_LIBRARIES
。您考虑过使用execute_process()
来调用ExternalProject CMakeLists.txt上的cmake
(两次),这样您就可以在配置时使用依赖项了吗?或者,您可以在CMakeLists.txt配置期间模拟创建仅依赖关系目录的方式。 - utopia