From 63446206c121a3c6c346dab74b839b0bf4d92dd4 Mon Sep 17 00:00:00 2001 From: Lawrence Stubbs Date: Fri, 2 Aug 2024 11:24:04 -0400 Subject: [PATCH] CMake create release package, add GitHub Action CI This will create an complete installer package for most platforms. Thereafter with `Findlibuv.cmake` in there directory and something like the following in there `CMakeLists.txt`. ``` find_package(libuv QUIET) if(NOT libuv_FOUND) FetchContent_Declare(libuv URL https://github.com/libuv/libuv/archive/refs/tags/v1.48.0.zip URL_MD5 67d0e50ac6e95de12b09b17ff8baed0f ) FetchContent_MakeAvailable(libuv) endif() ``` I think https://github.com/libuv/libuv/pull/3194 should just be closed, it just doesn't actually automate any process, which was my initial use case, grab binary without me doing any building. --- .github/workflows/CI-release_package.yml | 210 +++++++++++++++++++++++ .gitignore | 1 + CMakeLists.txt | 96 +++++++++++ Findlibuv.cmake | 138 +++++++++++++++ libuvConfig.cmake.in | 8 + 5 files changed, 453 insertions(+) create mode 100644 .github/workflows/CI-release_package.yml create mode 100644 Findlibuv.cmake create mode 100644 libuvConfig.cmake.in diff --git a/.github/workflows/CI-release_package.yml b/.github/workflows/CI-release_package.yml new file mode 100644 index 00000000..b674a96d --- /dev/null +++ b/.github/workflows/CI-release_package.yml @@ -0,0 +1,210 @@ +name: CI-release_package + +on: + release: + types: [published] + +jobs: + build-windows: + name: Windows (${{ matrix.config.target }}) + permissions: + contents: write + packages: write + runs-on: windows-latest + strategy: + fail-fast: false + matrix: + config: + - {target: x64, build: win64 } + - {target: Win32, build: win32 } + steps: + - uses: ilammy/msvc-dev-cmd@v1 + with: + arch: ${{ matrix.config.target }} + - uses: actions/checkout@v4 + - name: Configure + run: | + mkdir build + cd build + cmake .. -D LIBUV_BUILD_TESTS=OFF -A ${{ matrix.config.target }} + - name: Build + run: | + cd build + cmake --build . --config Release + - name: Create NSIS Installer from Release + run: | + cd build + cpack -G NSIS + - name: Upload NSIS binary artifacts + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: built/Package/libuv-${{ github.event.release.tag_name }}-${{ matrix.config.build }}.exe + asset_name: libuv-${{ github.event.release.tag_name }}-${{ matrix.config.build }}.exe + tag: ${{ github.ref }} + overwrite: true + file_glob: true + body: "Various platform library/package installers, includes libraries and needed header *.h files." + + build-linux: + name: Linux ${{ matrix.config.target }} + permissions: + contents: write + packages: write + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + config: + - {target: amd64, flags: -m64 } + # - {target: i386, flags: -m32 } + steps: + - uses: actions/checkout@v4 + - name: Prepare + run: | + sudo dpkg --add-architecture i386 + sudo apt-get update -q -y + sudo apt-get install -y gcc-multilib g++-multilib valgrind libc6-dbg libc6-dbg:i386 + - name: Configure & build + run: | + mkdir build + cd build + cmake .. -DCMAKE_BUILD_TYPE=Release -D LIBUV_BUILD_TESTS=OFF -DCMAKE_C_FLAGS=${{ matrix.config.flags }} + cmake --build . + - name: Create DEB Installer from Release + run: | + cd build + cpack -G DEB + - name: Upload DEB binary artifacts + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: built/Package/libuv_${{ github.event.release.tag_name }}_${{ matrix.config.target }}.deb + asset_name: libuv_${{ github.event.release.tag_name }}_${{ matrix.config.target }}.deb + tag: ${{ github.ref }} + overwrite: true + file_glob: true + body: "Various platform library/package installers, includes libraries and needed header *.h files." + + build-centos: + name: CentOS + permissions: + contents: write + packages: write + runs-on: ubuntu-latest + strategy: + fail-fast: false + container: quay.io/centos/centos:stream9 + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Prepare + run: | + dnf install git make cmake gcc gcc-c++ binutils glibc-devel valgrind autoconf libtool bison automake libxml2-devel sudo which rpmdevtools rpmlint -y + - name: Configure & build + run: | + mkdir build + cd build + cmake .. -DCMAKE_BUILD_TYPE=Release -D LIBUV_BUILD_TESTS=OFF + cmake --build . + - name: Create RPM Installer from Release + run: | + cd build + cpack -G RPM + - name: Upload RPM binary artifacts + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: built/Package/libuv-${{ github.event.release.tag_name }}-Linux.rpm + asset_name: libuv-${{ github.event.release.tag_name }}-Linux.rpm + tag: ${{ github.ref }} + overwrite: true + file_glob: true + body: "Various platform library/package installers, includes libraries and needed header *.h files." + + build-macos: + name: macOS + permissions: + contents: write + packages: write + runs-on: macos-12 + steps: + - uses: actions/checkout@v4 + - name: Envinfo + run: npx envinfo + - name: Setup + run: | + brew install ninja automake libtool + - name: Configure & build + run: | + mkdir build + cd build + cmake .. -DCMAKE_BUILD_TYPE=Release -D LIBUV_BUILD_TESTS=OFF -G Ninja + cmake --build . + - name: Create DMG Installer from Release + run: | + cd build + cpack -G DragNDrop + - name: Upload DMG binary artifacts + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: built/Package/libuv-${{ github.event.release.tag_name }}-Darwin.dmg + asset_name: libuv-${{ github.event.release.tag_name }}-Darwin.dmg + tag: ${{ github.ref }} + overwrite: true + file_glob: true + body: "Various platform library/package installers, includes libraries and needed header *.h files." + + build-qemu: + name: ${{ matrix.target }} + permissions: + contents: write + packages: write + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - target: armhf + arch: armv7 + - target: arm64 + arch: aarch64 + - target: ppc64el + arch: ppc64le + - target: riscv64 + arch: riscv64 + - target: s390x + arch: s390x + steps: + - uses: actions/checkout@v4 + - uses: uraimo/run-on-arch-action@v2 + with: + arch: ${{ matrix.arch }} + distro: ubuntu_latest + githubToken: ${{ github.token }} + setup: | + mkdir -p built/Package + install: | + apt-get update -q -y + apt-get install -q -y --no-install-recommends cmake build-essential + env: | + # Valgrind on arm will fail if the stack size is larger than 8MB. + # Set QEMUs stack size to 8MB since Github runners use 16MB default. + QEMU_STACK_SIZE: 8388608 + run: | + mkdir build + cd build + cmake .. -DCMAKE_BUILD_TYPE=Release -D LIBUV_BUILD_TESTS=OFF + cmake --build . + cpack -G DEB + - name: Upload ${{ matrix.arch }} DEB binary artifacts + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: built/Package/libuv_${{ github.event.release.tag_name }}_${{ matrix.target }}.deb + asset_name: libuv_${{ github.event.release.tag_name }}_${{ matrix.target }}.deb + tag: ${{ github.ref }} + overwrite: true + file_glob: true + body: "Various platform library/package installers, includes libraries and needed header `*.h` files." diff --git a/.gitignore b/.gitignore index 6d396efb..fdb4400a 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,7 @@ Makefile Makefile.in /build/ +/built/ /test/.libs/ /test/run-tests diff --git a/CMakeLists.txt b/CMakeLists.txt index d16cf76f..6a7868de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -806,3 +806,99 @@ message(STATUS "summary of build options: C compiler: ${CMAKE_C_COMPILER} (${CMAKE_C_COMPILER_ID}) CFLAGS: ${CMAKE_C_FLAGS_${_build_type}} ${CMAKE_C_FLAGS} ") + +message("Generated with config types: ${CMAKE_CONFIGURATION_TYPES}") +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/built") +set_target_properties(${LIB_SELECTED} PROPERTIES VERSION ${UV_VERSION_MAJOR}) +set_target_properties(${LIB_SELECTED} PROPERTIES SOVERSION ${UV_VERSION_MAJOR}) + +set(_fmt TGZ) +if(WIN32) + set(_fmt ZIP) +endif() + +set(CPACK_GENERATOR ${_fmt}) +set(CPACK_ARCHIVE_COMPONENT_INSTALL ON) +set(CPACK_DEB_COMPONENT_INSTALL ON) +set(CPACK_RPM_COMPONENT_INSTALL ON) +set(CPACK_NUGET_COMPONENT_INSTALL ON) +set(CPACK_WIX_COMPONENT_INSTALL ON) +set(CPACK_NSIS_MODIFY_PATH ON) +set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1) +set(CPACK_VERBATIM_VARIABLES YES) + +set(CPACK_SOURCE_IGNORE_FILES + "~$" + "\\\\.svn/" + "/CMakeFiles/" + "/CMakeCache*" + "/cmake_install\\\\.cmake$" + "/cmake_uninstall\\\\.cmake$" + "^_CPack_.*/" + "/CPack*" + "\\\\.o$" + "/m4/" + "/build/" + "/built/" +) + +set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} + CACHE PATH "Location of header files" ) + +set(SYSCONFIG_INSTALL_DIR ${CMAKE_INSTALL_SYSCONFDIR}/${PROJECT_NAME} + CACHE PATH "Location of configuration files" ) + +configure_package_config_file(libuvConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/libuvConfig.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + PATH_VARS INCLUDE_INSTALL_DIR SYSCONFIG_INSTALL_DIR) + +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/libuvConfigVersion.cmake + VERSION ${PACKAGE_VERSION} + COMPATIBILITY SameMajorVersion ) + +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libuvConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/libuvConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ) + +set(CMAKE_INSTALL_CONFIG_NAME ${CMAKE_BUILD_TYPE}) +set(CPACK_PACKAGE_DIRECTORY "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/Package") +set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}) +set(CPACK_PACKAGE_INSTALL_DIRECTORY libuv) + +set(CPACK_PACKAGE_CONTACT "fixme@libuv.org") +set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Fixme Project Maintainers <${CPACK_PACKAGE_CONTACT}>") +set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) +set(CPACK_COMPONENTS_GROUPING ALL_COMPONENTS_IN_ONE) +SET(CPACK_COMPONENT_LIBRARIES_DESCRIPTION "multi-platform support library with a focus on asynchronous I/O.") + +set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE) +set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_SOURCE_DIR}/README.md) + +set(CPACK_PACKAGE_VENDOR "http://libuv.org/") +set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION}) +set(CPACK_PACKAGE_DESCRIPTION ${PROJECT_DESCRIPTION}) + +set(CPACK_RPM_PACKAGE_LICENSE "MIT") +set(CPACK_RPM_PACKAGE_URL "http://libuv.org/") +set(CPACK_RPM_PACKAGE_ARCHITECTURE "noarch") + +set(CMAKE_INSTALL_CONFIG_NAME ${CMAKE_BUILD_TYPE}) +install( + TARGETS ${LIB_SELECTED} + EXPORT "${PROJECT_NAME}Targets" + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) + +install( + EXPORT "${PROJECT_NAME}Targets" + FILE "${PROJECT_NAME}Targets.cmake" + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} +) + +set(CPACK_INSTALL_CMAKE_CONFIGURATIONS Release) +include(CPack) diff --git a/Findlibuv.cmake b/Findlibuv.cmake new file mode 100644 index 00000000..49bb68d4 --- /dev/null +++ b/Findlibuv.cmake @@ -0,0 +1,138 @@ +#[=======================================================================[ + +FindLibuv +--------- + +Find libuv includes and library. + +Imported Targets +^^^^^^^^^^^^^^^^ + +An :ref:`imported target ` named +``LIBUV::LIBUV`` is provided if libuv has been found. + +Result Variables +^^^^^^^^^^^^^^^^ + +This module defines the following variables: + +``LIBUV_FOUND`` + True if libuv was found, false otherwise. +``LIBUV_INCLUDE_DIRS`` + Include directories needed to include libuv headers. +``LIBUV_LIBRARIES`` + Libraries needed to link to libuv. +``LIBUV_VERSION`` + The version of libuv found. +``LIBUV_VERSION_MAJOR`` + The major version of libuv. +``LIBUV_VERSION_MINOR`` + The minor version of libuv. +``LIBUV_VERSION_PATCH`` + The patch version of libuv. + +Cache Variables +^^^^^^^^^^^^^^^ + +This module uses the following cache variables: + +``LIBUV_LIBRARY`` + The location of the libuv library file. +``LIBUV_INCLUDE_DIR`` + The location of the libuv include directory containing ``uv.h``. + +The cache variables should not be used by project code. +They may be set by end users to point at libuv components. +#]=======================================================================] + +#============================================================================= +# Copyright 2014-2016 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +#----------------------------------------------------------------------------- +find_library(libuv_LIBRARY + NAMES uv + ) +mark_as_advanced(libuv_LIBRARY) + +find_path(libuv_INCLUDE_DIR + NAMES uv.h + ) +mark_as_advanced(libuv_INCLUDE_DIR) + +#----------------------------------------------------------------------------- +# Extract version number if possible. +set(_LIBUV_H_REGEX "#[ \t]*define[ \t]+UV_VERSION_(MAJOR|MINOR|PATCH)[ \t]+[0-9]+") +if(LIBUV_INCLUDE_DIR AND EXISTS "${LIBUV_INCLUDE_DIR}/uv-version.h") + file(STRINGS "${LIBUV_INCLUDE_DIR}/uv-version.h" _LIBUV_H REGEX "${_LIBUV_H_REGEX}") +elseif(LIBUV_INCLUDE_DIR AND EXISTS "${LIBUV_INCLUDE_DIR}/uv.h") + file(STRINGS "${LIBUV_INCLUDE_DIR}/uv.h" _LIBUV_H REGEX "${_LIBUV_H_REGEX}") +else() + set(_LIBUV_H "") +endif() +foreach(c MAJOR MINOR PATCH) + if(_LIBUV_H MATCHES "#[ \t]*define[ \t]+UV_VERSION_${c}[ \t]+([0-9]+)") + set(_LIBUV_VERSION_${c} "${CMAKE_MATCH_1}") + else() + unset(_LIBUV_VERSION_${c}) + endif() +endforeach() + +if(DEFINED _LIBUV_VERSION_MAJOR AND DEFINED _LIBUV_VERSION_MINOR) + set(LIBUV_VERSION_MAJOR "${_LIBUV_VERSION_MAJOR}") + set(LIBUV_VERSION_MINOR "${_LIBUV_VERSION_MINOR}") + set(LIBUV_VERSION "${LIBUV_VERSION_MAJOR}.${LIBUV_VERSION_MINOR}") + if(DEFINED _LIBUV_VERSION_PATCH) + set(LIBUV_VERSION_PATCH "${_LIBUV_VERSION_PATCH}") + set(LIBUV_VERSION "${LIBUV_VERSION}.${LIBUV_VERSION_PATCH}") + else() + unset(LIBUV_VERSION_PATCH) + endif() +else() + set(LIBUV_VERSION_MAJOR "") + set(LIBUV_VERSION_MINOR "") + set(LIBUV_VERSION_PATCH "") + set(LIBUV_VERSION "") +endif() +unset(_LIBUV_VERSION_MAJOR) +unset(_LIBUV_VERSION_MINOR) +unset(_LIBUV_VERSION_PATCH) +unset(_LIBUV_H_REGEX) +unset(_LIBUV_H) + +#----------------------------------------------------------------------------- +# Set Find Package Arguments +include (FindPackageHandleStandardArgs) +find_package_handle_standard_args(libuv + FOUND_VAR libuv_FOUND + REQUIRED_VARS LIBUV_LIBRARY LIBUV_INCLUDE_DIR + VERSION_VAR LIBUV_VERSION + HANDLE_COMPONENTS + FAIL_MESSAGE + "Could NOT find Libuv" +) + +set(LIBUV_FOUND ${libuv_FOUND}) + +#----------------------------------------------------------------------------- +# Provide documented result variables and targets. +if(LIBUV_FOUND) + set(LIBUV_INCLUDE_DIRS ${LIBUV_INCLUDE_DIR}) + set(LIBUV_LIBRARIES ${LIBUV_LIBRARY}) + if(NOT TARGET LIBUV::LIBUV) + add_library(LIBUV::LIBUV UNKNOWN IMPORTED) + set_target_properties(LIBUV::LIBUV PROPERTIES + IMPORTED_LOCATION "${LIBUV_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${LIBUV_INCLUDE_DIRS}" + ) + endif() +endif() diff --git a/libuvConfig.cmake.in b/libuvConfig.cmake.in new file mode 100644 index 00000000..51f09ea9 --- /dev/null +++ b/libuvConfig.cmake.in @@ -0,0 +1,8 @@ +set(LIBUV_VERSION ${PROJECT_VERSION}) + +@PACKAGE_INIT@ + +set_and_check(LIBUV_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") +set_and_check(LIBUV_SYSCONFIG_DIR "@PACKAGE_SYSCONFIG_INSTALL_DIR@") + +check_required_components(libuv)