From 243fd10db0ea08409eab81cb881bf67124529f53 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 18 Jan 2021 23:48:16 +0100 Subject: [PATCH] CMake: Set PANDA_BUILD_DATE_STR if SOURCE_DATE_EPOCH is set Adds CMake support for the 54638bfc10bd766563830adaac118a4e55b4b52b change. One thing to note, compared to makepanda, is that CMake doesn't automatically rebuild the file if this env var is changed. --- dtool/PandaVersion.cmake | 13 +++++++++++++ dtool/src/dtoolbase/pandaVersion.h.in | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/dtool/PandaVersion.cmake b/dtool/PandaVersion.cmake index 4ea2ef6688..f1fc591a97 100644 --- a/dtool/PandaVersion.cmake +++ b/dtool/PandaVersion.cmake @@ -43,6 +43,19 @@ set(PANDA_VERSION_SYMBOL panda_version_${PROJECT_VERSION_MAJOR}_${PROJECT_VERSIO # for each component. math(EXPR PANDA_NUMERIC_VERSION "${PROJECT_VERSION_MAJOR}*1000000 + ${PROJECT_VERSION_MINOR}*1000 + ${PROJECT_VERSION_PATCH}") +# If SOURCE_DATE_EPOCH is set, it affects PandaSystem::get_build_date() +if(DEFINED ENV{SOURCE_DATE_EPOCH}) + if(CMAKE_VERSION VERSION_LESS "3.8") + message(FATAL_ERROR "CMake 3.8 is required to support SOURCE_DATE_EPOCH properly.") + endif() + + string(TIMESTAMP _build_date "%b %d %Y %H:%M:%S" UTC) + + # CMake doesn't support %e, replace leading zero in day with space + string(REGEX REPLACE "^([a-zA-Z]+) 0" "\\1 " PANDA_BUILD_DATE_STR "${_build_date}") + unset(_build_date) +endif() + # The Panda Git SHA1 refspec, for PandaSystem::get_git_commit() find_package(Git QUIET) if(GIT_EXECUTABLE) diff --git a/dtool/src/dtoolbase/pandaVersion.h.in b/dtool/src/dtoolbase/pandaVersion.h.in index 4854ae47df..c83179f172 100644 --- a/dtool/src/dtoolbase/pandaVersion.h.in +++ b/dtool/src/dtoolbase/pandaVersion.h.in @@ -49,6 +49,11 @@ out from CVS by the builder). */ #define PANDA_VERSION_STR "@PANDA_VERSION_STR@" +/* This is the build date expressed as a string. It can be left undefined + to have this set automatically at build time, but it may be desirable to + override this to make the build process deterministic. */ +#cmakedefine PANDA_BUILD_DATE_STR "@PANDA_BUILD_DATE_STR@" + /* This is the Git commit we built Panda from, or an empty string if this isn't known. */ #define PANDA_GIT_COMMIT_STR "@PANDA_GIT_COMMIT_STR@"