diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index f18ee41b..9317b9bc 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -199,4 +199,17 @@ jobs: else $CTEST_EXE --output-on-failure -C Debug --parallel `nproc`; $CTEST_EXE --output-on-failure -C Release --parallel `nproc`; - fi; \ No newline at end of file + fi; + + - name: Test install + shell: bash + run: if [[ "${{matrix.GEN}}" == "Unix Makefiles" ]]; + then + $CMAKE_EXE --build $GITHUB_WORKSPACE/build --target install -- -j`nproc`; + else + $CMAKE_EXE --build $GITHUB_WORKSPACE/build --target install --config Release -- -j`nproc`; + fi; + + - name: Test pkg-config + shell: bash + run: PKG_CONFIG_PATH="$GITHUB_WORKSPACE/install/lib/pkgconfig" pkg-config OpenCL-Headers --cflags | grep -q "\-I$GITHUB_WORKSPACE/install/include" diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 24c16655..2d2828ec 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -50,4 +50,12 @@ jobs: shell: bash run: | ctest -C Release --output-on-failure --parallel `sysctl -n hw.logicalcpu` - ctest -C Debug --output-on-failure --parallel `sysctl -n hw.logicalcpu` \ No newline at end of file + ctest -C Debug --output-on-failure --parallel `sysctl -n hw.logicalcpu` + + - name: Test install + shell: bash + run: cmake --build $GITHUB_WORKSPACE/build --target install --config Release + + - name: Test pkg-config + shell: bash + run: PKG_CONFIG_PATH="$GITHUB_WORKSPACE/install/lib/pkgconfig" pkg-config OpenCL-Headers --cflags | grep -q "\-I$GITHUB_WORKSPACE/install/include" diff --git a/CMakeLists.txt b/CMakeLists.txt index d87fa17a..76f840d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,9 @@ project(OpenCLHeaders option(OPENCL_HEADERS_BUILD_TESTING "Enable support for OpenCL C headers testing." OFF) option(OPENCL_HEADERS_BUILD_CXX_TESTS "Enable support for OpenCL C headers testing in C++ mode." ON) +set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +include(JoinPaths) + include(GNUInstallDirs) add_library(Headers INTERFACE) @@ -93,3 +96,11 @@ endif() if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR OPENCL_HEADERS_BUILD_TESTING) AND BUILD_TESTING) add_subdirectory(tests) endif() + +join_paths(OPENCL_INCLUDEDIR_PC "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") + +configure_file(OpenCL-Headers.pc.in OpenCL-Headers.pc @ONLY) +set(pkg_config_location ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/OpenCL-Headers.pc + DESTINATION ${pkg_config_location}) diff --git a/OpenCL-Headers.pc.in b/OpenCL-Headers.pc.in new file mode 100644 index 00000000..92d241c4 --- /dev/null +++ b/OpenCL-Headers.pc.in @@ -0,0 +1,7 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +includedir=@OPENCL_INCLUDEDIR_PC@ + +Name: OpenCL-Headers +Description: Khronos OpenCL Headers +Version: 3.0 +Cflags: -I${includedir} diff --git a/cmake/JoinPaths.cmake b/cmake/JoinPaths.cmake new file mode 100644 index 00000000..32d6d668 --- /dev/null +++ b/cmake/JoinPaths.cmake @@ -0,0 +1,26 @@ +# This module provides function for joining paths +# known from from most languages +# +# Original license: +# SPDX-License-Identifier: (MIT OR CC0-1.0) +# Explicit permission given to distribute this module under +# the terms of the project as described in /LICENSE.rst. +# Copyright 2020 Jan Tojnar +# https://github.com/jtojnar/cmake-snips +# +# Modelled after Python’s os.path.join +# https://docs.python.org/3.7/library/os.path.html#os.path.join +# Windows not supported +function(join_paths joined_path first_path_segment) + set(temp_path "${first_path_segment}") + foreach(current_segment IN LISTS ARGN) + if(NOT ("${current_segment}" STREQUAL "")) + if(IS_ABSOLUTE "${current_segment}") + set(temp_path "${current_segment}") + else() + set(temp_path "${temp_path}/${current_segment}") + endif() + endif() + endforeach() + set(${joined_path} "${temp_path}" PARENT_SCOPE) +endfunction()