From 2a6f4d879ca79158b92aa84ca63137b86ed4704d Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Wed, 28 Jun 2023 19:44:01 +0200 Subject: [PATCH] CMake: Generate scmrev.h at build time instead of configure time. --- CMake/ScmRevGen.cmake | 53 +++++++++++++++++++++ CMakeLists.txt | 77 +++++++------------------------ Source/Core/Common/CMakeLists.txt | 2 + 3 files changed, 71 insertions(+), 61 deletions(-) create mode 100644 CMake/ScmRevGen.cmake diff --git a/CMake/ScmRevGen.cmake b/CMake/ScmRevGen.cmake new file mode 100644 index 0000000000..aacf7491ce --- /dev/null +++ b/CMake/ScmRevGen.cmake @@ -0,0 +1,53 @@ +cmake_minimum_required(VERSION 3.13) + +# for revision info +if(GIT_FOUND) + # defines DOLPHIN_WC_REVISION + execute_process(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} rev-parse HEAD + OUTPUT_VARIABLE DOLPHIN_WC_REVISION + OUTPUT_STRIP_TRAILING_WHITESPACE) + # defines DOLPHIN_WC_DESCRIBE + execute_process(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} describe --always --long --dirty + OUTPUT_VARIABLE DOLPHIN_WC_DESCRIBE + OUTPUT_STRIP_TRAILING_WHITESPACE) + + # remove hash (and trailing "-0" if needed) from description + string(REGEX REPLACE "(-0)?-[^-]+((-dirty)?)$" "\\2" DOLPHIN_WC_DESCRIBE "${DOLPHIN_WC_DESCRIBE}") + + # defines DOLPHIN_WC_BRANCH + execute_process(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD + OUTPUT_VARIABLE DOLPHIN_WC_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE) +endif() + +# version number +set(DOLPHIN_VERSION_MAJOR "5") +set(DOLPHIN_VERSION_MINOR "0") +if(DOLPHIN_WC_BRANCH STREQUAL "stable") + set(DOLPHIN_VERSION_PATCH "0") +else() + set(DOLPHIN_VERSION_PATCH ${DOLPHIN_WC_REVISION}) +endif() + +# If Dolphin is not built from a Git repository, default the version info to +# reasonable values. +if(NOT DOLPHIN_WC_REVISION) + set(DOLPHIN_WC_DESCRIBE "${DOLPHIN_VERSION_MAJOR}.${DOLPHIN_VERSION_MINOR}") + set(DOLPHIN_WC_REVISION "${DOLPHIN_WC_DESCRIBE} (no further info)") + set(DOLPHIN_WC_BRANCH "master") +endif() + +if(DOLPHIN_WC_BRANCH STREQUAL "master" OR DOLPHIN_WC_BRANCH STREQUAL "stable") + set(DOLPHIN_WC_IS_STABLE "1") +else() + set(DOLPHIN_WC_IS_STABLE "0") +endif() + +configure_file( + "${PROJECT_SOURCE_DIR}/Source/Core/Common/scmrev.h.in" + "${PROJECT_BINARY_DIR}/Source/Core/Common/scmrev.h.tmp" +) + +execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${PROJECT_BINARY_DIR}/Source/Core/Common/scmrev.h.tmp" "${PROJECT_BINARY_DIR}/Source/Core/Common/scmrev.h") + +file(REMOVE "${PROJECT_BINARY_DIR}/Source/Core/Common/scmrev.h.tmp") diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b9b324fc6..96cd381b3a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -196,59 +196,6 @@ endif() # setup CCache include(CCache) -# for revision info -find_package(Git) -if(GIT_FOUND) - # make sure version information gets re-run when the current Git HEAD changes - execute_process(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} rev-parse --git-path HEAD - OUTPUT_VARIABLE dolphin_git_head_filename - OUTPUT_STRIP_TRAILING_WHITESPACE) - set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${dolphin_git_head_filename}") - - execute_process(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} rev-parse --symbolic-full-name HEAD - OUTPUT_VARIABLE dolphin_git_head_symbolic - OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - COMMAND ${GIT_EXECUTABLE} rev-parse --git-path ${dolphin_git_head_symbolic} - OUTPUT_VARIABLE dolphin_git_head_symbolic_filename - OUTPUT_STRIP_TRAILING_WHITESPACE) - set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${dolphin_git_head_symbolic_filename}") - - # defines DOLPHIN_WC_REVISION - execute_process(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} rev-parse HEAD - OUTPUT_VARIABLE DOLPHIN_WC_REVISION - OUTPUT_STRIP_TRAILING_WHITESPACE) - # defines DOLPHIN_WC_DESCRIBE - execute_process(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} describe --always --long --dirty - OUTPUT_VARIABLE DOLPHIN_WC_DESCRIBE - OUTPUT_STRIP_TRAILING_WHITESPACE) - - # remove hash (and trailing "-0" if needed) from description - string(REGEX REPLACE "(-0)?-[^-]+((-dirty)?)$" "\\2" DOLPHIN_WC_DESCRIBE "${DOLPHIN_WC_DESCRIBE}") - - # defines DOLPHIN_WC_BRANCH - execute_process(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD - OUTPUT_VARIABLE DOLPHIN_WC_BRANCH - OUTPUT_STRIP_TRAILING_WHITESPACE) -endif() - -# version number -set(DOLPHIN_VERSION_MAJOR "5") -set(DOLPHIN_VERSION_MINOR "0") -if(DOLPHIN_WC_BRANCH STREQUAL "stable") - set(DOLPHIN_VERSION_PATCH "0") -else() - set(DOLPHIN_VERSION_PATCH ${DOLPHIN_WC_REVISION}) -endif() - -# If Dolphin is not built from a Git repository, default the version info to -# reasonable values. -if(NOT DOLPHIN_WC_REVISION) - set(DOLPHIN_WC_DESCRIBE "${DOLPHIN_VERSION_MAJOR}.${DOLPHIN_VERSION_MINOR}") - set(DOLPHIN_WC_REVISION "${DOLPHIN_WC_DESCRIBE} (no further info)") - set(DOLPHIN_WC_BRANCH "master") -endif() - # Architecture detection and arch specific settings message(STATUS "Detected architecture: ${CMAKE_SYSTEM_PROCESSOR}") @@ -1012,20 +959,28 @@ endif() ######################################## # Pre-build events: Define configuration variables and write SCM info header # -if(DOLPHIN_WC_BRANCH STREQUAL "master" OR DOLPHIN_WC_BRANCH STREQUAL "stable") - set(DOLPHIN_WC_IS_STABLE "1") -else() - set(DOLPHIN_WC_IS_STABLE "0") -endif() # Remove in-tree revision information generated by Visual Studio # This is because the compiler will check in-tree first and use this, even if it is outdated file(REMOVE "${PROJECT_SOURCE_DIR}/Source/Core/Common/scmrev.h") -configure_file( - "${PROJECT_SOURCE_DIR}/Source/Core/Common/scmrev.h.in" - "${PROJECT_BINARY_DIR}/Source/Core/Common/scmrev.h" +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Source/Core/Common) +if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/Source/Core/Common/scmrev.h) + file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/Source/Core/Common/scmrev.h) +endif() + +find_package(Git) +if(NOT GIT_FOUND) + set(GIT_EXECUTABLE "") +endif() +add_custom_target( + dolphin_scmrev + ${CMAKE_COMMAND} -DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR} -DPROJECT_BINARY_DIR=${PROJECT_BINARY_DIR} -DDISTRIBUTOR=${DISTRIBUTOR} -DDOLPHIN_DEFAULT_UPDATE_TRACK=${DOLPHIN_DEFAULT_UPDATE_TRACK} -DGIT_FOUND=${GIT_FOUND} -DGIT_EXECUTABLE=${GIT_EXECUTABLE} -P ${CMAKE_SOURCE_DIR}/CMake/ScmRevGen.cmake + BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/Source/Core/Common/scmrev.h + VERBATIM ) + +# This is here so #include "Common/scmrev.h" finds the generated header. include_directories("${PROJECT_BINARY_DIR}/Source/Core") ######################################## diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index 144c229438..3092103b16 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -135,6 +135,8 @@ add_library(common WorkQueueThread.h ) +add_dependencies(common dolphin_scmrev) + if(NOT MSVC AND _M_ARM_64) set_source_files_properties( Crypto/AES.cpp