forked from KhronosGroup/OpenCL-CLHPP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
140 lines (121 loc) · 4.68 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
cmake_minimum_required(VERSION 3.1)
project(OpenCLHeadersCpp
VERSION 3.0
LANGUAGES CXX # Ideally should be NONE, but GNUInstallDirs detects platform arch using try_compile
# https://stackoverflow.com/questions/43379311/why-does-project-affect-cmakes-opinion-on-cmake-sizeof-void-p
)
enable_testing()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
option(BUILD_DOCS "Build Documentation" ON)
option(BUILD_EXAMPLES "Build Examples" ON)
option(OPENCL_CLHPP_BUILD_TESTING "Enable support for OpenCL C++ headers testing." OFF)
set(THREADS_PREFER_PTHREAD_FLAG ON CACHE BOOL
"find_package(Threads) preference. Recommendation is to keep default value."
)
# Legacy helper variables, see later at finding headers and ICD Loader
set(OPENCL_DIST_DIR "" CACHE PATH "OpenCL source dir (legacy helper var)")
set(OPENCL_LIB_DIR "${OPENCL_DIST_DIR}/lib" CACHE PATH "OpenCL library dir (legacy helper var)" )
set(OPENCL_INCLUDE_DIR "${OPENCL_DIST_DIR}/include" CACHE PATH "OpenCL source dir (legacy helper var)")
# Helper vars with names consistent with OpenCL-ICD-Loader's OPENCL_ICD_LOADER_HEADERS_DIR
# Default values taken from legacy defaults
set(OPENCL_CLHPP_HEADERS_DIR "${OPENCL_INCLUDE_DIR}" CACHE PATH "OpenCL headers dir")
set(OPENCL_CLHPP_LOADER_DIR "${OPENCL_LIB_DIR}" CACHE PATH "OpenCL library dir")
add_library(HeadersCpp INTERFACE)
add_library(OpenCL::HeadersCpp ALIAS HeadersCpp)
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR OPENCL_CLHPP_BUILD_TESTING)
include(CTest)
endif()
if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR OPENCL_CLHPP_BUILD_TESTING) AND BUILD_TESTING)
set(CLHPP_BUILD_TESTS ON)
endif()
# In the spirit of backward compatibility, to not break existing build automation
# we first check if the helper vars refer to existing files. If yes, use them.
# Otherwise search using 3.0 installed CMake Package Configs.
if(EXISTS "${OPENCL_CLHPP_HEADERS_DIR}/CL/cl.h")
if(NOT TARGET OpenCL::Headers)
message(STATUS "Defining OpenCL::Headers through OPENCL_INCLUDE_DIR")
add_library(OpenCLHeaders INTERFACE)
add_library(OpenCL::Headers ALIAS OpenCLHeaders)
target_include_directories(OpenCLHeaders INTERFACE ${OPENCL_INCLUDE_DIR})
endif()
else()
if(NOT TARGET OpenCL::Headers)
find_package(OpenCLHeaders REQUIRED)
endif()
endif()
if(BUILD_EXAMPLES OR CLHPP_BUILD_TESTS)
enable_language(C)
find_package(Threads REQUIRED)
endif()
if(CLHPP_BUILD_TESTS)
find_program(RUBY_EXECUTABLE ruby REQUIRED)
endif()
target_include_directories(HeadersCpp
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(HeadersCpp
INTERFACE
OpenCL::Headers
)
install(
TARGETS HeadersCpp
EXPORT OpenCLHeadersCppTargets
)
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(JoinPaths)
include(GNUInstallDirs)
install(
DIRECTORY include/CL
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
export(
EXPORT OpenCLHeadersCppTargets
FILE ${PROJECT_BINARY_DIR}/OpenCLHeadersCpp/OpenCLHeadersCppTargets.cmake
NAMESPACE OpenCL::
)
file(
WRITE ${PROJECT_BINARY_DIR}/OpenCLHeadersCpp/OpenCLHeadersCppConfig.cmake
"include(\"\${CMAKE_CURRENT_LIST_DIR}/OpenCLHeadersCppTargets.cmake\")"
)
set(config_package_location ${CMAKE_INSTALL_DATADIR}/cmake/OpenCLHeadersCpp)
install(
EXPORT OpenCLHeadersCppTargets
FILE OpenCLHeadersCppTargets.cmake
NAMESPACE OpenCL::
DESTINATION ${config_package_location}
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/OpenCLHeadersCpp/OpenCLHeadersCppConfig.cmake
DESTINATION ${config_package_location}
)
unset(CMAKE_SIZEOF_VOID_P)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/OpenCLHeadersCpp/OpenCLHeadersCppConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/OpenCLHeadersCpp/OpenCLHeadersCppConfigVersion.cmake
DESTINATION ${config_package_location}
)
set(UNITY_DIR ${PROJECT_SOURCE_DIR}/external/Unity CACHE PATH "Unity dir")
set(CMOCK_DIR ${PROJECT_SOURCE_DIR}/external/CMock CACHE PATH "CMock dir")
if(BUILD_DOCS)
add_subdirectory(docs)
endif(BUILD_DOCS)
if(BUILD_EXAMPLES)
add_subdirectory(examples)
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})