Changeset: 8a323d18ae39 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8a323d18ae39 Added Files: common/utils/FindRevision.cmake Modified Files: CMakeLists.txt common/utils/CMakeLists.txt common/utils/revision.c monetdb_config.h.in Branch: cmake-fun Log Message:
The MERCURIAL_ID must be computed on every build. diffs (126 lines): diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,20 +54,11 @@ string(TOLOWER "${CMAKE_SYSTEM_NAME}" CM string(TOLOWER "${CMAKE_C_COMPILER_ID}" CMAKE_C_COMPILER_ID_LOWER) set("HOST" "${CMAKE_SYSTEM_PROCESSOR_LOWER}-pc-${CMAKE_SYSTEM_NAME_LOWER}-${CMAKE_C_COMPILER_ID_LOWER}") -set(DFT_STRICT "NO") -# Check current version control revision -if(EXISTS "${CMAKE_SOURCE_DIR}/.hg") - exec_program("hg" "${CMAKE_SOURCE_DIR}" ARGS "id -i" OUTPUT_VARIABLE HG_OUPUT_RES RETURN_VALUE HG_RETURN_CODE) - if(HG_RETURN_CODE EQUAL 0 AND HG_OUPUT_RES) - set(MERCURIAL_ID "${HG_OUPUT_RES}") - set(DFT_STRICT "YES") - endif() -elseif(EXISTS "${CMAKE_SOURCE_DIR}/.git") - exec_program("git" "${CMAKE_SOURCE_DIR}" ARGS "rev-parse --short HEAD" OUTPUT_VARIABLE GIT_OUPUT_RES RETURN_VALUE GIT_RETURN_CODE) - if(GIT_RETURN_CODE EQUAL 0 AND GIT_OUPUT_RES) - set(MERCURIAL_ID "${GIT_OUPUT_RES}+") - set(DFT_STRICT "YES") - endif() +# If checking out from version control enable strict compilation flags +if(EXISTS "${CMAKE_SOURCE_DIR}/.hg" OR EXISTS "${CMAKE_SOURCE_DIR}/.git") + set(DFT_STRICT "YES") +else() + set(DFT_STRICT "NO") endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") # Initialize variable diff --git a/common/utils/CMakeLists.txt b/common/utils/CMakeLists.txt --- a/common/utils/CMakeLists.txt +++ b/common/utils/CMakeLists.txt @@ -6,7 +6,11 @@ # Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V. #]] -include_directories(${UUID_INCLUDE_DIR} ${CRYPTO_INCLUDE_DIR}) +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${UUID_INCLUDE_DIR} ${CRYPTO_INCLUDE_DIR}) + +# FindRevision script must run every time to detect the current revision +add_custom_target(mrevision COMMAND ${CMAKE_COMMAND} ARGS -P ${CMAKE_CURRENT_SOURCE_DIR}/FindRevision.cmake + ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/monetdb_hgversion.h) set(MUTILS_OBJECTS mutils.h mutils.c revision.c) set(MCRYPT_OBJECTS mcrypt.h mcrypt.c) @@ -41,4 +45,5 @@ else() set_target_properties(msabaoth PROPERTIES POSITION_INDEPENDENT_CODE ON) endif() +add_dependencies(mutils mrevision) install(FILES matomic.h DESTINATION ${INCLUDEDIR}/monetdb) diff --git a/common/utils/FindRevision.cmake b/common/utils/FindRevision.cmake new file mode 100644 --- /dev/null +++ b/common/utils/FindRevision.cmake @@ -0,0 +1,33 @@ +#[[ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V. +#]] + +if(NOT ${CMAKE_ARGC} EQUAL 6) + message(FATAL_ERROR "Six arguments must be given to this script (called from common/utils/CMakeLists.txt)") +endif() + +# Get the current version control revision +if(EXISTS "${CMAKE_ARGV4}/.hg") + exec_program("hg" "${CMAKE_ARGV4}" ARGS "id -i" OUTPUT_VARIABLE HG_OUPUT_RES RETURN_VALUE HG_RETURN_CODE) + if(HG_RETURN_CODE EQUAL 0 AND HG_OUPUT_RES) + set(MERCURIAL_ID "${HG_OUPUT_RES}") + else() + message(FATAL_ERROR "Failed to find mercurial ID") + endif() +elseif(EXISTS "${CMAKE_ARGV4}/.git") + exec_program("git" "${CMAKE_ARGV4}" ARGS "rev-parse --short HEAD" OUTPUT_VARIABLE GIT_OUPUT_RES RETURN_VALUE GIT_RETURN_CODE) + if(GIT_RETURN_CODE EQUAL 0 AND GIT_OUPUT_RES) + set(MERCURIAL_ID "${GIT_OUPUT_RES}") + else() + message(FATAL_ERROR "Failed to find git ID") + endif() +else() + set(MERCURIAL_ID "Unknown") +endif() + +# Write it to monetdb_hgversion.h file +file(WRITE "${CMAKE_ARGV5}" "#define MERCURIAL_ID \"${MERCURIAL_ID}\"") diff --git a/common/utils/revision.c b/common/utils/revision.c --- a/common/utils/revision.c +++ b/common/utils/revision.c @@ -7,18 +7,11 @@ */ #include "monetdb_config.h" +#include "monetdb_hgversion.h" #include "mutils.h" -static const char revision[] = -#ifdef MERCURIAL_ID - MERCURIAL_ID -#else - "Unknown" -#endif - ; - const char * mercurial_revision(void) { - return revision; + return MERCURIAL_ID; } diff --git a/monetdb_config.h.in b/monetdb_config.h.in --- a/monetdb_config.h.in +++ b/monetdb_config.h.in @@ -240,9 +240,6 @@ /* modifiable single-machine data */ #cmakedefine LOCALSTATEDIR "@LOCALSTATE_DIR@" -/* Mercurial repository version */ -#cmakedefine MERCURIAL_ID "@MERCURIAL_ID@" - /* The used password hash algorithm */ #cmakedefine MONETDB5_PASSWDHASH "@MONETDB5_PASSWDHASH@" _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list