Skip to content

Commit

Permalink
CMake minimum 3.16
Browse files Browse the repository at this point in the history
  • Loading branch information
mfep committed Aug 15, 2023
1 parent 736cb47 commit 38d42ef
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 71 deletions.
83 changes: 44 additions & 39 deletions .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,47 +55,47 @@ 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
CONF:
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
CONF:
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
CONF:
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
CONF:
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
CONF:
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
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -484,6 +487,7 @@ jobs:
}
macos:
if: false
runs-on: macos-latest
needs: format
strategy:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
53 changes: 23 additions & 30 deletions cmake/Package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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:
# <PackageName>_<VersionNumber>-<DebianRevisionNumber>_<DebianArchitecture>.deb
Expand Down

0 comments on commit 38d42ef

Please sign in to comment.