Skip to content

Commit

Permalink
Merge pull request #158 from eseiler/infra/install
Browse files Browse the repository at this point in the history
[INFRA] install target and cpack
  • Loading branch information
eseiler authored Nov 4, 2024
2 parents 9e1394b + 782d1a7 commit ba646e7
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 50 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/ci_install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# 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_BUILD_TYPE=Release \
-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
if: matrix.compiler == 'gcc-14'
uses: actions/upload-artifact@v4
with:
name: source-package
path: package/needle-*.tar.xz*
retention-days: 1

11 changes: 10 additions & 1 deletion .github/workflows/ci_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
67 changes: 20 additions & 47 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 ()
8 changes: 8 additions & 0 deletions cmake/cpack_install.cmake.in
Original file line number Diff line number Diff line change
@@ -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 ()
4 changes: 2 additions & 2 deletions cmake/package-lock.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand Down
50 changes: 50 additions & 0 deletions cmake/package.cmake
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit ba646e7

Please sign in to comment.