I'm working on reducing build time for my project. In my top level CMakeLists.txt
I add several external projects, e.g. googletest
:
ExternalProject_Add(googletest
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/googletest"
GIT_REPOSITORY https://github.com/google/googletest.git
INSTALL_DIR "${CMAKE_BINARY_DIR}"
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}"
)
When I recompile the project, googletest
also recompiles or at least it takes about 15 second for being processed. I can avoid that by adding UPDATE_COMMAND ""
. Then goolgetest will not be recompiled and building is about 15s faster.
Ideally googletest would update, if e.g. the local clone wasn't updated for a day. That way I would not need to comment the UPDATE_COMMAND ""
-line out for getting the latest version.
Is there a way to accomplish this automatically?
答案 0 :(得分:2)
可以将当前日期存储在缓存变量中,并且只有在自上次cmake配置运行后更改日期时才更新googletest。
在cmake mailing list archive上找到了以下脚本中使用的“TODAY”宏。macro (TODAY RESULT)
if (WIN32)
execute_process(COMMAND "date" "/T" OUTPUT_VARIABLE ${RESULT})
string(REGEX REPLACE "(..)/(..)/..(..).*" "\\3\\2\\1"
${RESULT} ${${RESULT}})
elseif(UNIX)
execute_process(COMMAND "date" "+%d/%m/%Y" OUTPUT_VARIABLE ${RESULT})
string(REGEX REPLACE "(..)/(..)/..(..).*" "\\3\\2\\1"
${RESULT} ${${RESULT}})
else (WIN32)
message(SEND_ERROR "date not implemented")
set(${RESULT} 000000)
endif (WIN32)
endmacro (TODAY)
TODAY(CURRENT_DATE)
message("Current date is: ${CURRENT_DATE}")
if(${PREVIOUS_CURRENT_DATE} AND ${PREVIOUS_CURRENT_DATE} STREQUAL ${CURRENT_DATE})
message("Sorry. Googletest already updated today.")
else()
message("Ok. It's first time today!")
set(PREVIOUS_CURRENT_DATE ${CURRENT_DATE} CACHE INTERNAL "Current date")
ExternalProject_Add(googletest
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/googletest"
GIT_REPOSITORY https://github.com/google/googletest.git
INSTALL_DIR "${CMAKE_BINARY_DIR}"
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}"
)
endif()
如果更改了构建目录或删除了CMakeCache.txt,则缓存日期将丢失 - 在cmake配置/构建之后将更新googletest。
另请注意,仅在cmake配置步骤期间比较日期。 因此,除非明确执行cmake配置或修改CMakeLists.txt,否则将跳过日期比较。
答案 1 :(得分:1)
开箱即用,这是不可能的。也许您可以使用UPDATE_DISCONNECTED
提出解决方法。
可能最好为CMake提交功能请求(并在此处共享)。我认为你的用例是有效的。