Commit 0861254b authored by Sebastian Müller's avatar Sebastian Müller 🐈
Browse files

git subrepo clone (merge) --branch=v1.7 --force...

git subrepo clone (merge) --branch=v1.7 --force https://git.ufz.de/chs/cmake-fortran-scripts.git cmake

subrepo:
  subdir:   "cmake"
  merged:   "b4ffa36"
upstream:
  origin:   "https://git.ufz.de/chs/cmake-fortran-scripts.git"
  branch:   "v1.7"
  commit:   "b4ffa36"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "2f68596"
parent 52c7d6db
Pipeline #98877 passed with stages
in 7 minutes and 23 seconds
......@@ -5,8 +5,8 @@
;
[subrepo]
remote = https://git.ufz.de/chs/cmake-fortran-scripts.git
branch = v1.6
commit = 92ca685ef4c3bf640fe116ffb4ab1fe348ef2376
parent = bc63473aab83485bacee865eebcd0e4caa498c11
branch = v1.7
commit = b4ffa3641b3d1ab733d98500dc2364a91eda15e5
parent = 52c7d6db1139f546f9dfae67ec338213a9e10bfc
method = merge
cmdver = 0.4.3
......@@ -64,9 +64,9 @@ To specify a particular NetCDF library, use
or set environment variable `NetCDF_ROOT=/path/to/netcdff`.
### `version.cmake`
Provides a function to read version and date from a given files `version.txt` and `version-date.txt`.
Provides a function to read version and date from given files `version.txt` and (optional) `version_date.txt`.
Can be included and used with (`PROJECT_VER_DEV` will hold the develop version string):
```cmake
......@@ -74,7 +74,13 @@ include(version)
get_version(PROJECT_VER PROJECT_VER_DEV PROJECT_DATE)
```
### `CPM.cmake` (v0.35.0)
If a development version was found (e.g. `1.0.0-dev0`), it will try to determine the latest git commit short hash and add it (e.g. `1.0.0-dev0+02d7e12`).
If there is no `version_date.txt` file or a development version was found, the script will try to determine the latest git commit date or use the current date.
`PROJECT_VER` will hold the simple version to be used with cmakes `project` command (e.g. `1.0.0`).
A prefixed `v` in the version will be ignored.
### `CPM.cmake` (v0.35.1)
CPM.cmake is a CMake script that adds dependency management capabilities to CMake.
It's built as a thin wrapper around CMake's [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html)
module that adds version control, caching, a simple API [and more](#comparison-to-pure-fetchcontent--externalproject).
......@@ -84,14 +90,11 @@ Copied from: https://github.com/cpm-cmake/CPM.cmake
Can be used like:
```cmake
include(CPM)
CPMAddPackage(
NAME forces
GIT_REPOSITORY https://git.ufz.de/chs/forces.git
GIT_TAG v0.1.0
)
CPMAddPackage("https://git.ufz.de/chs/forces.git@0.3.2")
target_link_libraries(<project> PUBLIC forces)
```
## Cmake Cache Files
Cache files provide templates for specific cmake setups.
......
......@@ -28,7 +28,7 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
set(CURRENT_CPM_VERSION 0.35.0)
set(CURRENT_CPM_VERSION 0.35.1)
if(CPM_DIRECTORY)
if(NOT CPM_DIRECTORY STREQUAL CMAKE_CURRENT_LIST_DIR)
......@@ -433,6 +433,47 @@ function(cpm_check_git_working_dir_is_clean repoPath gitTag isClean)
endfunction()
# method to overwrite internal FetchContent properties, to allow using CPM.cmake to overload
# FetchContent calls. As these are internal cmake properties, this method should be used carefully
# and may need modification in future CMake versions. Source:
# https://github.com/Kitware/CMake/blob/dc3d0b5a0a7d26d43d6cfeb511e224533b5d188f/Modules/FetchContent.cmake#L1152
function(cpm_override_fetchcontent contentName)
cmake_parse_arguments(PARSE_ARGV 1 arg "" "SOURCE_DIR;BINARY_DIR" "")
if(NOT "${arg_UNPARSED_ARGUMENTS}" STREQUAL "")
message(FATAL_ERROR "Unsupported arguments: ${arg_UNPARSED_ARGUMENTS}")
endif()
string(TOLOWER ${contentName} contentNameLower)
set(prefix "_FetchContent_${contentNameLower}")
set(propertyName "${prefix}_sourceDir")
define_property(
GLOBAL
PROPERTY ${propertyName}
BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()"
FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}"
)
set_property(GLOBAL PROPERTY ${propertyName} "${arg_SOURCE_DIR}")
set(propertyName "${prefix}_binaryDir")
define_property(
GLOBAL
PROPERTY ${propertyName}
BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()"
FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}"
)
set_property(GLOBAL PROPERTY ${propertyName} "${arg_BINARY_DIR}")
set(propertyName "${prefix}_populated")
define_property(
GLOBAL
PROPERTY ${propertyName}
BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()"
FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}"
)
set_property(GLOBAL PROPERTY ${propertyName} TRUE)
endfunction()
# Download and add a package from source
function(CPMAddPackage)
list(LENGTH ARGN argnLength)
......@@ -644,8 +685,15 @@ function(CPMAddPackage)
"${${CPM_ARGS_NAME}_SOURCE_DIR}/${CPM_ARGS_SOURCE_SUBDIR}" "${${CPM_ARGS_NAME}_BINARY_DIR}"
"${CPM_ARGS_EXCLUDE_FROM_ALL}" "${CPM_ARGS_OPTIONS}"
)
set(CPM_SKIP_FETCH TRUE)
set(PACKAGE_INFO "${PACKAGE_INFO} at ${download_directory}")
# As the source dir is already cached/populated, we override the call to FetchContent.
set(CPM_SKIP_FETCH TRUE)
cpm_override_fetchcontent(
"${lower_case_name}" SOURCE_DIR "${${CPM_ARGS_NAME}_SOURCE_DIR}/${CPM_ARGS_SOURCE_SUBDIR}"
BINARY_DIR "${${CPM_ARGS_NAME}_BINARY_DIR}"
)
else()
# Enable shallow clone when GIT_TAG is not a commit hash. Our guess may not be accurate, but
# it should guarantee no commit hash get mis-detected.
......
......@@ -42,18 +42,54 @@ function(get_version ver_short ver_full ver_date)
# create version x.y.z
set(ver ${ver_major}.${ver_minor}.${ver_patch})
# check date file (if not a development version)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/version_date.txt" AND (NOT (${ver_pre} MATCHES "^dev.*")))
# whether it is a development version (e.g.: 1.1.0-dev0)
set(is_dev_ver (${ver_pre} MATCHES "^dev.*"))
# use git to get commit SHA and commit date
find_package(Git QUIET)
# set date, check date file (if not a development version)
string(TIMESTAMP date "%Y-%m-%d") # current date
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/version_date.txt" AND (NOT is_dev_ver))
file(STRINGS "version_date.txt" date LIMIT_COUNT 1)
else()
string(TIMESTAMP date "%Y-%m-%d") # current date
if(Git_FOUND)
execute_process(
COMMAND "${GIT_EXECUTABLE}" log -1 --format=%cd --date=format:%Y-%m-%d
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE res
OUTPUT_VARIABLE out
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(res EQUAL 0)
set(date "${out}")
endif()
endif()
endif()
# add commit SHA to development version
set(ver_dev "${ver_file}")
if(is_dev_ver)
if(Git_FOUND)
execute_process(
COMMAND "${GIT_EXECUTABLE}" log -1 --format=%h
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE res
OUTPUT_VARIABLE out
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(res EQUAL 0)
set(ver_dev "${ver_file}+${out}")
endif()
endif()
message(STATUS "use DEV-VERSION: ${ver_dev}")
endif()
message(STATUS "use VERSION: ${ver} (from ${ver_file})")
message(STATUS "use DATE: ${date}")
message(STATUS "use VERSION : ${ver} (from ${ver_file})")
message(STATUS "use DATE : ${date}")
# set given variables in parent scope
set(${ver_date} ${date} PARENT_SCOPE)
set(${ver_full} ${ver_file} PARENT_SCOPE)
set(${ver_full} ${ver_dev} PARENT_SCOPE)
set(${ver_short} ${ver} PARENT_SCOPE)
endfunction()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment