CMake: optional date/time overrides for reproducible builds
authorCampbell Barton <ideasman42@gmail.com>
Tue, 10 May 2016 16:43:58 +0000 (02:43 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 10 May 2016 16:47:38 +0000 (02:47 +1000)
CMakeLists.txt
build_files/cmake/buildinfo.cmake
source/creator/CMakeLists.txt

index 6fc4ca2729d701e8b95e206cec0614836e8ca408..af457de21fac59d2faf4029ed2b847974c4122a7 100644 (file)
@@ -218,6 +218,10 @@ if(${CMAKE_VERSION} VERSION_LESS 2.8.8)
        # add_library OBJECT arg unsupported
        set(WITH_BUILDINFO OFF)
 endif()
+set(BUILDINFO_OVERRIDE_DATE "" CACHE STRING "Use instead of the current date for reproducable builds (empty string disables this option)")
+set(BUILDINFO_OVERRIDE_TIME "" CACHE STRING "Use instead of the current time for reproducable builds (empty string disables this option)")
+mark_as_advanced(BUILDINFO_OVERRIDE_DATE)
+mark_as_advanced(BUILDINFO_OVERRIDE_TIME)
 
 option(WITH_IK_ITASC      "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON)
 option(WITH_IK_SOLVER     "Enable Legacy IK solver (only disable for development)" ON)
index 4caa4a954ea5b349c2a1d4628d4f8adcc3154f1d..af0ccd250e8031a4139f398fc64a4b9888993304 100644 (file)
@@ -1,5 +1,10 @@
-# This is called by cmake as an extermal process from
+# This is called by cmake as an external process from
 # ./source/creator/CMakeLists.txt to write ./source/creator/buildinfo.h
+# Caller must define:
+#   SOURCE_DIR
+# Optional overrides:
+#   BUILD_DATE
+#   BUILD_TIME
 
 # Extract working copy information for SOURCE_DIR into MY_XXX variables
 # with a default in case anything fails, for example when using git-svn
@@ -128,12 +133,19 @@ endif()
 # BUILD_PLATFORM and BUILD_PLATFORM are taken from CMake
 # but BUILD_DATE and BUILD_TIME are platform dependent
 if(UNIX)
-       execute_process(COMMAND date "+%Y-%m-%d" OUTPUT_VARIABLE BUILD_DATE OUTPUT_STRIP_TRAILING_WHITESPACE)
-       execute_process(COMMAND date "+%H:%M:%S" OUTPUT_VARIABLE BUILD_TIME OUTPUT_STRIP_TRAILING_WHITESPACE)
-endif()
-if(WIN32)
-       execute_process(COMMAND cmd /c date /t OUTPUT_VARIABLE BUILD_DATE OUTPUT_STRIP_TRAILING_WHITESPACE)
-       execute_process(COMMAND cmd /c time /t OUTPUT_VARIABLE BUILD_TIME OUTPUT_STRIP_TRAILING_WHITESPACE)
+       if(NOT BUILD_DATE)
+               execute_process(COMMAND date "+%Y-%m-%d" OUTPUT_VARIABLE BUILD_DATE OUTPUT_STRIP_TRAILING_WHITESPACE)
+       endif()
+       if(NOT BUILD_TIME)
+               execute_process(COMMAND date "+%H:%M:%S" OUTPUT_VARIABLE BUILD_TIME OUTPUT_STRIP_TRAILING_WHITESPACE)
+       endif()
+elseif(WIN32)
+       if(NOT BUILD_DATE)
+               execute_process(COMMAND cmd /c date /t OUTPUT_VARIABLE BUILD_DATE OUTPUT_STRIP_TRAILING_WHITESPACE)
+       endif()
+       if(NOT BUILD_TIME)
+               execute_process(COMMAND cmd /c time /t OUTPUT_VARIABLE BUILD_TIME OUTPUT_STRIP_TRAILING_WHITESPACE)
+       endif()
 endif()
 
 # Write a file with the BUILD_HASH define
index b7d8381639d701aec08f653a65ca86a1b9a2df6c..daba01e33c728b8a66735a9df70e116c5b5984e1 100644 (file)
@@ -186,6 +186,9 @@ if(WITH_BUILDINFO)
        add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_buildinfo.h
                COMMAND ${CMAKE_COMMAND}
                -DSOURCE_DIR=${CMAKE_SOURCE_DIR}
+               # overrides only used when non-empty strings
+               -DBUILD_DATE=${BUILDINFO_OVERRIDE_DATE}
+               -DBUILD_TIME=${BUILDINFO_OVERRIDE_TIME}
                -P ${CMAKE_SOURCE_DIR}/build_files/cmake/buildinfo.cmake)
 
        # buildinfo.h is a generated file