#must come after all cpack settings!
include(CPack)
+set(SOURCE_IS_GIT_REPOSITORY OFF)
+if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
+ set(SOURCE_IS_GIT_REPOSITORY ON)
+endif()
+
########################################################################
# Check and warn if cache generated on a different host is being reused
########################################################################
option(GMX_GPU "Enable GPU acceleration" ON)
option(GMX_OPENMP "Enable OpenMP-based multithreading" ON)
-option(USE_VERSION_H "Generate development version string/information" ON)
-mark_as_advanced(USE_VERSION_H)
+option(GMX_GIT_VERSION_INFO "Generate git version information" ${SOURCE_IS_GIT_REPOSITORY})
+mark_as_advanced(GMX_GIT_VERSION_INFO)
option(GMX_DEFAULT_SUFFIX "Use default suffixes for GROMACS binaries and libs (_d for double, _mpi for MPI; rerun cmake after changing to see relevant options)" ON)
endif()
# only bother with finding git and using version.h if the source is a git repo
-if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
- if(USE_VERSION_H)
- # We need at least git v1.5.3 be able to parse git's date output. If not
- # found or the version is too small, we can't generate version information.
- find_package(Git)
-
- # Find out the git version
- if(GIT_FOUND AND NOT GIT_VERSION)
- execute_process(COMMAND ${GIT_EXECUTABLE} "--version"
- OUTPUT_VARIABLE _exec_out
- OUTPUT_STRIP_TRAILING_WHITESPACE)
- string(REGEX REPLACE "git version (.*)" "\\1" GIT_VERSION ${_exec_out})
- set(GIT_VERSION ${GIT_VERSION} CACHE STRING "Git version")
- mark_as_advanced(GIT_VERSION)
- endif()
-
- if(NOT GIT_FOUND OR GIT_VERSION VERSION_LESS "1.5.3")
- message("No compatible git version found, won't be able to generate proper development version information.")
- set(USE_VERSION_H OFF)
- endif()
+if(GMX_GIT_VERSION_INFO)
+ if (NOT SOURCE_IS_GIT_REPOSITORY)
+ message(FATAL_ERROR
+ "Cannot generate git version information from source tree not under git. "
+ "Set GMX_GIT_VERSION_INFO=OFF to proceed.")
+ endif ()
+ # We need at least git v1.5.3 be able to parse git's date output. If not
+ # found or the version is too small, we can't generate version information.
+ find_package(Git)
+
+ # Find out the git version
+ if(GIT_FOUND AND NOT GIT_VERSION)
+ execute_process(COMMAND ${GIT_EXECUTABLE} "--version"
+ OUTPUT_VARIABLE _exec_out
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ string(REGEX REPLACE "git version (.*)" "\\1" GIT_VERSION ${_exec_out})
+ set(GIT_VERSION ${GIT_VERSION} CACHE STRING "Git version")
+ mark_as_advanced(GIT_VERSION)
+ endif()
+
+ if(NOT GIT_FOUND OR GIT_VERSION VERSION_LESS "1.5.3")
+ message(FATAL_ERROR
+ "No compatible git version found (>= 1.5.3 required). "
+ "Won't be able to generate development version information. "
+ "Set GMX_GIT_VERSION_INFO=OFF to proceed.")
endif()
-else()
- set(USE_VERSION_H OFF)
endif()
option(GMX_INTERNAL_BOOST "Use minimal internal version of boost" OFF)
# The following variables have to be previously defined:
# GIT_EXECUTABLE - path to git binary
# GIT_VERSION - git version (if not defined it's assumed that >=1.5.3)
-# PROJECT_VERSION - hard-coded version string, should have the following structure:
-# VERSION[-dev-SUFFIX] where the VERSION can have any form and the suffix
-# is optional but should start with -dev
+# PROJECT_VERSION - hard-coded version string (generated info is appended)
# PROJECT_SOURCE_DIR - top level source directory (which has to be in git)
-# VERSION_C_CMAKEIN - path to the version.c.cmakein file
-# VERSION_C_OUT - path to the version.c output file
+# VERSION_C_CMAKEIN - path to the gitversion.c.cmakein file
+# VERSION_C_OUT - path to the gitversion.c output file
#
# Output:
-# i) Script mode: version.c configured from the input version.c.cmakein using
-# the variables listed below.
+# i) Script mode: gitversion.c configured from the input gitversion.c.cmakein
+# using the variables listed below.
# ii) Cache variable mode: the varables below are set in cache.
#
# GMX_PROJECT_VERSION_STR - version string
if("${PROJECT_VERSION}" STREQUAL "")
message(FATAL_ERROR "PROJECT_VERSION undefined!")
endif()
-set(VER ${PROJECT_VERSION})
# if we're generating variables for cache unset the variables
if(GEN_VERSION_INFO_INTERNAL)
endif()
endif()
- # compile final version string, if there is already a -dev suffix in VER
- # remove everything after this and replace it with the generated suffix
- string(REGEX REPLACE "(.*)-dev.*" "\\1" VER "${VER}")
- set(GMX_PROJECT_VERSION_STR "${VER}-dev-${VERSION_STR_SUFFIX}")
+ # compile final version string
+ set(GMX_PROJECT_VERSION_STR "${PROJECT_VERSION}-${VERSION_STR_SUFFIX}")
else()
- # the version has to be defined - if not we're not using version.h/.c and set
- # the GIT related information to "unknown"
+ # the version has to be defined - if not we're not using gitversion.h/.c;
+ # set the GIT related information to "unknown"
message(WARNING "Source tree seems to be a repository, but no compatible git is available, using hard-coded version string")
set(GMX_PROJECT_VERSION_STR "${PROJECT_VERSION}")
set(GMX_GIT_HEAD_HASH "unknown")
endif()
# if we're generating cache variables set these
-# otherwise it's assumed that it's called in script mode to generate version.c
+# otherwise it's assumed that it's called in script mode to generate gitversion.c
if(GEN_VERSION_INFO_INTERNAL)
set(GMX_PROJECT_VERSION_STR ${GMX_PROJECT_VERSION_STR}
CACHE STRING "Gromacs version string" FORCE)
if("${VERSION_C_OUT}" STREQUAL "")
message(FATAL_ERROR "Missing input parameter VERSION_C_OUT!")
endif()
- # generate version.c
+ # generate gitversion.c
configure_file(${VERSION_C_CMAKEIN} ${VERSION_C_OUT})
endif()
/* Version number of package (translate from cmake to autoconf macro name) */
#define VERSION "@PROJECT_VERSION@"
-/* Use the version string from generated version.h */
-#cmakedefine USE_VERSION_H
+/* Use extra version information generated with git */
+#cmakedefine GMX_GIT_VERSION_INFO
/* Default location of data files */
#define GMXLIBDIR "@GMXLIBDIR@"
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/version.h
DESTINATION ${INCL_INSTALL_DIR}/gromacs
COMPONENT development)
-# add target that generates version.c every time a make is run
-# only do this if we generate the version
-if (USE_VERSION_H)
+
+# Add target that generates gitversion.c every time make is run
+# if git version info is requested
+# This code is here instead of utility/CMakeLists.txt because CMake
+# ignores set_source_file_properties from subdirectories.
+if (GMX_GIT_VERSION_INFO)
+ set(GENERATED_VERSION_FILE ${CMAKE_CURRENT_BINARY_DIR}/utility/gitversion.c)
add_custom_target(gmx_version ALL
- COMMAND ${CMAKE_COMMAND}
+ COMMAND ${CMAKE_COMMAND}
-D GIT_EXECUTABLE="${GIT_EXECUTABLE}"
-D GIT_VERSION="${GIT_VERSION}"
-D PROJECT_VERSION="${PROJECT_VERSION}"
-D PROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR}"
- -D VERSION_C_CMAKEIN="${CMAKE_CURRENT_SOURCE_DIR}/version.c.cmakein"
- -D VERSION_C_OUT="${CMAKE_CURRENT_BINARY_DIR}/version.c"
- -P ${CMAKE_SOURCE_DIR}/cmake/gmxGenerateVersionInfo.cmake
- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src/gmxlib
- DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/version.c.cmakein
- COMMENT "Generating version information")
- list(APPEND LIBGROMACS_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/version.c) # auto-generated
- set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/version.c
+ -D VERSION_C_CMAKEIN="${CMAKE_CURRENT_SOURCE_DIR}/utility/gitversion.c.cmakein"
+ -D VERSION_C_OUT=${GENERATED_VERSION_FILE}
+ -P ${CMAKE_SOURCE_DIR}/cmake/gmxGenerateVersionInfo.cmake
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/utility/gitversion.c.cmakein
+ COMMENT "Generating git version information")
+ set_source_files_properties(${GENERATED_VERSION_FILE}
PROPERTIES GENERATED true)
-endif (USE_VERSION_H)
+ list(APPEND LIBGROMACS_SOURCES ${GENERATED_VERSION_FILE})
+endif()
# apply gcc 4.4.x bug workaround
if(GMX_USE_GCC44_BUG_WORKAROUND)
endif()
add_library(libgromacs ${LIBGROMACS_SOURCES})
-if (USE_VERSION_H)
+if (GMX_GIT_VERSION_INFO)
add_dependencies(libgromacs gmx_version)
-endif (USE_VERSION_H)
+endif ()
target_link_libraries(libgromacs ${GMX_GPU_LIBRARIES}
${GMX_EXTRA_LIBRARIES} ${FFT_LIBRARIES} ${XML_LIBRARIES}
fflush(fp);
}
-#ifdef USE_VERSION_H
+#ifdef GMX_GIT_VERSION_INFO
/* Version information generated at compile time. */
-#include "version.h"
+#include "gromacs/utility/gitversion.h"
#else
/* Fall back to statically defined version. */
static const char _gmx_ver_string[]="VERSION " VERSION;
void gmx_print_version_info(FILE *fp)
{
fprintf(fp, "Version: %s\n", _gmx_ver_string);
-#ifdef USE_VERSION_H
+#ifdef GMX_GIT_VERSION_INFO
fprintf(fp, "GIT SHA1 hash: %s\n", _gmx_full_git_hash);
/* Only print out the branch information if present.
* The generating script checks whether the branch point actually
gmx_header_config_gen.h
+gitversion.c
-#include "gromacs/gmxlib/version.h"
+#include "gromacs/utility/gitversion.h"
+
const char _gmx_ver_string[] = "VERSION @GMX_PROJECT_VERSION_STR@";
const char _gmx_full_git_hash[] = "@GMX_GIT_HEAD_HASH@";
const char _gmx_central_base_hash[] = "@GMX_GIT_REMOTE_HASH@";
*
* For more info, check our website at http://www.gromacs.org
*/
-#ifndef GMX_GMXLIB_VERSION_H
-#define GMX_GMXLIB_VERSION_H
+#ifndef GMX_UTILITY_GITVERSION_H
+#define GMX_UTILITY_GITVERSION_H
extern const char _gmx_ver_string[];
extern const char _gmx_full_git_hash[];
extern const char _gmx_central_base_hash[];
-#endif /* GMX_GMXLIB_VERSION_H */
+#endif