Skip to content

Commit

Permalink
CMake: set versioning variables before project()
Browse files Browse the repository at this point in the history
  • Loading branch information
mic84 committed Feb 29, 2020
1 parent f0467fd commit 645e5cc
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 42 deletions.
77 changes: 49 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,54 @@
cmake_minimum_required(VERSION 3.14)
project(AMReX)
enable_language(C) # needed for find_package(MPI REQUIRED "C")
enable_language(CXX)
enable_language(Fortran)

########################################################################
#
# Set variables for AMReX versioning
#
########################################################################
find_package (Git QUIET)

set( _tmp "" )

if ( EXISTS ${CMAKE_SOURCE_DIR}/.git AND ${GIT_FOUND} )
execute_process ( COMMAND git describe --abbrev=12 --dirty --always --tags
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE _tmp )
string( STRIP ${_tmp} _tmp )
else ()
# Grep first line from file CHANGES if cannot find version from Git
file(STRINGS ${CMAKE_SOURCE_DIR}/CHANGES ALL_VERSIONS REGEX "#")
list(GET ALL_VERSIONS 0 _tmp)
string(REPLACE "#" "" _tmp "${_tmp}")
string(STRIP "${_tmp}" _tmp )
set(_tmp "${_tmp}.0")
endif ()

set( AMREX_GIT_VERSION "${_tmp}" CACHE INTERNAL "" )
unset(_tmp)

# Package version is a modified form of AMREX_GIT_VERSION
if (AMREX_GIT_VERSION)
string(FIND "${AMREX_GIT_VERSION}" "-" _idx REVERSE)
string(SUBSTRING "${AMREX_GIT_VERSION}" 0 "${_idx}" _pkg_version )
string(FIND "${_pkg_version}" "-" _idx REVERSE)
string(SUBSTRING "${_pkg_version}" 0 "${_idx}" _pkg_version )
string(REPLACE "-" "." _pkg_version "${_pkg_version}")
endif ()

set( AMREX_PKG_VERSION "${_pkg_version}" CACHE INTERNAL "" )
unset(_pkg_version)

########################################################################
#
# AMReX project
#
########################################################################
project( AMReX
DESCRIPTION "A software framework for massively parallel, block-structured adaptive mesh refinement (AMR) applications"
VERSION ${AMREX_PKG_VERSION}
HOMEPAGE_URL "https://amrex-codes.github.io/amrex/"
LANGUAGES C CXX Fortran
)
#
# Load required modules
#
Expand Down Expand Up @@ -38,30 +83,6 @@ endif ()
#
set_default_config_flags ()

#
# Set variable for AMReX versioning
#
find_package (Git QUIET)

set ( TMP "" )

if ( EXISTS ${CMAKE_SOURCE_DIR}/.git AND ${GIT_FOUND} )
execute_process ( COMMAND git describe --abbrev=12 --dirty --always --tags
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE TMP )
string ( STRIP ${TMP} TMP )
else ()
# Grep first line from file CHANGES if AMREX_GIT_VERSION is not
# provided
file(STRINGS ${PROJECT_SOURCE_DIR}/CHANGES ALL_VERSIONS REGEX "#")
list(GET ALL_VERSIONS 0 TMP)
string(REPLACE "#" "" TMP "${TMP}")
string (STRIP "${TMP}" TMP )
set (TMP "${TMP}.0")
endif ()

set ( AMREX_GIT_VERSION "${TMP}" CACHE INTERNAL "" )
unset (TMP)

#
# Source files for all binaries and libraries found under src
Expand Down
17 changes: 3 additions & 14 deletions Tools/CMake/AMReXInstallHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,9 @@ function (install_amrex)
${PROJECT_BINARY_DIR}/export/AMReXConfig.cmake
INSTALL_DESTINATION bin/cmake/AMReX )


# Install Version file
# Package version is a modified form of AMREX_GIT_VERSION
if (AMREX_GIT_VERSION)
string(FIND "${AMREX_GIT_VERSION}" "-" _idx REVERSE)
string(SUBSTRING "${AMREX_GIT_VERSION}" 0 "${_idx}" _pkg_version )
string(FIND "${_pkg_version}" "-" _idx REVERSE)
string(SUBSTRING "${_pkg_version}" 0 "${_idx}" _pkg_version )
string(REPLACE "-" "." _pkg_version "${_pkg_version}")
endif ()

write_basic_package_version_file( ${PROJECT_BINARY_DIR}/export/AMReXConfigVersion.cmake
VERSION ${_pkg_version}
COMPATIBILITY AnyNewerVersion )
write_basic_package_version_file(
${PROJECT_BINARY_DIR}/export/AMReXConfigVersion.cmake
COMPATIBILITY AnyNewerVersion )

install( FILES
${PROJECT_BINARY_DIR}/export/AMReXConfig.cmake
Expand Down

0 comments on commit 645e5cc

Please sign in to comment.