Skip to content

Commit

Permalink
Added support for pkg-config. (#213)
Browse files Browse the repository at this point in the history
* Added support for pkg-config.

* Update CMakeLists.txt

* Update OpenCL-Headers.pc.in

* Try to add CI for Linux.

* Try to add CI for pkg-config for MacOS.

* Update to same scheme as OpenCL Loader.

* Update CMakeLists.txt
  • Loading branch information
Kerilk authored Jan 10, 2023
1 parent 8f33fba commit a86f4e7
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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"
10 changes: 9 additions & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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`
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"
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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})
7 changes: 7 additions & 0 deletions OpenCL-Headers.pc.in
Original file line number Diff line number Diff line change
@@ -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}
26 changes: 26 additions & 0 deletions cmake/JoinPaths.cmake
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit a86f4e7

Please sign in to comment.