From 66aae0900b940139d4d8f82185711afbbaf37fe9 Mon Sep 17 00:00:00 2001 From: Leland Lucius Date: Wed, 11 Mar 2020 22:31:19 -0500 Subject: [PATCH] Ease CMake and legacy build coexistence Cliff noticed that the CMake git ident was not being updated when pulling new changes. This was because it was getting captured at configuration time and, even if you pull more changes, the CMake configuration may not be redone automatically if the build files weren't also changed. So, this adds a new target to get the information at build time instead. --- cmake-proxies/cmake-modules/Version.cmake | 16 ++++++++++++++++ src/AboutDialog.cpp | 8 ++++++-- src/CMakeLists.txt | 21 ++++++++++++++++----- 3 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 cmake-proxies/cmake-modules/Version.cmake diff --git a/cmake-proxies/cmake-modules/Version.cmake b/cmake-proxies/cmake-modules/Version.cmake new file mode 100644 index 000000000..c3729a975 --- /dev/null +++ b/cmake-proxies/cmake-modules/Version.cmake @@ -0,0 +1,16 @@ +# Executed during build (NOT configuration) to create/update the +# RevisionIdent.h header. It will only update it if there was +# a change in git. + +execute_process( + COMMAND + ${GIT} show -s "--format=#define REV_LONG \"%H\"%n#define REV_TIME \"%cd\"%n%n" + OUTPUT_FILE + RevisionIdent.h.in + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + COMMAND_ECHO STDOUT +) + +configure_file( RevisionIdent.h.in RevisionIdent.h COPYONLY ) + diff --git a/src/AboutDialog.cpp b/src/AboutDialog.cpp index d22729e13..aabc6a7c6 100644 --- a/src/AboutDialog.cpp +++ b/src/AboutDialog.cpp @@ -53,12 +53,16 @@ hold information about one contributor to Audacity. #else #include "../images/AudacityLogoWithName.xpm" #endif -#include "RevisionIdent.h" +// Notice this is a "system include". This is on purpose and only until +// we convert over to CMake. Once converted, the "RevisionIndent.h" file +// should be deleted and this can be changed back to a user include if +// desired. +// // RevisionIdent.h may contain #defines like these ones: //#define REV_LONG "28864acb238cb3ca71dda190a2d93242591dd80e" //#define REV_TIME "Sun Apr 12 12:40:22 2015 +0100" - +#include #ifndef REV_TIME #define REV_TIME "unknown date and time" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b42627aa0..750aaacdc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,6 +14,21 @@ add_dependencies( ${TARGET} plug-ins ) def_vars() +# Add a target that will provide the git revision info +# whenever it changes. (Must be done at build time, not +# configuration time.) +if( GIT_FOUND ) + add_custom_target( + version + COMMAND + ${CMAKE_COMMAND} -D GIT=${GIT_EXECUTABLE} + -P ${CMAKE_MODULE_PATH}/Version.cmake + WORKING_DIRECTORY + ${_PRVDIR} + ) + add_dependencies( ${TARGET} version ) +endif() + # Handle Audio Units option if( CMAKE_SYSTEM_NAME MATCHES "Darwin" ) cmd_option( @@ -1002,10 +1017,6 @@ list( APPEND DEFINES WXINTL_NO_GETTEXT_MACRO WXUSINGDLL CMAKE - $<$: - REV_LONG="${GIT_COMMIT_LONG}" - REV_TIME="${GIT_COMMIT_TIME}" - > $<$: HAVE_LRINT > @@ -1347,7 +1358,7 @@ source_group( ${_INTDIR}/CMakeFiles/Audacity.dir/cmake_pch.hxx ) -target_sources( ${TARGET} PRIVATE ${HEADERS} ${SOURCES} ${RESOURCES} ${MAC_RESOURCES} ${WIN_RESOURCES} ) +target_sources( ${TARGET} PRIVATE ${HEADERS} ${SOURCES} ${RESOURCES} ${MAC_RESOURCES} ${WIN_RESOURCES} ${_PRVDIR}/RevisionIdent.h) target_compile_definitions( ${TARGET} PRIVATE ${DEFINES} ) target_compile_options( ${TARGET} PRIVATE ${OPTIONS} ) target_include_directories( ${TARGET} PRIVATE ${INCLUDES} )