Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,30 @@ jobs:
cd $GITHUB_WORKSPACE/build/downstream/sdk ;
$CTEST_EXE --output-on-failure

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

- name: Test pkg-config --libs
shell: bash
run: PKG_CONFIG_PATH="$GITHUB_WORKSPACE/install/lib/pkgconfig" pkg-config OpenCL --libs | grep -q "\-L$GITHUB_WORKSPACE/install/lib -lOpenCL"

- name: Consume pkg-config
shell: bash
run: ln -s $GITHUB_WORKSPACE/external/OpenCL-Headers/install/include $GITHUB_WORKSPACE/install/include;
PKG_CONFIG_PATH="$GITHUB_WORKSPACE/install/lib/pkgconfig" $CMAKE_EXE
-G "${{matrix.GEN}}"
-D CMAKE_C_COMPILER=${{matrix.COMPILER}}
-D CMAKE_C_FLAGS="-Wall -Wextra -pedantic -m${{matrix.BIN}}"
-D CMAKE_C_STANDARD=${{matrix.STD}}
-D CMAKE_C_EXTENSIONS=${{matrix.EXT}}
-D DRIVER_STUB_PATH=$GITHUB_WORKSPACE/build/libOpenCLDriverStub.so
-B$GITHUB_WORKSPACE/build/downstream/pkgconfig
-H$GITHUB_WORKSPACE/test/pkgconfig/pkgconfig ;
$CMAKE_EXE --build $GITHUB_WORKSPACE/build/downstream/pkgconfig ;
cd $GITHUB_WORKSPACE/build/downstream/pkgconfig ;
$CTEST_EXE --output-on-failure




Expand Down Expand Up @@ -266,3 +290,29 @@ 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 --cflags
shell: bash
run: PKG_CONFIG_PATH="$GITHUB_WORKSPACE/install/lib/pkgconfig" pkg-config OpenCL --cflags | grep -q "\-I$GITHUB_WORKSPACE/install/include"

- name: Test pkg-config --libs
shell: bash
run: PKG_CONFIG_PATH="$GITHUB_WORKSPACE/install/lib/pkgconfig" pkg-config OpenCL --libs | grep -q "\-L$GITHUB_WORKSPACE/install/lib -lOpenCL"

- name: Consume pkg-config
shell: bash
run: ln -s $GITHUB_WORKSPACE/external/OpenCL-Headers/install/include $GITHUB_WORKSPACE/install/include;
PKG_CONFIG_PATH="$GITHUB_WORKSPACE/install/lib/pkgconfig" $CMAKE_EXE
-G "${{matrix.GEN}}"
-D CMAKE_C_COMPILER=${{matrix.COMPILER}}
-D CMAKE_C_FLAGS="-Wall -Wextra -pedantic -m${{matrix.BIN}}"
-D CMAKE_C_STANDARD=${{matrix.STD}}
-D CMAKE_C_EXTENSIONS=${{matrix.EXT}}
-D DRIVER_STUB_PATH=$GITHUB_WORKSPACE/build/Release/libOpenCLDriverStub.so
-B $GITHUB_WORKSPACE/build/downstream/pkgconfig
-S $GITHUB_WORKSPACE/test/pkgconfig/pkgconfig;
$CMAKE_EXE --build $GITHUB_WORKSPACE/build/downstream/pkgconfig --config Release;
$CMAKE_EXE --build $GITHUB_WORKSPACE/build/downstream/pkgconfig --config Debug;
cd $GITHUB_WORKSPACE/build/downstream/pkgconfig;
$CTEST_EXE --output-on-failure -C Release;
$CTEST_EXE --output-on-failure -C Debug;
28 changes: 27 additions & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,30 @@ jobs:
if: matrix.GEN == 'Ninja Multi-Config'
shell: bash
run: |
cmake --build $GITHUB_WORKSPACE/build --config Release --target install
cmake --build $GITHUB_WORKSPACE/build --config Release --target install

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

- name: Test pkg-config --libs
shell: bash
run: PKG_CONFIG_PATH="$GITHUB_WORKSPACE/install/lib/pkgconfig" pkg-config OpenCL --libs | grep -q "\-L$GITHUB_WORKSPACE/install/lib -lOpenCL"

