Skip to content

Commit

Permalink
CMake: Add SURGE_RELIABLE_VERSION_INFO option (defaults to ON)
Browse files Browse the repository at this point in the history
Reliable version info with commit hash and build date is useful, but it
slows down debugging, where there's often no need to rebuild otherwise.

This adds an option SURGE_RELIABLE_VERSION_INFO. Switching it off causes
version info to be generated at configuration time rather than on every
build.
  • Loading branch information
mvf committed Sep 16, 2021
1 parent 558997e commit d715304
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
6 changes: 3 additions & 3 deletions cmake/versiontools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ else ()
endif ()
endif ()

set(SURGE_FULL_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${fverpatch}.${GIT_COMMIT_HASH}")
set(SURGE_MAJOR_VERSION "${PROJECT_VERSION_MAJOR}")
set(SURGE_SUB_VERSION "${PROJECT_VERSION_MINOR}")
set(SURGE_FULL_VERSION "${CMAKE_PROJECT_VERSION_MAJOR}.${CMAKE_PROJECT_VERSION_MINOR}.${fverpatch}.${GIT_COMMIT_HASH}")
set(SURGE_MAJOR_VERSION "${CMAKE_PROJECT_VERSION_MAJOR}")
set(SURGE_SUB_VERSION "${CMAKE_PROJECT_VERSION_MINOR}")
set(SURGE_RELEASE_VERSION "${lverpatch}")
set(SURGE_RELEASE_NUMBER "${lverrel}")
set(SURGE_BUILD_HASH "${GIT_COMMIT_HASH}")
Expand Down
32 changes: 20 additions & 12 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -284,19 +284,27 @@ elseif(WIN32)
)
endif()

add_custom_target(git-info BYPRODUCTS ${CMAKE_BINARY_DIR}/geninclude/version.cpp
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -D PROJECT_VERSION_MAJOR=${CMAKE_PROJECT_VERSION_MAJOR}
-D PROJECT_VERSION_MINOR=${CMAKE_PROJECT_VERSION_MINOR}
-D SURGESRC=${CMAKE_SOURCE_DIR} -D SURGEBLD=${CMAKE_BINARY_DIR}
-D AZURE_PIPELINE=${AZURE_PIPELINE}
-D WIN32=${WIN32}
-D CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-D SURGE_COMPILER_INFO="${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}"
-P ${CMAKE_SOURCE_DIR}/cmake/versiontools.cmake
)
option(SURGE_RELIABLE_VERSION_INFO "Update version info on every build (off: generate only at configuration time)" ON)
if(SURGE_RELIABLE_VERSION_INFO)
add_custom_target(version-info BYPRODUCTS ${CMAKE_BINARY_DIR}/geninclude/version.cpp
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -D CMAKE_PROJECT_VERSION_MAJOR=${CMAKE_PROJECT_VERSION_MAJOR}
-D CMAKE_PROJECT_VERSION_MINOR=${CMAKE_PROJECT_VERSION_MINOR}
-D SURGESRC=${CMAKE_SOURCE_DIR} -D SURGEBLD=${CMAKE_BINARY_DIR}
-D AZURE_PIPELINE=${AZURE_PIPELINE}
-D WIN32=${WIN32}
-D CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-D CMAKE_CXX_COMPILER_ID=${CMAKE_CXX_COMPILER_ID}
-D CMAKE_CXX_COMPILER_VERSION=${CMAKE_CXX_COMPILER_VERSION}
-P ${CMAKE_SOURCE_DIR}/cmake/versiontools.cmake
)
add_dependencies(${PROJECT_NAME} version-info)
else()
set(SURGESRC ${CMAKE_SOURCE_DIR})
set(SURGEBLD ${CMAKE_BINARY_DIR})
include(${CMAKE_SOURCE_DIR}/cmake/versiontools.cmake)
endif()
target_sources(${PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR}/geninclude/version.cpp)
add_dependencies(${PROJECT_NAME} git-info)

add_library(surge::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME} PUBLIC
Expand Down
2 changes: 1 addition & 1 deletion src/common/version.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Surge
const char* Build::FullVersionStr = "@SURGE_FULL_VERSION@";
const char* Build::BuildHost = "@SURGE_BUILD_FQDN@";
const char* Build::BuildArch = "@SURGE_BUILD_ARCH@";
const char *Build::BuildCompiler = "@SURGE_COMPILER_INFO@";
const char *Build::BuildCompiler = "@CMAKE_CXX_COMPILER_ID@-@CMAKE_CXX_COMPILER_VERSION@";

const char* Build::BuildLocation = "@SURGE_BUILD_LOCATION@";

Expand Down

0 comments on commit d715304

Please sign in to comment.