diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c9b992b..e33528d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,6 +21,9 @@ on: doc: type: boolean default: false + pack: + type: boolean + default: false workflow_dispatch: inputs: @@ -50,6 +53,9 @@ on: doc: type: boolean default: false + pack: + type: boolean + default: false jobs: format: @@ -139,6 +145,18 @@ jobs: - name: Run tests (release) run: ctest --preset ${{ matrix.compiler }}-release + - name: Package + if: inputs.pack && matrix.compiler == 'gcc' && matrix.arch == 'amd64' + working-directory: build/gcc/release + run: cpack + + - name: Upload package to GitHub + if: inputs.pack && matrix.compiler == 'gcc' && matrix.arch == 'amd64' + uses: actions/upload-artifact@v7.0.0 + with: + name: package + path: build/gcc/release/*.deb + - name: Configure (debug) run: cmake --preset ${{ matrix.compiler }}-debug diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index dfe8ab5..c7f1e39 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -23,3 +23,4 @@ jobs: scan: true coverage: true doc: true + pack: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a7865ff --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,59 @@ +name: release + +on: + push: + tags: + - 'v*.*.*' + +jobs: + version: + runs-on: ubuntu-latest + + permissions: + contents: read + + steps: + - name: Checkout + uses: actions/checkout@v6.0.2 + + - name: Check version + run: test "$GITHUB_REF_NAME" = "v$(cat VERSION)" + + build: + needs: [version] + + uses: ./.github/workflows/build.yml + + permissions: + contents: read + security-events: write + pull-requests: write + pages: write + id-token: write + + secrets: inherit + + with: + scan: true + asan: true + pack: true + + release: + needs: [build] + + runs-on: ubuntu-latest + + permissions: + contents: write + + steps: + - name: Download packages from GitHub + uses: actions/download-artifact@v7.0.0 + with: + name: package + + - name: Create release + uses: softprops/action-gh-release@v2.4.1 + with: + files: '*.deb' + generate_release_notes: true diff --git a/.gitignore b/.gitignore index 6a217b6..cc6a478 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build* +Testing/ *version.hpp *.cproject *.project @@ -6,3 +7,4 @@ build* *.launch *.vscode *.cache +CMakeUserPresets.json diff --git a/CMakeLists.txt b/CMakeLists.txt index faa182c..33f16c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,8 @@ string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" DCONV_VERSION_PATCH ${ message(STATUS "dconv version: ${DCONV_VERSION}") +include(GNUInstallDirs) + if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message(STATUS "Setting build type to Release as none was specified.") set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose build type." FORCE) @@ -68,3 +70,33 @@ endif() add_subdirectory(dconv) add_subdirectory(tools) + +include(CMakePackageConfigHelpers) + +install(EXPORT dconvTargets + NAMESPACE dconv:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + COMPONENT dev +) + +configure_package_config_file( + ${PROJECT_SOURCE_DIR}/cmake/dconvConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/dconvConfig.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} +) + +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/dconvConfigVersion.cmake + VERSION ${DCONV_VERSION} + COMPATIBILITY SameMajorVersion + ARCH_INDEPENDENT +) + +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/dconvConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/dconvConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + COMPONENT dev +) + +include(${PROJECT_SOURCE_DIR}/cmake/packaging.cmake) diff --git a/cmake/dconvConfig.cmake.in b/cmake/dconvConfig.cmake.in new file mode 100644 index 0000000..6040e19 --- /dev/null +++ b/cmake/dconvConfig.cmake.in @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/dconvTargets.cmake") + +check_required_components(dconv) diff --git a/cmake/packaging.cmake b/cmake/packaging.cmake new file mode 100644 index 0000000..90c85ff --- /dev/null +++ b/cmake/packaging.cmake @@ -0,0 +1,23 @@ +set(CPACK_GENERATOR "DEB") +set(CPACK_PACKAGE_NAME "lib${PROJECT_NAME}") +set(CPACK_PACKAGE_VERSION "${DCONV_VERSION}") +set(CPACK_PACKAGE_VERSION_MAJOR "${DCONV_VERSION_MAJOR}") +set(CPACK_PACKAGE_VERSION_MINOR "${DCONV_VERSION_MINOR}") +set(CPACK_PACKAGE_VERSION_PATCH "${DCONV_VERSION_PATCH}") +set(CPACK_PACKAGE_CONTACT "Mathieu Rabine") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Header-only C++ library for printing and parsing floating point numbers") +set(CPACK_COMPONENT_DEV_DESCRIPTION +"dconv converts doubles to and from text, from a buffer or a stream. +This package contains the headers and CMake configuration.") +set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/joinframework/dconv") + +set(CPACK_DEB_COMPONENT_INSTALL ON) +set(CPACK_COMPONENTS_ALL dev) +set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) +set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional") + +set(CPACK_DEBIAN_DEV_PACKAGE_NAME "lib${PROJECT_NAME}-dev") +set(CPACK_DEBIAN_DEV_PACKAGE_SECTION "libdevel") +set(CPACK_DEBIAN_DEV_PACKAGE_ARCHITECTURE "all") + +include(CPack) diff --git a/dconv/CMakeLists.txt b/dconv/CMakeLists.txt index d6fa372..36a7514 100644 --- a/dconv/CMakeLists.txt +++ b/dconv/CMakeLists.txt @@ -1,9 +1,5 @@ cmake_minimum_required(VERSION 3.22.1) -set(PUBLIC_HEADER_DIRS - include -) - set(PUBLIC_HEADERS include/dconv/probe.hpp include/dconv/diyfp.hpp @@ -14,9 +10,17 @@ set(PUBLIC_HEADERS ) add_library(${PROJECT_NAME} INTERFACE) -target_include_directories(${PROJECT_NAME} INTERFACE ${PUBLIC_HEADER_DIRS}) +add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) +target_include_directories(${PROJECT_NAME} INTERFACE + $ + $ +) +target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_20) set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS}") -install(TARGETS ${PROJECT_NAME} PUBLIC_HEADER DESTINATION include/dconv) +install(TARGETS ${PROJECT_NAME} + EXPORT dconvTargets + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dconv COMPONENT dev +) if(DCONV_ENABLE_TESTS) add_subdirectory(tests)