- name: Consume pkg-config
shell: bash
run: ln -s $GITHUB_WORKSPACE/external/OpenCL-Headers/install/include $GITHUB_WORKSPACE/install/include;
PKG_CONFIG_PATH="$GITHUB_WORKSPACE/install/lib/pkgconfig" cmake
-G "${{matrix.GEN}}"
-D CMAKE_C_FLAGS="-Wall -Wextra -pedantic -Wno-format"
-D CMAKE_C_COMPILER=/usr/local/bin/gcc-${{matrix.VER}}
-D CMAKE_C_STANDARD=${{matrix.STD}}
-D CMAKE_C_EXTENSIONS=${{matrix.EXT}}
-D DRIVER_STUB_PATH=$GITHUB_WORKSPACE/build/Release/libOpenCLDriverStub.dylib
-B $GITHUB_WORKSPACE/build/downstream/pkgconfig
-S $GITHUB_WORKSPACE/test/pkgconfig/pkgconfig;
cmake --build $GITHUB_WORKSPACE/build/downstream/pkgconfig --config Release;
cmake --build $GITHUB_WORKSPACE/build/downstream/pkgconfig --config Debug;
cd $GITHUB_WORKSPACE/build/downstream/pkgconfig;
ctest --output-on-failure -C Release
ctest --output-on-failure -C Debug
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ endif()
# and to study the performance impact.
option (ENABLE_OPENCL_LAYERS "Enable OpenCL Layers" ON)

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

include(CheckFunctionExists)
check_function_exists(secure_getenv HAVE_SECURE_GETENV)
check_function_exists(__secure_getenv HAVE___SECURE_GETENV)
Expand Down Expand Up @@ -211,3 +214,14 @@ install (TARGETS OpenCL
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

join_paths(OPENCL_LIBDIR_PC "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}")
join_paths(OPENCL_INCLUDEDIR_PC "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")

if (NOT MSVC)
configure_file(OpenCL.pc.in OpenCL.pc @ONLY)
set(pkg_config_location ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/OpenCL.pc
DESTINATION ${pkg_config_location})
endif()
10 changes: 10 additions & 0 deletions OpenCL.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=@OPENCL_LIBDIR_PC@

Name: OpenCL
Description: Khronos OpenCL ICD Loader
Requires: OpenCL-Headers
Version: 3.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirming: It's OK if this version number is different than our SOVERSION?

If so, this is another place that would be great to automate with #182!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirming: It's OK if this version number is different than our SOVERSION?

This mimics what ocl-icd does here: https://github.com/OCL-dev/ocl-icd/blob/master/OpenCL.pc.in where @OPENCL_VERSION@ is currently evaluated to 3.0

If so, this is another place that would be great to automate with #182!

Indeed

Libs: -L${libdir} -lOpenCL
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()
55 changes: 55 additions & 0 deletions test/pkgconfig/pkgconfig/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
cmake_minimum_required(VERSION 3.1)
find_package(PkgConfig REQUIRED)

project(PkgConfigTest
LANGUAGES C
)

pkg_check_modules(OPENCL REQUIRED OpenCL)

if(CMAKE_VERSION VERSION_LESS 3.12)
link_directories("${OPENCL_LIBRARY_DIRS}")
endif()

add_executable(${PROJECT_NAME}
../pkgconfig.c
)

target_include_directories(${PROJECT_NAME}
PRIVATE
${OPENCL_INCLUDE_DIRS}
)

if(CMAKE_VERSION VERSION_LESS 3.12)
target_link_libraries(${PROJECT_NAME}
PRIVATE
${OPENCL_LIBRARIES}
)
else()
target_link_libraries(${PROJECT_NAME}
PRIVATE
${OPENCL_LINK_LIBRARIES}
)
endif()

target_compile_options(${PROJECT_NAME}
PRIVATE
${OPENCL_CFLAGS_OTHER}
)

target_compile_definitions(${PROJECT_NAME}
PRIVATE
CL_TARGET_OPENCL_VERSION=120
)

include(CTest)

add_test(
NAME ${PROJECT_NAME}
COMMAND ${PROJECT_NAME}
)

set_tests_properties(${PROJECT_NAME}
PROPERTIES
ENVIRONMENT "OCL_ICD_FILENAMES=${DRIVER_STUB_PATH}"
)