Skip to content

Commit

Permalink
Add pkg-config file for C++ API bindings (#194)
Browse files Browse the repository at this point in the history
* Add pkg-config file for C++ API bindings.

* Fix missing pkgconfig on macos.

* Reflect headers updated pkgconfig install path.
  • Loading branch information
Kerilk authored Feb 22, 2023
1 parent 154810f commit ac7e7bd
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 1 deletion.
19 changes: 19 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Linux

on: [push, pull_request]

env:
OPENCL_PKGCONFIG_PATHS: ${{ github.workspace }}/install/share/pkgconfig:${{ github.workspace }}/external/OpenCL-Headers/install/share/pkgconfig:${{ github.workspace }}/external/OpenCL-ICD-Loader/install/lib/pkgconfig

jobs:
cmake-minimum:
runs-on: ${{ matrix.OS }}
Expand Down Expand Up @@ -160,6 +163,14 @@ jobs:
cd $GITHUB_WORKSPACE/build/downstream/sdk ;
$CTEST_EXE --output-on-failure

- name: Test pkg-config
shell: bash
run: PKG_CONFIG_PATH="$OPENCL_PKGCONFIG_PATHS" pkg-config OpenCL-CLHPP --cflags | grep -q "\-I$GITHUB_WORKSPACE/install/include"

- name: Test pkg-config dependency
shell: bash
run: PKG_CONFIG_PATH="$OPENCL_PKGCONFIG_PATHS" pkg-config OpenCL-CLHPP --cflags | grep -q "\-I$GITHUB_WORKSPACE/external/OpenCL-Headers/install/include"




Expand Down Expand Up @@ -319,3 +330,11 @@ jobs:
cd $GITHUB_WORKSPACE/build/downstream/sdk;
$CTEST_EXE --output-on-failure -C Release;
$CTEST_EXE --output-on-failure -C Debug;

- name: Test pkg-config
shell: bash
run: PKG_CONFIG_PATH="$OPENCL_PKGCONFIG_PATHS" pkg-config OpenCL-CLHPP --cflags | grep -q "\-I$GITHUB_WORKSPACE/install/include"

- name: Test pkg-config dependency
shell: bash
run: PKG_CONFIG_PATH="$OPENCL_PKGCONFIG_PATHS" pkg-config OpenCL-CLHPP --cflags | grep -q "\-I$GITHUB_WORKSPACE/external/OpenCL-Headers/install/include"
15 changes: 14 additions & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: MacOS

on: [push, pull_request]

env:
OPENCL_PKGCONFIG_PATHS: ${{ github.workspace }}/install/share/pkgconfig:${{ github.workspace }}/external/OpenCL-Headers/install/share/pkgconfig:${{ github.workspace }}/external/OpenCL-ICD-Loader/install/lib/pkgconfig

jobs:
macos-gcc:
#runs-on: macos-latest
Expand Down Expand Up @@ -157,4 +160,14 @@ jobs:
cmake --build $GITHUB_WORKSPACE/build/downstream/sdk --config Debug ;
cd $GITHUB_WORKSPACE/build/downstream/sdk ;
ctest --output-on-failure -C Release ;
ctest --output-on-failure -C Debug
ctest --output-on-failure -C Debug

- name: Test pkg-config
shell: bash
run: |
if [[ ! `which pkg-config` ]]; then brew install pkg-config; fi;
PKG_CONFIG_PATH="$OPENCL_PKGCONFIG_PATHS" pkg-config OpenCL-CLHPP --cflags | grep -q "\-I$GITHUB_WORKSPACE/install/include"
- name: Test pkg-config dependency
shell: bash
run: PKG_CONFIG_PATH="$OPENCL_PKGCONFIG_PATHS" pkg-config OpenCL-CLHPP --cflags | grep -q "\-I$GITHUB_WORKSPACE/external/OpenCL-Headers/install/include"
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ install(
EXPORT OpenCLHeadersCppTargets
)

set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(JoinPaths)

include(GNUInstallDirs)

install(
Expand Down Expand Up @@ -127,3 +130,11 @@ endif(BUILD_EXAMPLES)
if(CLHPP_BUILD_TESTS)
add_subdirectory(tests)
endif(CLHPP_BUILD_TESTS)

join_paths(OPENCLHPP_INCLUDEDIR_PC "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")

configure_file(OpenCL-CLHPP.pc.in OpenCL-CLHPP.pc @ONLY)
set(pkg_config_location ${CMAKE_INSTALL_DATADIR}/pkgconfig)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/OpenCL-CLHPP.pc
DESTINATION ${pkg_config_location})
8 changes: 8 additions & 0 deletions OpenCL-CLHPP.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
prefix=@CMAKE_INSTALL_PREFIX@
includedir=@OPENCLHPP_INCLUDEDIR_PC@

Name: OpenCL-CLHPP
Description: OpenCL API C++ bindings
Requires: 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 ac7e7bd

Please sign in to comment.