Skip to content

Commit

Permalink
[INFRA] Use CPM
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed Dec 9, 2024
1 parent e0330d9 commit f477f56
Show file tree
Hide file tree
Showing 25 changed files with 287 additions and 3,267 deletions.
77 changes: 77 additions & 0 deletions .cmake-format.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,83 @@ parse:
pargs: 1
kwargs:
CYCLIC_DEPENDING_INCLUDES: '+'
cpmaddpackage:
pargs:
nargs: '*'
flags: []
spelling: CPMAddPackage
kwargs: &cpmaddpackagekwargs
NAME: 1
FORCE: 1
VERSION: 1
GIT_TAG: 1
DOWNLOAD_ONLY: 1
GITHUB_REPOSITORY: 1
GITLAB_REPOSITORY: 1
GIT_REPOSITORY: 1
SVN_REPOSITORY: 1
SVN_REVISION: 1
SOURCE_DIR: 1
DOWNLOAD_COMMAND: 1
FIND_PACKAGE_ARGUMENTS: 1
NO_CACHE: 1
GIT_SHALLOW: 1
URL: 1
URL_HASH: 1
URL_MD5: 1
DOWNLOAD_NAME: 1
DOWNLOAD_NO_EXTRACT: 1
HTTP_USERNAME: 1
HTTP_PASSWORD: 1
EXCLUDE_FROM_ALL: 1
SYSTEM: 1
SOURCE_SUBDIR: 1
QUIET: 1
PATCHES: +
OPTIONS: +
cpmfindpackage:
pargs:
nargs: '*'
flags: []
spelling: CPMFindPackage
kwargs: *cpmaddpackagekwargs
cpmdeclarepackage:
pargs:
nargs: '*'
flags: []
spelling: CPMDeclarePackage
kwargs: *cpmaddpackagekwargs
packageproject:
pargs:
nargs: '*'
flags: []
spelling: packageProject
kwargs:
NAME: 1
VERSION: 1
NAMESPACE: 1
INCLUDE_DIR: 1
INCLUDE_DESTINATION: 1
INCLUDE_HEADER_PATTERN: 1
BINARY_DIR: 1
COMPATIBILITY: 1
VERSION_HEADER: 1
EXPORT_HEADER: 1
DISABLE_VERSION_SUFFIX: 1
CPACK: 1
DEPENDENCIES: +
cpmgetpackage:
pargs: 1
spelling: CPMGetPackage
cpmusepackagelock:
pargs: 1
spelling: CPMUsePackageLock
cpmregisterpackage:
pargs: 1
spelling: CPMRegisterPackage
cpmgetpackageversion:
pargs: 2
spelling: CPMGetPackageVersion
_help_override_spec:
- Override configurations per-command where available
override_spec: {}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
run: |
mkdir build && cd build
cmake ../test/coverage -DCMAKE_BUILD_TYPE=Coverage
make gtest_build yaml-cpp
make gtest_main yaml-cpp
- name: Build tests
working-directory: build
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/ci_cpm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
# SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: CC0-1.0

name: Update CPM

on:
schedule:
- cron: "0 12 * * SAT"
workflow_dispatch:

env:
TZ: Europe/Berlin

concurrency:
group: update-cpm-actions
cancel-in-progress: true

jobs:
update_cpm:
name: Update CPM
runs-on: ubuntu-latest
timeout-minutes: 15
if: github.repository_owner == 'seqan' || github.event_name == 'workflow_dispatch'
steps:
- name: Run update CPM
uses: seqan/actions/update_cpm_package_lock@main
with:
token: ${{ secrets.SEQAN_ACTIONS_PAT }}
gpg_key: ${{ secrets.SEQAN_ACTIONS_GPG_KEY }}
gpg_passphrase: ${{ secrets.SEQAN_ACTIONS_GPG_PASSPHRASE }}
package_lock_file: cmake/package-lock.cmake
2 changes: 1 addition & 1 deletion .github/workflows/ci_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
mkdir build && cd build
cmake ../test/unit -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}"
make gtest_build yaml-cpp
make gtest_main yaml-cpp
- name: Build tests
working-directory: build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
mkdir build && cd build
cmake ../test/${{ matrix.build }} -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}"
make gtest_build yaml-cpp
make gtest_main yaml-cpp
- name: Build tests
working-directory: build
Expand Down
22 changes: 22 additions & 0 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# SPDX-License-Identifier: MIT
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors

