Skip to content

Commit

Permalink
cmake: Only generate camkes-gen.cmake if it is out of date
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Adrian Danis authored and Adrian Danis committed Mar 23, 2018
1 parent e2e2290 commit 2bf14a0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions camkes.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 2bf14a0

Please sign in to comment.