From 2bf14a0aa0206ca532ee84c5d2b3e3580c2aa302 Mon Sep 17 00:00:00 2001 From: Adrian Danis Date: Fri, 23 Mar 2018 11:45:22 +1100 Subject: [PATCH] cmake: Only generate camkes-gen.cmake if it is out of date The camkes-gen.cmake only needs to be recreated if either any of its dependencies have changed, or if the invocation to the camkes tool itself has changed. Doing this forces us to perform some manual dependency management which is highly undesirable, but due to the extreme cost to invoking camkes this is worth it. After this change it is now possible to re-invoke cmake and change cache variables in the cmake-gui (that do not get passed to camkes) without the cost of needlessly regenerating the camkes-gen.cmake file. --- camkes.cmake | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/camkes.cmake b/camkes.cmake index c874f254..4d1b3d74 100644 --- a/camkes.cmake +++ b/camkes.cmake @@ -539,6 +539,7 @@ function(GenerateCAmkESRootserver) # Need to ensure our camkes_gen folder exists as camkes will not create the directory file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/camkes_gen") set(deps_file "${CMAKE_CURRENT_BINARY_DIR}/camkes_gen/deps") + set(invoc_file "${CMAKE_CURRENT_BINARY_DIR}/camkes_gen/last_invocation") set(gen_outfile "${CMAKE_CURRENT_BINARY_DIR}/camkes-gen.cmake") set(camkes_invocation ${CMAKE_COMMAND} -E env ${CAMKES_TOOL_ENVIRONMENT} "${CAMKES_TOOL}" @@ -550,7 +551,22 @@ function(GenerateCAmkESRootserver) ) # We need to determine if we actually need to regenerate. We start by assuming that we do set(regen TRUE) + if((EXISTS "${invoc_file}") AND (EXISTS "${deps_file}") AND (EXISTS "${gen_outfile}")) + file(READ "${invoc_file}" old_contents) + if ("${old_contents}" STREQUAL "${camkes_invocation}") + MakefileDepsToList("${deps_file}" deps) + # At this point assume we do not need to regenerate, unless we found a newer file + set(regen FALSE) + foreach(dep IN LISTS deps) + if("${dep}" IS_NEWER_THAN "${gen_outfile}") + set(regen TRUE) + break() + endif() + endforeach() + endif() + endif() if (regen) + message(STATUS "camkes-gen.cmake is out of date. Regenerating...") execute_process( # First delete the data structure cache directory as this is a new build COMMAND @@ -560,6 +576,7 @@ function(GenerateCAmkESRootserver) OUTPUT_VARIABLE camkes_output ERROR_VARIABLE camkes_output ) + file(WRITE "${invoc_file}" "${camkes_invocation}") if (camkes_gen_error) message(FATAL_ERROR "Failed to generate camkes-gen.cmake: ${camkes_output}") endif()