我尝试使用来自cmake的ExternalProject_Add命令下载和构建DevIL,但由于某种原因,git repo在项目的子文件夹中包含CMakeLists.txt文件。
我似乎找不到让ExternalProject_add在正确的文件夹上调用cmake的方法。 我尝试使用prefix和source_dir,但它仍然失败。
然后,我在网上看到了一个回答,其中涉及创建一个临时的CMakeLists.txt,它将调用正确的cmake路径。但由于我不知道如何提供cmake调用的路径,这意味着我必须把它放在下载的git repo中,后来显示这很痛苦...... 这是我使用的当前命令: include(" ExternalProject")
######### 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} )
我尝试过硬编码这样的路径(&#34; / src / ThirdParty_DevIL /&#34;部分),但它很丑陋,如果cmake决定将来改变它,那么& #39;打破。 此外,由于这实际上是复制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?
我对参数,路径等没有任何要求,所以请随时提出建议。 我怎样才能解决这个问题? 感谢
答案 0 :(得分:1)
您可以提供 CONFIGURE_COMMAND 选项,而不是修补源代码树,该选项使用正确的目录作为源:
ExternalProject_Add ( ThirdParty_DevIL
PREFIX "${DEVIL_BUILD_PATH}"
GIT_REPOSITORY "https://github.com/DentonW/DevIL"
INSTALL_DIR ${DEVIL_OUTPUT_PATH}
CONFIGURE_COMMAND ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
<SOURCE_DIR>/DevIL # Tell CMake to use subdirectory as source.
)
在这种情况下,您应手动添加此命令,通常通过 CMAKE_ARGS , CMAKE_CACHE_ARGS 等选项提供。但这不应该是一个真正的问题。
或者,您可以将ExternalProject_Add
分成两个调用:一个只下载包,第二个执行其他操作。在这些调用中,您可以使用不同的 SOURCE_DIR 选项:
ExternalProject_Add ( ThirdParty_DevIL_download
PREFIX "${DEVIL_BUILD_PATH}"
SOURCE_DIR "${DEVIL_BUILD_PATH}/src/ThirdParty_DevIL" # Explicitely set
GIT_REPOSITORY "https://github.com/DentonW/DevIL"
CONFIGURE_COMMAND "" # Disable all other steps
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
ExternalProject_Add ( ThirdParty_DevIL
PREFIX "${DEVIL_BUILD_PATH}"
DOWNLOAD_COMMAND "" # Disable download step
SOURCE_DIR "${DEVIL_BUILD_PATH}/src/ThirdParty_DevIL/DevIL" # Source dir for configuration
INSTALL_DIR ${DEVIL_OUTPUT_PATH}
CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
)
# Add dependency between to calls
add_dependencies(ThirdParty_DevIL ThirdParty_DevIL_download)
因为基于 PREFIX 的 SOURCE_DIR 的计算取决于外部项目的名称,并且两个调用的名称不同,所以此选项显式设置。
这种方法的缺点是构建日志显示了许多“未执行”步骤(第一次ExternalProject_Add()
调用和下载的配置,构建和安装,第二次调用的路径和更新)。
答案 1 :(得分:1)
我认为使用参数SOURCE_SUBDIR可以解决此问题,例如:
ExternalProject_Add ( ThirdParty_DevIL
PREFIX "${DEVIL_BUILD_PATH}"
GIT_REPOSITORY "https://github.com/DentonW/DevIL"
SOURCE_SUBDIR "DevIL"
....
)