-
Notifications
You must be signed in to change notification settings - Fork 120
/
CMakeLists.txt
221 lines (209 loc) · 7.27 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
include(GenerateExportHeader)
include(GNUInstallDirs)
foreach(UTIL_LIB_NAME IN ITEMS Utils UtilsCpp)
if(UTIL_LIB_NAME STREQUAL Utils)
set(UTIL_LIB_SOURCES src/Utils/Utils.c)
set(UTIL_LIB_DEPS
OpenCL::Headers
$<$<BOOL:${HAVE_LIB_M}>:m>
)
set(UTIL_CL_VERSION_MACRO_NAME CL_TARGET_OPENCL_VERSION)
elseif(UTIL_LIB_NAME STREQUAL UtilsCpp)
set(UTIL_LIB_SOURCES src/Utils/Utils.cpp)
set(UTIL_LIB_DEPS
OpenCL::HeadersCpp
OpenCL::Utils
)
set(UTIL_CL_VERSION_MACRO_NAME CL_HPP_TARGET_OPENCL_VERSION)
else()
message(FATAL_ERROR "Unkown Util flavor")
endif()
set(UTIL_LIB_TARGET OpenCL${UTIL_LIB_NAME})
add_library(${UTIL_LIB_TARGET} ${UTIL_LIB_SOURCES})
add_library(OpenCL::${UTIL_LIB_NAME} ALIAS ${UTIL_LIB_TARGET})
string(TOUPPER ${UTIL_LIB_NAME} UPPER_UTIL_LIB_NAME)
generate_export_header(${UTIL_LIB_TARGET}
EXPORT_MACRO_NAME ${UPPER_UTIL_LIB_NAME}_EXPORT
EXPORT_FILE_NAME OpenCL${UTIL_LIB_NAME}_Export.h
)
target_include_directories(${UTIL_LIB_TARGET}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
)
target_link_libraries(${UTIL_LIB_TARGET}
PUBLIC
${UTIL_LIB_DEPS}
OpenCL::OpenCL
)
target_compile_definitions(${UTIL_LIB_TARGET}
PRIVATE
${UTIL_CL_VERSION_MACRO_NAME}=300
PUBLIC
CL_HPP_ENABLE_EXCEPTIONS
)
set_target_properties(${UTIL_LIB_TARGET}
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
FOLDER "Libraries/${UTIL_LIB_NAME}"
)
install(
TARGETS ${UTIL_LIB_TARGET}
EXPORT OpenCL${UTIL_LIB_NAME}Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(
DIRECTORY include/CL/Utils
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/CL
)
export(
EXPORT OpenCL${UTIL_LIB_NAME}Targets
FILE ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/cmake/OpenCL${UTIL_LIB_NAME}/OpenCL${UTIL_LIB_NAME}Targets.cmake
NAMESPACE OpenCL::
)
file(
WRITE ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/cmake/OpenCL${UTIL_LIB_NAME}/OpenCL${UTIL_LIB_NAME}Config.cmake
"include(\"\${CMAKE_CURRENT_LIST_DIR}/OpenCL${UTIL_LIB_NAME}Targets.cmake\")"
)
set(config_package_location ${CMAKE_INSTALL_DATADIR}/cmake/OpenCL${UTIL_LIB_NAME})
install(
EXPORT OpenCL${UTIL_LIB_NAME}Targets
FILE OpenCL${UTIL_LIB_NAME}Targets.cmake
NAMESPACE OpenCL::
DESTINATION ${config_package_location}
)
install(
FILES ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/cmake/OpenCL${UTIL_LIB_NAME}/OpenCL${UTIL_LIB_NAME}Config.cmake
DESTINATION ${config_package_location}
)
unset(CMAKE_SIZEOF_VOID_P)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/cmake/OpenCL${UTIL_LIB_NAME}/OpenCL${UTIL_LIB_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
install(
FILES ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/cmake/OpenCL${UTIL_LIB_NAME}/OpenCL${UTIL_LIB_NAME}ConfigVersion.cmake
DESTINATION ${config_package_location}
)
endforeach()
if(OPENCL_SDK_BUILD_SAMPLES)
foreach(SDK_LIB_NAME IN ITEMS SDK SDKCpp)
if(SDK_LIB_NAME STREQUAL SDK)
set(SDK_LIB_SOURCES
src/SDK/CLI.c
src/SDK/Context.c
src/SDK/Image.c
src/SDK/Random.c
)
set(SDK_LIB_DEPS
OpenCL::Headers
OpenCL::Utils
cargs
)
set(SDK_LIB_INCLUDES
${Stb_INCLUDE_DIR}
)
set(SDK_CL_VERSION_MACRO_NAME CL_TARGET_OPENCL_VERSION)
elseif(SDK_LIB_NAME STREQUAL SDKCpp)
set(SDK_LIB_SOURCES
src/SDK/CLI.cpp
src/SDK/Image.cpp
$<$<BOOL:${OPENCL_SDK_BUILD_OPENGL_SAMPLES}>:src/SDK/InteropContext.cpp>
$<$<BOOL:${OPENCL_SDK_BUILD_OPENGL_SAMPLES}>:src/SDK/InteropWindow.cpp>
)
set(SDK_LIB_DEPS
OpenCL::HeadersCpp
OpenCL::UtilsCpp
$<$<BOOL:${OPENCL_SDK_BUILD_OPENGL_SAMPLES}>:OpenGL::GL>
$<$<BOOL:${OPENCL_SDK_BUILD_OPENGL_SAMPLES}>:GLEW::GLEW>
$<$<AND:$<BOOL:${OPENCL_SDK_BUILD_OPENGL_SAMPLES}>,$<PLATFORM_ID:Linux>>:OpenGL::GLU>
$<$<BOOL:${OPENCL_SDK_BUILD_OPENGL_SAMPLES}>:sfml-system>
$<$<BOOL:${OPENCL_SDK_BUILD_OPENGL_SAMPLES}>:sfml-window>
$<$<BOOL:${OPENCL_SDK_BUILD_OPENGL_SAMPLES}>:sfml-graphics>
)
set(SDK_LIB_INCLUDES
${TCLAP_INCLUDE_DIR}
${Stb_INCLUDE_DIR}
)
set(SDK_CL_VERSION_MACRO_NAME CL_HPP_TARGET_OPENCL_VERSION)
else()
message(FATAL_ERROR "Unkown SDK flavor")
endif()
set(SDK_LIB_TARGET OpenCL${SDK_LIB_NAME})
add_library(${SDK_LIB_TARGET} ${SDK_LIB_SOURCES})
add_library(OpenCL::${SDK_LIB_NAME} ALIAS ${SDK_LIB_TARGET})
string(TOUPPER ${SDK_LIB_NAME} UPPER_SDK_LIB_NAME)
generate_export_header(${SDK_LIB_TARGET}
EXPORT_MACRO_NAME ${UPPER_SDK_LIB_NAME}_EXPORT
EXPORT_FILE_NAME OpenCL${SDK_LIB_NAME}_Export.h
)
configure_file(
include/CL/SDK/OpenCLSDK_Config.in.h
${CMAKE_CURRENT_BINARY_DIR}/OpenCLSDK_Config.h
)
target_include_directories(${SDK_LIB_TARGET}
PUBLIC
${SDK_LIB_INCLUDES}
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
)
target_link_libraries(${SDK_LIB_TARGET}
PUBLIC
${SDK_LIB_DEPS}
OpenCL::OpenCL
)
target_compile_definitions(${SDK_LIB_TARGET}
PRIVATE
${SDK_CL_VERSION_MACRO_NAME}=300
PUBLIC
CL_HPP_ENABLE_EXCEPTIONS
)
set_target_properties(${SDK_LIB_TARGET}
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
FOLDER "Libraries/${SDK_LIB_TARGET}"
)
install(
TARGETS ${SDK_LIB_TARGET}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
# Copying DLLs the samples depend on only makes sense on Wnidows. On *nix
# OSes we rely on RPATH. We can only do this with sufficiently new CMake.
if(
OPENCL_SDK_BUILD_OPENGL_SAMPLES AND
CMAKE_VERSION VERSION_GREATER_EQUAL 3.21 AND
CMAKE_SYSTEM_NAME MATCHES Windows
)
foreach(DEP IN ITEMS
GLEW::GLEW
sfml-window
sfml-graphics
sfml-system
)
if(TARGET ${DEP})
get_target_property(DEP_TYPE ${DEP} TYPE)
if(${DEP_TYPE} STREQUAL SHARED_LIBRARY)
install(
IMPORTED_RUNTIME_ARTIFACTS
${DEP}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endif()
endif()
endforeach()
endif()
endforeach()
endif(OPENCL_SDK_BUILD_SAMPLES)