From 38d42efba5fbe23f82f8b8ae2dcd1ab74492f239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc=20Serf=C5=91z=C5=91?= Date: Tue, 15 Aug 2023 13:07:28 +0200 Subject: [PATCH] CMake minimum 3.16 --- .github/workflows/presubmit.yml | 83 +++++++++++++++++---------------- CMakeLists.txt | 4 +- cmake/Package.cmake | 53 +++++++++------------ 3 files changed, 69 insertions(+), 71 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 22c88404..b3f4d4bf 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -55,7 +55,7 @@ jobs: IMAGE: - streamhpc/opencl-sdk-intelcpu:ubuntu-22.04-20230717 include: - - CMAKE: 3.0.2 + - CMAKE: system C_COMPILER: gcc-9 BIN: 64 STD: 99 @@ -63,7 +63,7 @@ jobs: GEN: Unix Makefiles CONFIG: Debug IMAGE: streamhpc/opencl-sdk-intelcpu:ubuntu-20.04-20230717 - - CMAKE: 3.0.2 + - CMAKE: system C_COMPILER: gcc-9 BIN: 64 STD: 99 @@ -71,7 +71,7 @@ jobs: GEN: Unix Makefiles CONFIG: Release IMAGE: streamhpc/opencl-sdk-intelcpu:ubuntu-20.04-20230717 - - CMAKE: 3.0.2 + - CMAKE: system C_COMPILER: gcc-9 BIN: 32 STD: 99 @@ -79,7 +79,7 @@ jobs: GEN: Unix Makefiles CONFIG: Debug IMAGE: streamhpc/opencl-sdk-intelcpu:ubuntu-20.04-20230717 - - CMAKE: 3.0.2 + - CMAKE: system C_COMPILER: gcc-9 BIN: 32 STD: 99 @@ -87,7 +87,7 @@ jobs: GEN: Unix Makefiles CONFIG: Release IMAGE: streamhpc/opencl-sdk-intelcpu:ubuntu-20.04-20230717 - - CMAKE: 3.0.2 + - CMAKE: system C_COMPILER: gcc-11 BIN: 64 STD: 99 @@ -95,7 +95,7 @@ jobs: GEN: Unix Makefiles CONFIG: Debug IMAGE: streamhpc/opencl-sdk-intelcpu:ubuntu-22.04-20230717 - - CMAKE: 3.0.2 + - CMAKE: system C_COMPILER: gcc-11 BIN: 64 STD: 99 @@ -109,33 +109,41 @@ jobs: CPACK_EXE: /opt/Kitware/CMake/${{ matrix.CMAKE }}/bin/cpack CTEST_EXE: /opt/Kitware/CMake/${{ matrix.CMAKE }}/bin/ctest CC: ${{matrix.C_COMPILER}} + CFLAGS: -Wall -Wextra -pedantic -Werror -m${{matrix.BIN}} steps: + - name: Install system CMake + shell: bash + if: ${{matrix.CMAKE}} == 'system' + run: apt-get update -qq && apt-get install -y cmake && + echo "CMAKE_EXE=cmake" >> "$GITHUB_ENV" && + echo "CPACK_EXE=cpack" >> "$GITHUB_ENV" && + echo "CTEST_EXE=ctest" >> "$GITHUB_ENV" + - name: Checkout OpenCL-Headers uses: actions/checkout@v3 - name: Configure shell: bash - run: mkdir $GITHUB_WORKSPACE/build && cd $GITHUB_WORKSPACE/build && - $CMAKE_EXE + run: $CMAKE_EXE -G "${{matrix.CONF.GEN}}" -D BUILD_TESTING=ON - -D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}} + `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` -D CMAKE_C_STANDARD=${{matrix.STD}} - -D CMAKE_C_FLAGS="-Wall -Wextra -pedantic -Werror -m${{matrix.BIN}}" -D CMAKE_C_EXTENSIONS=OFF - -D CMAKE_INSTALL_PREFIX=`if [[ "${{matrix.CMAKE}}" != "3.0.2" ]]; then echo "$GITHUB_WORKSPACE/install"; else echo "/usr"; fi` - `if [[ "${{matrix.CMAKE}}" != "3.0.2" ]]; then echo "-D CPACK_PACKAGING_INSTALL_PREFIX=/usr"; fi` - $GITHUB_WORKSPACE + -D CMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install + -D CPACK_PACKAGING_INSTALL_PREFIX=/usr + -S $GITHUB_WORKSPACE + -B $GITHUB_WORKSPACE/build - name: Build shell: bash run: if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then - $CMAKE_EXE --build $GITHUB_WORKSPACE/build -- -j`nproc`; + $CMAKE_EXE --build $GITHUB_WORKSPACE/build --parallel `nproc`; else - $CMAKE_EXE --build $GITHUB_WORKSPACE/build --config Debug -- -j`nproc`; - $CMAKE_EXE --build $GITHUB_WORKSPACE/build --config Release -- -j`nproc`; + $CMAKE_EXE --build $GITHUB_WORKSPACE/build --config Debug --parallel `nproc`; + $CMAKE_EXE --build $GITHUB_WORKSPACE/build --config Release --parallel `nproc`; fi; - name: Test @@ -160,27 +168,28 @@ jobs: - name: Consume (DEB) shell: bash run: dpkg -i $GITHUB_WORKSPACE/package-deb/*.deb && - mkdir $GITHUB_WORKSPACE/build_package && cd $GITHUB_WORKSPACE/build_package && $CMAKE_EXE -G "${{matrix.CONF.GEN}}" - -D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}} + `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` -D CMAKE_C_STANDARD=${{matrix.STD}} - -D CMAKE_C_FLAGS="-Wall -Wextra -pedantic -Werror -m${{matrix.BIN}}" -D CMAKE_C_EXTENSIONS=OFF - $GITHUB_WORKSPACE/tests/pkgconfig/bare && + -S $GITHUB_WORKSPACE/tests/pkgconfig/bare + -B $GITHUB_WORKSPACE/build_package && if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then - $CMAKE_EXE --build $GITHUB_WORKSPACE/build_package -- -j`nproc`; + $CMAKE_EXE --build $GITHUB_WORKSPACE/build_package --parallel `nproc`; else - $CMAKE_EXE --build $GITHUB_WORKSPACE/build_package --config Debug -- -j`nproc`; - $CMAKE_EXE --build $GITHUB_WORKSPACE/build_package --config Release -- -j`nproc`; + $CMAKE_EXE --build $GITHUB_WORKSPACE/build_package --config Debug --parallel `nproc`; + $CMAKE_EXE --build $GITHUB_WORKSPACE/build_package --config Release --parallel `nproc`; fi; - name: Test pkg-config (DEB) shell: bash # /usr/include is already on the include search path, # we don't expect any output - run: if [[ $(pkg-config OpenCL --cflags) ]]; + run: | + pkg-config OpenCL-Headers --cflags + if [[ "$(pkg-config OpenCL-Headers --cflags)" ]]; then exit 1; fi; @@ -189,33 +198,26 @@ jobs: shell: bash run: apt-get remove -y opencl-c-headers - - name: Re-configure for install - if: matrix.CMAKE == '3.0.2' - shell: bash - run: cd $GITHUB_WORKSPACE/build && - $CMAKE_EXE -D CMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install $GITHUB_WORKSPACE - - name: Test install shell: bash - run: $CMAKE_EXE --build $GITHUB_WORKSPACE/build --target install --config ${{matrix.CONF.CONFIG}} -- -j`nproc`; + run: $CMAKE_EXE --build $GITHUB_WORKSPACE/build --target install --config ${{matrix.CONF.CONFIG}} --parallel `nproc` - name: Consume (install) shell: bash - run: mkdir $GITHUB_WORKSPACE/build_install && cd $GITHUB_WORKSPACE/build_install && - $CMAKE_EXE + run: $CMAKE_EXE -G "${{matrix.CONF.GEN}}" - -D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}} + `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` -D CMAKE_C_STANDARD=${{matrix.STD}} - -D CMAKE_C_FLAGS="-Wall -Wextra -pedantic -Werror -m${{matrix.BIN}}" -D CMAKE_C_EXTENSIONS=OFF -D CMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/install - $GITHUB_WORKSPACE/tests/pkgconfig/bare && + -S $GITHUB_WORKSPACE/tests/pkgconfig/bare + -B $GITHUB_WORKSPACE/build_install && if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then - $CMAKE_EXE --build $GITHUB_WORKSPACE/build_install -- -j`nproc`; + $CMAKE_EXE --build $GITHUB_WORKSPACE/build_install --parallel `nproc`; else - $CMAKE_EXE --build $GITHUB_WORKSPACE/build_install --config Debug -- -j`nproc`; - $CMAKE_EXE --build $GITHUB_WORKSPACE/build_install --config Release -- -j`nproc`; + $CMAKE_EXE --build $GITHUB_WORKSPACE/build_install --config Debug --parallel `nproc`; + $CMAKE_EXE --build $GITHUB_WORKSPACE/build_install --config Release --parallel `nproc`; fi; - name: Test pkg-config (install) @@ -224,6 +226,7 @@ jobs: pkg-config OpenCL-Headers --cflags | grep -q "\-I$GITHUB_WORKSPACE/install/include" windows: + if: false runs-on: windows-latest needs: format strategy: @@ -484,6 +487,7 @@ jobs: } macos: + if: false runs-on: macos-latest needs: format strategy: @@ -571,6 +575,7 @@ jobs: pkg-config OpenCL-Headers --cflags | grep -q "\-I$GITHUB_WORKSPACE/install/include" android: + if: false runs-on: ubuntu-latest needs: format strategy: diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fb337d6..e28aed49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ -cmake_minimum_required(VERSION 3.0) -cmake_policy(VERSION 3.0...3.22) +cmake_minimum_required(VERSION 3.16) +cmake_policy(VERSION 3.16...3.26) # Include guard for including this project multiple times if(TARGET Headers) diff --git a/cmake/Package.cmake b/cmake/Package.cmake index 225b53ad..6506f290 100644 --- a/cmake/Package.cmake +++ b/cmake/Package.cmake @@ -29,33 +29,28 @@ install( DESTINATION ${pkg_config_location} COMPONENT pkgconfig_install) -if(NOT (CMAKE_VERSION VERSION_LESS "3.5")) - set(PKGCONFIG_PREFIX "${CPACK_PACKAGING_INSTALL_PREFIX}") - configure_file( - OpenCL-Headers.pc.in - ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig_package/OpenCL-Headers.pc - @ONLY) - # This install component is only needed in the Debian package - install( - FILES ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig_package/OpenCL-Headers.pc - DESTINATION ${pkg_config_location} - COMPONENT pkgconfig_package - EXCLUDE_FROM_ALL) - - # By using component based packaging, component pkgconfig_install - # can be excluded from the package, and component pkgconfig_package - # can be included. - set(CPACK_DEB_COMPONENT_INSTALL ON) - set(CPACK_COMPONENTS_GROUPING "ALL_COMPONENTS_IN_ONE") - - include(CPackComponent) - cpack_add_component(pkgconfig_install) - cpack_add_component(pkgconfig_package) - set(CPACK_COMPONENTS_ALL "Unspecified;pkgconfig_package") -elseif(NOT (CMAKE_INSTALL_PREFIX STREQUAL CPACK_PACKAGING_INSTALL_PREFIX)) - message(FATAL_ERROR "When using CMake version < 3.5, CPACK_PACKAGING_INSTALL_PREFIX should not be set," - " or should be the same as CMAKE_INSTALL_PREFIX") -endif() +set(PKGCONFIG_PREFIX "${CPACK_PACKAGING_INSTALL_PREFIX}") +configure_file( + OpenCL-Headers.pc.in + ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig_package/OpenCL-Headers.pc + @ONLY) +# This install component is only needed in the Debian package +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig_package/OpenCL-Headers.pc + DESTINATION ${pkg_config_location} + COMPONENT pkgconfig_package + EXCLUDE_FROM_ALL) + +# By using component based packaging, component pkgconfig_install +# can be excluded from the package, and component pkgconfig_package +# can be included. +set(CPACK_DEB_COMPONENT_INSTALL ON) +set(CPACK_COMPONENTS_GROUPING "ALL_COMPONENTS_IN_ONE") + +include(CPackComponent) +cpack_add_component(pkgconfig_install) +cpack_add_component(pkgconfig_package) +set(CPACK_COMPONENTS_ALL "Unspecified;pkgconfig_package") # DEB packaging configuration set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_VENDOR}) @@ -75,9 +70,7 @@ set(CPACK_DEBIAN_PACKAGE_NAME "${DEBIAN_PACKAGE_NAME}" CACHE STRING "Package name" FORCE) -# Get architecture -execute_process(COMMAND dpkg "--print-architecture" OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE) -string(STRIP "${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}" CPACK_DEBIAN_PACKAGE_ARCHITECTURE) +set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "all") # Package file name in deb format: # _-_.deb