-# Add target that generates baseversion-gen.c every time make is run
-# if git version info is requested, or create it statically.
-# This code is here instead of utility/CMakeLists.txt because CMake
-# ignores set_source_file_properties from subdirectories.
-set(GENERATED_VERSION_FILE
- ${CMAKE_CURRENT_BINARY_DIR}/utility/baseversion-gen.c)
-set(GENERATED_VERSION_FILE_SOURCE
- ${CMAKE_CURRENT_SOURCE_DIR}/utility/baseversion-gen.c.cmakein)
-if (GMX_GIT_VERSION_INFO)
- add_custom_target(gmx-version ALL
- COMMAND ${CMAKE_COMMAND}
- -D GIT_EXECUTABLE="${GIT_EXECUTABLE}"
- -D PROJECT_VERSION="${PROJECT_VERSION}"
- -D PROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR}"
- -D VERSION_CMAKEIN=${GENERATED_VERSION_FILE_SOURCE}
- -D VERSION_OUT=${GENERATED_VERSION_FILE}
- -P ${CMAKE_SOURCE_DIR}/cmake/gmxGenerateVersionInfo.cmake
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
- DEPENDS ${GENERATED_VERSION_FILE_SOURCE}
- COMMENT "Generating git version information")
- set_source_files_properties(${GENERATED_VERSION_FILE}
- PROPERTIES GENERATED true)
-else()
- set(GMX_PROJECT_VERSION_STR ${PROJECT_VERSION})
- configure_file(${GENERATED_VERSION_FILE_SOURCE} ${GENERATED_VERSION_FILE})
-endif()
+# This code is here instead of utility/CMakeLists.txt, because CMake
+# custom commands and source file properties can only be set in the directory
+# that contains the target that uses them.
+# TODO: Generate a header instead that can be included from baseversion.c.
+# That probably simplifies things somewhat.
+set(GENERATED_VERSION_FILE utility/baseversion-gen.c)
+gmx_configure_version_file(
+ utility/baseversion-gen.c.cmakein ${GENERATED_VERSION_FILE}
+ REMOTE_HASH SOURCE_FILE)