我正在尝试使用来自 cmake 的 ExternalProject_Add 命令下载和构建 DevIL,但由于某种原因,git repo 在项目的子文件夹中有 CMakeLists.txt 文件。
我似乎找不到让 ExternalProject_add 在正确文件夹上调用 cmake 的方法。我尝试使用前缀和 source_dir,但它仍然失败。
然后,我在网上看到了一个答案,其中涉及创建一个临时的 CMakeLists.txt,它将调用正确的 cmake 路径。但是由于我不知道如何提供 cmake 调用的路径,这意味着我必须将它放在下载的 git repo 中,后来证明这很痛苦......这是我正在使用的当前命令:包括(“外部项目”)
######### Search for required third-party libraries. If not found, attempt to download and build them ########
set ( DEVIL_ROOT "${THIRD_PARTY_OUTPUT_PATH}/DevIL" )
option ( BUILD_DEVIL "Download and build DevIL" FALSE )
find_package ( Devil )
if ( NOT DEVIL_FOUND )
message ( STATUS "DevIL not found. Forcing to build own copy...")
set ( BUILD_DEVIL TRUE )
endif()
if ( BUILD_DEVIL )
set ( DEVIL_BUILD_PATH "${THIRD_PARTY_BUILD_PATH}/DevIL/" )
set ( DEVIL_OUTPUT_PATH "${THIRD_PARTY_OUTPUT_PATH}/DevIL" )
message ( STATUS "Downloading DevIL and building...")
file( WRITE ${DEVIL_BUILD_PATH}/DevilCMakeLists.txt "cmake_minimum_required( VERSION 3.0 ) \n add_subdirectory ( DevIL )" )
ExternalProject_Add ( ThirdParty_DevIL
PREFIX "${DEVIL_BUILD_PATH}"
GIT_REPOSITORY "https://github.com/DentonW/DevIL"
PATCH_COMMAND cmake -E copy "${DEVIL_BUILD_PATH}/DevilCMakeLists.txt" "${DEVIL_BUILD_PATH}/src/ThirdParty_DevIL/DevIL/"
INSTALL_DIR ${DEVIL_OUTPUT_PATH}
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> )
list ( APPEND THIRD_PARTY_DEPENDENCIES ThirdParty_DevIL )
set ( DEVIL_INCLUDE_DIR "${DEVIL_OUTPUT_PATH}/include" )
set ( DEVIL_LIBRARY devil )
add_definitions ( -DDEVIL )
endif()
list ( APPEND THIRD_PARTY_INCLUDE_DIRS "${DEVIL_INCLUDE_DIR}" )
list ( APPEND THIRD_PARTY_LIBRARIES ${DEVIL_LIBRARY} )
我尝试像这样对路径进行硬编码(“/src/ThirdParty_DevIL/”部分),但它丑得要命,如果 cmake 决定在将来更改它,它就会中断。此外,由于这实际上是在 git 树中复制文件,cmake 后来抱怨
Failed to unstash changes in:
'<yadda yadda>/ThirdParty/build//DevIL//src/ThirdParty_DevIL/'.
You will have to resolve the conflicts manually
有没有办法使这个解决方案(创建一个临时的 CMakeListst.txt )工作?或者更好的是,是否有另一种解决方案,只涉及正确配置 ExternalProject_add ?
我对参数、路径等没有任何要求,所以请随意提出任何建议。我怎样才能解决这个问题?谢谢