我项目中的一个依赖项是OpenCV,它是从源代码编译的。下载后,cmake总是尝试签出编译最新的主提交,我需要标记3.4.2。 cmake版本为3.1.3。这是cmake脚本的相关部分:
include(ExternalProject)
set(OCV_CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=. -DCMAKE_SOURCE_DIR=${SOURCE_DIR}
-DCMAKE_BINARY_DIR=${BINARY_DIR} -DENABLE_FAST_MATH=ON -DWITH_EIGEN=1
-DWITH_TBB=ON -DENABLE_BUILD_HARDENING=ON
-DWITH_MATLAB=ON -DWITH_GTK=ON -DWITH_GTK_2_X=ON
-DBUILD_LIST=core,features2d,highgui,improc,calib3d,imgcodecs,videoio,video)
if( NOT OCV_TAG )
set(OCV_TAG 3.4.2)
endif()
ExternalProject_Add(opencv
DOWNLOAD_COMMAND git clone https://github.com/opencv/opencv.git opencv
DOWNLOAD_DIR ${CMAKE_INSTALL_PREFIX}/src/lib/
GIT_TAG "${OCV_TAG}"
SOURCE_DIR ${CMAKE_INSTALL_PREFIX}/src/lib/opencv
BINARY_DIR ${CMAKE_INSTALL_PREFIX}/bin/lib/opencv
INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin/lib/opencv
TMP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tmp
CMAKE_ARGS ${OCV_CMAKE_ARGS}
BUILD_COMMAND make -j ${N}
INSTALL_COMMAND make install
UPDATE_COMMAND
TEST_COMMAND make -j ${N} # make in the end because of some bug (?) that breaks links for libraries
BUILD_IN_SOURCE 0
BUILD_ALWAYS 0
DOWNLOAD_NO_PROGRESS 0
UPDATE_DISCONNECTED 1
LOG_DOWNLOAD 0
LOG_CONFIGURE 0
LOG_INSTALL 0
LOG_BUILD 0
LOG_UPDATE 0
LOG_TEST 0
GIT_PROGRESS 1
)
我尝试了相关的GIT_TAG字符串的这些变体:
if( NOT OCV_TAG )
set(OCV_TAG "3.4.2")
endif()
...
GIT_TAG "${OCV_TAG}"
GIT_TAG "3.4.2"
GIT_TAG 3.4.2
GIT_TAG origin/master/3.4.2
GIT_TAG master/3.4.2
尽管根据文档它必须起作用,但这些都不起作用。有人遇到了这个问题/或实际上有cmake 3.1.3的有效示例吗? 谢谢!
答案 0 :(得分:1)
当CMake自行执行项目下载时,选项GIT_TAG
仅与GIT_REPOSITORY
一起使用。
如果您手动进行下载(通过DOWNLOAD_COMMAND
),那么您也应该手动调整分支。