Merge topic 'FindOpenCL-imported-target'

b66d4739 FindOpenCL: Add an imported target
This commit is contained in:
Brad King 2016-06-03 10:45:48 -04:00 committed by CMake Topic Stage
commit e3f7637659
6 changed files with 66 additions and 2 deletions

View File

@ -0,0 +1,4 @@
FindOpenCL-imported-target
--------------------------
* The :module:`FindOpenCL` module now provides imported targets.

View File

@ -4,7 +4,16 @@
#
# Try to find OpenCL
#
# Once done this will define::
# IMPORTED Targets
# ^^^^^^^^^^^^^^^^
#
# This module defines :prop_tgt:`IMPORTED` target ``OpenCL::OpenCL``, if
# OpenCL has been found.
#
# Result Variables
# ^^^^^^^^^^^^^^^^
#
# This module defines the following variables::
#
# OpenCL_FOUND - True if OpenCL was found
# OpenCL_INCLUDE_DIRS - include directories for OpenCL
@ -20,7 +29,7 @@
#
#=============================================================================
# Copyright 2014 Matthaeus G. Chajdas
# Copyright 2014-2016 Matthaeus G. Chajdas
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
@ -134,3 +143,10 @@ find_package_handle_standard_args(
mark_as_advanced(
OpenCL_INCLUDE_DIR
OpenCL_LIBRARY)
if(OpenCL_FOUND AND NOT TARGET OpenCL::OpenCL)
add_library(OpenCL::OpenCL UNKNOWN IMPORTED)
set_target_properties(OpenCL::OpenCL PROPERTIES
IMPORTED_LOCATION "${OpenCL_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${OpenCL_INCLUDE_DIRS}")
endif()

View File

@ -1378,6 +1378,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
add_subdirectory(FindLTTngUST)
endif()
if(CMake_TEST_FindOpenCL)
add_subdirectory(FindOpenCL)
endif()
if(CMake_TEST_FindOpenSSL)
add_subdirectory(FindOpenSSL)
endif()

View File

@ -0,0 +1,10 @@
add_test(NAME FindOpenCL.Test COMMAND
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
--build-and-test
"${CMake_SOURCE_DIR}/Tests/FindOpenCL/Test"
"${CMake_BINARY_DIR}/Tests/FindOpenCL/Test"
${build_generator_args}
--build-project TestFindOpenCL
--build-options ${build_options}
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)

View File

@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.4)
project(TestFindOpenCL C)
include(CTest)
find_package(OpenCL REQUIRED)
add_executable(test_tgt main.c)
target_link_libraries(test_tgt OpenCL::OpenCL)
add_test(NAME test_tgt COMMAND test_tgt)
add_executable(test_var main.c)
target_include_directories(test_var PRIVATE ${OpenCL_INCLUDE_DIRS})
target_link_libraries(test_var PRIVATE ${OpenCL_LIBRARIES})
add_test(NAME test_var COMMAND test_var)

View File

@ -0,0 +1,16 @@
#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#include <CL/cl.h>
#endif
int main()
{
cl_uint platformIdCount;
// We can't assert on the result because this may return an error if no ICD is
// found
clGetPlatformIDs (0, NULL, &platformIdCount);
return 0;
}