set (CPM_DOWNLOAD_VERSION 0.40.2)
set (CPM_HASH_SUM "c8cdc32c03816538ce22781ed72964dc864b2a34a310d3b7104812a5ca2d835d")

if (CPM_SOURCE_CACHE)
set (CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif (DEFINED ENV{CPM_SOURCE_CACHE})
set (CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else ()
set (CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif ()

# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component (CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)

file (DOWNLOAD https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM})

include (${CPM_DOWNLOAD_LOCATION})
13 changes: 13 additions & 0 deletions cmake/cpack_install.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

# Only if creating the source package (`make package_source`):
# Copy dependency include directories into package's staging folder
if (CPACK_SOURCE_INSTALLED_DIRECTORIES)
configure_file ("@CPM_DOWNLOAD_LOCATION@" "${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake" COPYONLY)
if ("@use_ccache_ADDED@" STREQUAL "YES")
configure_file ("@use_ccache_SOURCE_DIR@/ccache/CMakeLists.txt"
"${CMAKE_CURRENT_BINARY_DIR}/test/cmake/sharg_require_ccache.cmake" COPYONLY)
endif ()
endif ()
48 changes: 48 additions & 0 deletions cmake/package-lock.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: CC0-1.0

# CPM Package Lock
# This file should be committed to version control

# URL/GIT_TAG may be annotated with a branch name
# This is needed for https://github.com/seqan/actions/tree/main/update_cpm_package_lock

# The first argument of CPMDeclarePackage can be freely chosen and is used as argument in CPMGetPackage.
# The NAME argument should be package name that would also be used in a find_package call.
# Ideally, both are the same, which might not always be possible: https://github.com/cpm-cmake/CPM.cmake/issues/603
# This is needed to support CPM_USE_LOCAL_PACKAGES

# TDL
set (SHARG_TDL_VERSION 1.0.1)
CPMDeclarePackage (tdl
NAME tdl
VERSION ${SHARG_TDL_VERSION}
GITHUB_REPOSITORY deNBI-cibi/tool_description_lib
SYSTEM TRUE
OPTIONS "INSTALL_TDL OFF" "CMAKE_MESSAGE_LOG_LEVEL WARNING")
# googletest
set (SHARG_GOOGLETEST_VERSION 1.15.2)
CPMDeclarePackage (googletest
NAME GTest
VERSION ${SHARG_GOOGLETEST_VERSION}
GITHUB_REPOSITORY google/googletest
SYSTEM TRUE
OPTIONS "BUILD_GMOCK OFF" "INSTALL_GTEST OFF" "CMAKE_MESSAGE_LOG_LEVEL WARNING")
# doxygen-awesome
set (SHARG_DOXYGEN_AWESOME_VERSION 2.3.4)
CPMDeclarePackage (doxygen_awesome
NAME doxygen_awesome
VERSION ${SHARG_DOXYGEN_AWESOME_VERSION}
GITHUB_REPOSITORY jothepro/doxygen-awesome-css
DOWNLOAD_ONLY TRUE
QUIET YES)
# use_ccache
set (SHARG_USE_CCACHE_VERSION d2a54ef555b6fc2d496a4c9506dbeb7cf899ce37)
CPMDeclarePackage (use_ccache
NAME use_ccache
GIT_TAG ${SHARG_USE_CCACHE_VERSION} # main
GITHUB_REPOSITORY seqan/cmake-scripts
SOURCE_SUBDIR ccache
SYSTEM TRUE
EXCLUDE_FROM_ALL TRUE)
55 changes: 22 additions & 33 deletions cmake/sharg-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -108,31 +108,35 @@ macro (sharg_config_error text)
endif ()
endmacro ()

# ----------------------------------------------------------------------------
# CPM
# ----------------------------------------------------------------------------

# This will be true for git clones and source packages, but not for installed packages.
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/CPM.cmake")
set (SHARG_HAS_CPM TRUE)
else ()
set (SHARG_HAS_CPM FALSE)
endif ()

if (SHARG_HAS_CPM)
set (CPM_INDENT " CMake Package Manager CPM: ")
include ("${CMAKE_CURRENT_LIST_DIR}/CPM.cmake")
CPMUsePackageLock ("${CMAKE_CURRENT_LIST_DIR}/package-lock.cmake")
endif ()

# ----------------------------------------------------------------------------
# Find SHARG include path
# ----------------------------------------------------------------------------

# Note that sharg-config.cmake can be standalone and thus SHARG_CLONE_DIR might be empty.
# * `SHARG_CLONE_DIR` was already found in sharg-config-version.cmake
# * `SHARG_INCLUDE_DIR` was already found in sharg-config-version.cmake
find_path (SHARG_SUBMODULES_DIR
NAMES submodules/tool_description_lib
HINTS "${SHARG_CLONE_DIR}" "${SHARG_INCLUDE_DIR}/sharg")

if (SHARG_INCLUDE_DIR)
sharg_config_print ("SHARG include dir found: ${SHARG_INCLUDE_DIR}")
else ()
sharg_config_error ("SHARG include directory could not be found (SHARG_INCLUDE_DIR: '${SHARG_INCLUDE_DIR}')")
endif ()

# ----------------------------------------------------------------------------
# Detect if we are a clone of repository and if yes auto-add submodules
# ----------------------------------------------------------------------------

if (SHARG_CLONE_DIR)
sharg_config_print ("Detected as running from a repository checkout…")
endif ()

# ----------------------------------------------------------------------------
# Options for CheckCXXSourceCompiles
# ----------------------------------------------------------------------------
Expand Down Expand Up @@ -206,22 +210,13 @@ endif ()
set (SHARG_USE_TDL FALSE)

if (NOT SHARG_NO_TDL)
find_package (TDL QUIET HINTS ${SHARG_HINT_TDL})

if (NOT TDL_FOUND)
if (EXISTS ${SHARG_SUBMODULES_DIR}/submodules/tool_description_lib)
include (FetchContent)
FetchContent_Declare (tdl SOURCE_DIR ${SHARG_SUBMODULES_DIR}/submodules/tool_description_lib)
set (SHARG_LOG_LEVEL ${CMAKE_MESSAGE_LOG_LEVEL})
set (CMAKE_MESSAGE_LOG_LEVEL "ERROR")
option (INSTALL_TDL "Enable installation of TDL." ${INSTALL_SHARG})
FetchContent_MakeAvailable (tdl)
set (CMAKE_MESSAGE_LOG_LEVEL ${SHARG_LOG_LEVEL})
set (TDL_FOUND TRUE)
endif ()
if (NOT SHARG_HAS_CPM)
find_package (tdl QUIET)
else ()
CPMGetPackage (tdl)
endif ()

if (TDL_FOUND)
if (TDL_FOUND OR tdl_ADDED)
sharg_config_print ("Optional dependency: TDL found.")
set (SHARG_USE_TDL TRUE)
list (APPEND SHARG_LIBRARIES tdl::tdl)
Expand Down Expand Up @@ -323,12 +318,6 @@ if (SHARG_FOUND AND NOT TARGET sharg::sharg)
target_link_libraries (sharg_sharg INTERFACE ${SHARG_LIBRARIES})
target_include_directories (sharg_sharg INTERFACE "${SHARG_INCLUDE_DIR}")
add_library (sharg::sharg ALIAS sharg_sharg)

if (SHARG_USE_TDL)
# Include TDL as system header to suppress warnings.
get_target_property (tdl_include_dir tdl::tdl INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories (sharg_sharg SYSTEM INTERFACE ${tdl_include_dir})
endif ()
endif ()

set (CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE})
Expand Down
22 changes: 20 additions & 2 deletions cmake/sharg-package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,30 @@ set (CPACK_PACKAGE_VENDOR "seqan")
# A description of the project, used in places such as the introduction screen of CPack-generated Windows installers.
# set (CPACK_PACKAGE_DESCRIPTION_FILE "") # TODO
set (CPACK_PACKAGE_CHECKSUM "SHA256")
set (CPACK_PACKAGE_ICON "${SHARG_CLONE_DIR}/test/documentation/sharg_logo.png")
set (CPACK_PACKAGE_ICON "${SHARG_CLONE_DIR}/test/documentation/sharg_logo.svg")
set (CPACK_RESOURCE_FILE_LICENSE "${SHARG_CLONE_DIR}/LICENSE.md")
set (CPACK_RESOURCE_FILE_README "${SHARG_CLONE_DIR}/README.md")

# Already being called on source package, i.e. CPM is already downloaded.
if (NOT CPM_DOWNLOAD_LOCATION)
set (CPM_DOWNLOAD_LOCATION "${SHARG_CLONE_DIR}/cmake/CPM.cmake")
else ()
CPMGetPackage (use_ccache)
endif ()

configure_file ("${SHARG_CLONE_DIR}/cmake/cpack_install.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cpack_install.cmake"
@ONLY)
set (CPACK_INSTALL_SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/cpack_install.cmake")

# Source Package
set (CPACK_SOURCE_GENERATOR "TXZ")
set (CPACK_SOURCE_IGNORE_FILES "\\\\.git($|/)")
# Next 2 lines would overwrite copy in cpack_install.cmake
list (APPEND CPACK_SOURCE_IGNORE_FILES "/cmake/CPM.cmake")
list (APPEND CPACK_SOURCE_IGNORE_FILES "/test/cmake/sharg_require_ccache.cmake")
list (APPEND CPACK_SOURCE_IGNORE_FILES "/\.git($|/)")
list (APPEND CPACK_SOURCE_IGNORE_FILES "/\.github/")
list (APPEND CPACK_SOURCE_IGNORE_FILES "/\.vscode/")
list (APPEND CPACK_SOURCE_IGNORE_FILES "/build/")
list (APPEND CPACK_SOURCE_IGNORE_FILES "/submodules/")

include (CPack)
28 changes: 5 additions & 23 deletions test/cmake/sharg_require_ccache.cmake
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
# SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
# SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.15)

# Uses `ccache` to cache build results.
#
# See also
# * https://ccache.dev/
# * https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_LAUNCHER.html
macro (sharg_require_ccache)
find_program (CCACHE_PROGRAM ccache)
find_package_message (CCACHE_PROGRAM_PRE "Finding program ccache" "[${CCACHE_PROGRAM}]")

if (NOT CCACHE_PROGRAM)
find_package_message (CCACHE_PROGRAM "Finding program ccache - Failed" "[${CCACHE_PROGRAM}]")
else ()
find_package_message (CCACHE_PROGRAM "Finding program ccache - Success" "[${CCACHE_PROGRAM}]")
list (PREPEND CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
# use ccache in external cmake projects
list (APPEND SHARG_EXTERNAL_PROJECT_CMAKE_ARGS "-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}")
endif ()
unset (CCACHE_PROGRAM)
endmacro ()
# This file's only purpose is to be replaced with the content of the use_ccache CMakeLists.txt file
# when creating the source package.
CPMGetPackage (use_ccache)
Loading

0 comments on commit f477f56

Please sign in to comment.