From 2158f68bdb656949148af1769e7927a24a70a0df Mon Sep 17 00:00:00 2001 From: Enrico Seiler Date: Mon, 4 Nov 2024 16:31:15 +0100 Subject: [PATCH] [INFRA] install target and cpack --- .github/workflows/ci_install.yml | 69 ++++++++++++++++++++++++++++++++ .github/workflows/ci_lint.yml | 11 ++++- CMakeLists.txt | 67 +++++++++---------------------- cmake/cpack_install.cmake.in | 8 ++++ cmake/package-lock.cmake | 4 +- cmake/package.cmake | 50 +++++++++++++++++++++++ src/CMakeLists.txt | 3 ++ 7 files changed, 162 insertions(+), 50 deletions(-) create mode 100644 .github/workflows/ci_install.yml create mode 100644 cmake/cpack_install.cmake.in create mode 100644 cmake/package.cmake diff --git a/.github/workflows/ci_install.yml b/.github/workflows/ci_install.yml new file mode 100644 index 0000000..fb8ea79 --- /dev/null +++ b/.github/workflows/ci_install.yml @@ -0,0 +1,69 @@ +# 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: Install + +on: + push: + branches: + - 'main' + pull_request: + types: + - unlabeled + workflow_dispatch: + +concurrency: + group: install-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.event_name != 'push' }} + +env: + TZ: Europe/Berlin + +defaults: + run: + shell: bash -Eexuo pipefail {0} + +jobs: + build: + runs-on: ubuntu-latest + name: ${{ matrix.compiler }} + if: github.repository_owner == 'seqan' || github.event_name == 'workflow_dispatch' || github.event.label.name == 'lint' + strategy: + fail-fast: false + matrix: + compiler: ["clang-18", "gcc-14"] + container: + image: ghcr.io/seqan/${{ matrix.compiler }} + volumes: + - /home/runner:/home/runner + options: --privileged + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Create source package + run: | + mkdir package && cd package + cmake .. -DCMAKE_BUILD_TYPE=Release -Dneedle_PACKAGE=ON -Dneedle_TEST=OFF + make package_source + mkdir ../unpacked + tar xf needle-*.tar.xz -C ../unpacked --strip-components=1 + + - name: Install from source package + run: | + mkdir build && cd build + unshare -r -n cmake ../unpacked -DCMAKE_INSTALL_PREFIX=$(pwd)/install -Dneedle_TEST=OFF + make install + + - name: Run tests + working-directory: build + run: ./install/bin/needle --help + + - name: Upload source package + uses: actions/upload-artifact@v4 + with: + name: source-package + path: package/needle-*.tar.xz + retention-days: 1 + diff --git a/.github/workflows/ci_lint.yml b/.github/workflows/ci_lint.yml index 457670d..e1ef77e 100644 --- a/.github/workflows/ci_lint.yml +++ b/.github/workflows/ci_lint.yml @@ -43,12 +43,21 @@ jobs: steps: - name: "Cancel Coverage" run: echo "Cancelling Coverage" + cancel_install: + name: Cancel running Workflows + concurrency: + group: install-${{ github.event.pull_request.number }} + cancel-in-progress: true + runs-on: ubuntu-latest + steps: + - name: "Cancel Install" + run: echo "Cancelling Install" lint: name: Lint concurrency: group: lint-${{ github.event.pull_request.number }} cancel-in-progress: true - needs: [cancel_linux, cancel_macos, cancel_coverage] + needs: [cancel_linux, cancel_macos, cancel_coverage, cancel_install] runs-on: ubuntu-latest timeout-minutes: 15 steps: diff --git a/CMakeLists.txt b/CMakeLists.txt index c125d4f..025244b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,23 @@ list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") # Specify the directories where to store the built archives, libraries and executables. include (output_directories) +# An option to disable configuring and building the tests. Tests are enabled by default. +# If your project-name (line 8 of this file) is `app-template`, the option will be `app-template_TEST`. +# It can be used when calling CMake: `cmake .. -Dapp-template_TEST=OFF`. +# It is good practice to allow disabling tests. If another project includes your application, +# it might not want to build your tests. +option (${PROJECT_NAME}_TEST "Enable testing for ${PROJECT_NAME}." ON) +option (${PROJECT_NAME}_DOCS "Enable documentation for ${PROJECT_NAME}." OFF) +option (${PROJECT_NAME}_PACKAGE "Enable packaging for ${PROJECT_NAME}." OFF) + +if (${PROJECT_NAME}_PACKAGE) + set (CPM_SOURCE_CACHE "${CMAKE_CURRENT_BINARY_DIR}/vendor") + set (CPM_USE_LOCAL_PACKAGES OFF) + include (package) +elseif (EXISTS "${CMAKE_CURRENT_LIST_DIR}/vendor") + set (CPM_SOURCE_CACHE "${CMAKE_CURRENT_LIST_DIR}/vendor") +endif () + # Add packages. # We use CPM for package management: https://github.com/cpm-cmake/CPM.cmake # The added packages (e.g., hibf, sharg, seqan3) are defined in the `cmake/package-lock.cmake` file. @@ -31,55 +48,11 @@ CPMGetPackage (robin-hood) # Add the application. This will include `src/CMakeLists.txt`. add_subdirectory (src) -# An option to disable configuring and building the tests. Tests are enabled by default. -# If your project-name (line 8 of this file) is `app-template`, the option will be `app-template_TEST`. -# It can be used when calling CMake: `cmake .. -Dapp-template_TEST=OFF`. -# It is good practice to allow disabling tests. If another project includes your application, -# it might not want to build your tests. -option (${PROJECT_NAME}_TEST "Enable testing for ${PROJECT_NAME}." ON) - if (${PROJECT_NAME}_TEST) # Add the tests. This will include `test/CMakeLists.txt`. add_subdirectory (test EXCLUDE_FROM_ALL) endif () -# add_subdirectory (doc EXCLUDE_FROM_ALL) - -## PACKAGE -# Change version in this file: project (needle VERSION x.x.x) -# Change version in src/main.cpp: parser.info.version = "x.x.x"; -# To package, create a clean directory: -# -# mkdir needle-package -# cd needle-package -# git clone https://github.com/seqan/needle -# cd needle -# # git checkout VERSION # optional: Checkout a tag if it exists. -# git submodule update --init -# cd lib/seqan3 -# git submodule update --init -# cd ../../../ -# mkdir package -# cd package -# cmake ../needle -# cmake --build . --target package_source -# -# Will create needle-[VERSION]-Source.tar.xz{,.sha256}. -# We do git submodule update --init instead of a recursive clone, because we do not want to package the recursive -# submodules, but only what we need. The script handles all submodules at the time of writing, but newer submodules -# might be missing. -# This should be done in a clean directory, because everything in the needle checkout will be packaged, i.e., also -# local build directories if they exist. - -# set (CPACK_GENERATOR "TXZ") - -# set (CPACK_PACKAGE_VERSION "${needle_VERSION}") -# set (CPACK_PACKAGE_VENDOR "seqan") -# set (CPACK_PACKAGE_CHECKSUM "SHA256") -# set (CPACK_RESOURCE_FILE_LICENSE "${needle_SOURCE_DIR}/LICENSE.md") -# set (CPACK_RESOURCE_FILE_README "${needle_SOURCE_DIR}/README.md") - -# set (CPACK_SOURCE_GENERATOR "TXZ") -# set (CPACK_SOURCE_IGNORE_FILES "\\\\.git($|/)") - -# include (CPack) +if (${PROJECT_NAME}_DOCS) + add_subdirectory (doc EXCLUDE_FROM_ALL) +endif () diff --git a/cmake/cpack_install.cmake.in b/cmake/cpack_install.cmake.in new file mode 100644 index 0000000..c05544c --- /dev/null +++ b/cmake/cpack_install.cmake.in @@ -0,0 +1,8 @@ +# 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`). +if (CPACK_SOURCE_INSTALLED_DIRECTORIES) + file (COPY "@CPM_SOURCE_CACHE@" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") +endif () diff --git a/cmake/package-lock.cmake b/cmake/package-lock.cmake index ebd0ee8..104851a 100644 --- a/cmake/package-lock.cmake +++ b/cmake/package-lock.cmake @@ -6,7 +6,7 @@ # This file should be committed to version control # seqan3 -set (NEEDLE_SEQAN3_VERSION d4a7c88fde0311e12e98e7822da772b99c887cb5) +set (NEEDLE_SEQAN3_VERSION f500cf7fbe128636c6e50a99519b5eb2532ab70e) CPMDeclarePackage (seqan3 NAME seqan3 GIT_TAG ${NEEDLE_SEQAN3_VERSION} @@ -19,7 +19,7 @@ CPMDeclarePackage (seqan3 # googletest set (NEEDLE_GOOGLETEST_VERSION 1.15.2) CPMDeclarePackage (googletest - NAME googletest + NAME GTest VERSION ${NEEDLE_GOOGLETEST_VERSION} GITHUB_REPOSITORY google/googletest SYSTEM TRUE diff --git a/cmake/package.cmake b/cmake/package.cmake new file mode 100644 index 0000000..ad48e31 --- /dev/null +++ b/cmake/package.cmake @@ -0,0 +1,50 @@ +# 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 + +## PACKAGE +# Change version in this file: project (needle VERSION x.x.x) +# Change version in src/main.cpp: parser.info.version = "x.x.x"; +# No dependencies should be locally installed. +# To package, create a clean directory: +# +# mkdir needle-package +# cd needle-package +# git clone https://github.com/seqan/needle +# cd needle +# cd ../../../ +# mkdir package +# cd package +# cmake ../needle +# cmake --build . --target package_source +# +# Will create needle-[VERSION]-Source.tar.xz{,.sha256}. + +cmake_minimum_required (VERSION 3.7...3.30) + +set (CPACK_GENERATOR "TXZ") + +set (CPACK_PACKAGE_VERSION "${needle_VERSION}") +set (CPACK_PACKAGE_VENDOR "seqan") +set (CPACK_PACKAGE_CHECKSUM "SHA256") +set (CPACK_RESOURCE_FILE_LICENSE "${needle_SOURCE_DIR}/LICENSE.md") +set (CPACK_RESOURCE_FILE_README "${needle_SOURCE_DIR}/README.md") + +# Already being called on source package, i.e. CPM is already downloaded. +if (NOT CPM_DOWNLOAD_LOCATION) + set (CPM_DOWNLOAD_LOCATION "${needle_SOURCE_DIR}/cmake/CPM.cmake") +endif () + +configure_file ("${needle_SOURCE_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") +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/") + +include (CPack) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 63f63db..18acf8c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,6 +15,9 @@ add_executable ("${PROJECT_NAME}" main.cpp) target_link_libraries ("${PROJECT_NAME}" PRIVATE "${PROJECT_NAME}_lib") set_target_properties ("${PROJECT_NAME}" PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") +include (GNUInstallDirs) +install (TARGETS ${PROJECT_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + # https://cmake.org/cmake/help/latest/module/CMakeDependentOption.html # We usually want "-Werror" in the CI, but not when developing locally. # Virtually all CI providers set the environment variable `CI` to some value.