This repository has been archived by the owner on Jan 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
CMakeLists.txt
423 lines (335 loc) · 13.7 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
cmake_minimum_required(VERSION 2.8.12)
project(cf4ocl2)
# Set modules directory
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules")
# Set log domain
add_definitions(-DG_LOG_DOMAIN=\"${PROJECT_NAME}\")
# #################### #
# DEPENDENCIES SECTION #
# #################### #
# Find git
find_package(Git QUIET)
# Update version from Git?
if (GIT_FOUND)
option(VERSION_UPDATE_FROM_GIT "Update project version from git?" OFF)
endif()
# Determine version from Git
include(GetVersionFromGitTag)
# Required for building with Visual Studio
include(GenerateExportHeader)
# Auto-determine architecture
include(TargetArch)
# Code coverage configuration
if ((DEFINED CMAKE_BUILD_TYPE) AND (CMAKE_BUILD_TYPE STREQUAL "Debug"))
# Option for generating code coverage reports
option(TESTS_GENERATE_COVERAGE "Generate code coverage?" OFF)
# If option for generating code coverage reports is on...
if (TESTS_GENERATE_COVERAGE)
# Include code coverage settings
include(CodeCoverage)
# Code coverage program locations should be marked as advanced
mark_as_advanced(GCOVR_PATH GCOV_PATH GENHTML_PATH LCOV_PATH)
# Append coverage compiler flags
append_coverage_compiler_flags()
# Define exclude folders
set(COVERAGE_LCOV_EXCLUDES '/usr/*')
# ...setup test target for coverage
setup_target_for_coverage_lcov(
NAME codecov # Name for custom target
EXECUTABLE ${CMAKE_CTEST_COMMAND} # Name of the test driver executable that runs the tests
DEPENDENCIES tests examples utils # Dependencies to build first
)
endif()
else()
# Unset code coverage generation options
unset(TESTS_GENERATE_COVERAGE CACHE)
endif()
# Search for glib with pkg-config
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB REQUIRED glib-2.0>=2.40.0)
# Find OpenCL
find_package(OpenCL REQUIRED)
set(OpenCL_SYSTEM_INCLUDE_DIRS ${OpenCL_INCLUDE_DIRS})
# Find optional executables for creating docs
find_package(Doxygen 1.8.3 QUIET)
find_package(LATEX QUIET)
# ################ #
# COMPILER OPTIONS #
# ################ #
# Compiler options for GCC/Clang
# -Wno-comment because of comment within comment in OpenCL headers
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra -Wall -Wno-comment -std=c99")
# Avoid including MinGW dll dependency
if(MINGW)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static-libgcc")
endif()
# Definitions for release builds
if ((DEFINED CMAKE_BUILD_TYPE) AND (CMAKE_BUILD_TYPE STREQUAL "Release"))
# Disable assertions on release builds
add_definitions("-DG_DISABLE_ASSERT")
elseif((DEFINED CMAKE_BUILD_TYPE) AND (CMAKE_BUILD_TYPE STREQUAL "MinSizeRel"))
# Disable assertions (e.g. g_return_if_fail) on minimum size release builds
add_definitions("-DG_DISABLE_ASSERT")
# Disable checks on minimum size release builds
add_definitions("-DG_DISABLE_CHECKS")
endif()
# ################################### #
# OPTIONALLY USE LOCAL OPENCL HEADERS #
# ################################### #
# Use provided OpenCL headers or system OpenCL headers?
if (NOT APPLE) # Not for Apple, which handles these headers differently
option(OpenCL_USE_LOCAL_HEADERS "Use local OpenCL headers?" OFF)
if (OpenCL_USE_LOCAL_HEADERS)
set(OpenCL_LOCAL_HEADERS "1.2" CACHE STRING
"OpenCL header version selected at CMake configure time")
set_property(CACHE OpenCL_LOCAL_HEADERS PROPERTY STRINGS
"1.0" "1.1" "1.2" "2.0" "2.1" "2.2" "3.0")
set(OpenCL_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/ocl")
set(OpenCL_VERSION_STRING ${OpenCL_LOCAL_HEADERS})
string(SUBSTRING ${OpenCL_VERSION_STRING} 0 1 OpenCL_VERSION_MAJOR)
string(SUBSTRING ${OpenCL_VERSION_STRING} 2 1 OpenCL_VERSION_MINOR)
else()
unset(OpenCL_LOCAL_HEADERS CACHE)
endif()
add_definitions(-DCL_TARGET_OPENCL_VERSION=${OpenCL_VERSION_MAJOR}${OpenCL_VERSION_MINOR}0)
else()
# Avoid deprecation messages in macOS
add_definitions("-DCL_SILENCE_DEPRECATION")
endif()
# ########################### #
# SET LIBRARY INCLUDE FOLDERS #
# ########################### #
include_directories(
${GLIB_INCLUDE_DIRS} # GLib headers
${OpenCL_INCLUDE_DIRS} # OpenCL headers
${CMAKE_BINARY_DIR}/include/cf4ocl2 # Library headers
${CMAKE_BINARY_DIR}/include) # Aggregate library header
# ###################### #
# DEFINE INSTALL FOLDERS #
# ###################### #
if(NOT DEFINED CMAKE_INSTALL_BINDIR)
set(CMAKE_INSTALL_BINDIR "bin"
CACHE PATH "Install sub-location for executables")
endif(NOT DEFINED CMAKE_INSTALL_BINDIR)
if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
set(CMAKE_INSTALL_LIBDIR "lib"
CACHE PATH "Install sub-location for object code libraries")
endif(NOT DEFINED CMAKE_INSTALL_LIBDIR)
if(NOT DEFINED CMAKE_INSTALL_INCLUDEDIR)
set(CMAKE_INSTALL_INCLUDEDIR "include"
CACHE PATH "Install sub-location for header files")
endif(NOT DEFINED CMAKE_INSTALL_INCLUDEDIR)
if(NOT DEFINED CMAKE_INSTALL_DATADIR)
set(CMAKE_INSTALL_DATADIR "share"
CACHE PATH "Install sub-location for read-only data")
endif(NOT DEFINED CMAKE_INSTALL_DATADIR)
if(NOT DEFINED CMAKE_INSTALL_DOCDIR)
set(CMAKE_INSTALL_DOCDIR "${CMAKE_INSTALL_DATADIR}/doc"
CACHE PATH "Install sub-location for documentation")
endif(NOT DEFINED CMAKE_INSTALL_DOCDIR)
if(NOT DEFINED CMAKE_INSTALL_MANDIR)
set(CMAKE_INSTALL_MANDIR "${CMAKE_INSTALL_DATADIR}/man"
CACHE PATH "Install sub-location for man docs")
endif(NOT DEFINED CMAKE_INSTALL_MANDIR)
mark_as_advanced(CMAKE_INSTALL_BINDIR CMAKE_INSTALL_LIBDIR
CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_DATADIR
CMAKE_INSTALL_DOCDIR CMAKE_INSTALL_MANDIR)
# ########################### #
# BUILD DOCUMENTATION SECTION #
# ########################### #
# add a target to generate API documentation with Doxygen
if(DOXYGEN_FOUND AND DOXYGEN_DOT_FOUND AND LATEX_COMPILER)
# Doc build is enabled
set(DOC_BUILD "ON" CACHE INTERNAL "Build documentation")
# Set doc generation directory
set(DOCS_DIRECTORY "doc")
# Document generation options
option(DOC_GENERATE_HTML "Generate HTML documentation?" ON)
option(DOC_DEVELOPER
"Generate internal documentation (for cf4ocl development only)?" OFF)
option(DOC_GENERATE_LATEX "Generate Latex documentation?" OFF)
if (DOC_GENERATE_LATEX AND CMAKE_MAKE_PROGRAM
AND PDFLATEX_COMPILER AND MAKEINDEX_COMPILER)
option(DOC_GENERATE_PDF "Generate PDF documentation?" OFF)
else()
unset(DOC_GENERATE_PDF CACHE)
endif()
if(UNIX)
option(DOC_GENERATE_MAN "Generate man pages?" OFF)
endif()
# If development docs are to be generated...
if (DOC_DEVELOPER)
# ...do not exclude test documentation
set(DOX_EXCLUDE_PATHS "" CACHE INTERNAL "")
# ...and include all headers
set(DOX_EXCLUDE_PATTERNS "" CACHE INTERNAL "")
else()
# ...otherwise exclude test documentation
set(DOX_EXCLUDE_PATHS
"${CMAKE_CURRENT_SOURCE_DIR}/tests" CACHE INTERNAL "")
# ...and exclude non-public headers
set(DOX_EXCLUDE_PATTERNS "*err_macros.h" CACHE INTERNAL "")
endif()
# Set doxygen document generation options
if (DOC_GENERATE_HTML)
set(DOX_GENERATE_HTML "YES")
else()
set(DOX_GENERATE_HTML "NO")
endif()
if (DOC_GENERATE_LATEX)
set(DOX_GENERATE_LATEX "YES")
else()
set(DOX_GENERATE_LATEX "NO")
endif()
if (DOC_GENERATE_MAN)
set(DOX_GENERATE_MAN "YES")
else()
set(DOX_GENERATE_MAN "NO")
endif()
if (DOC_DEVELOPER)
set(DOX_INTERNAL "YES")
else()
set(DOX_INTERNAL "NO")
endif()
# Document install options
if (DOC_GENERATE_HTML)
option(DOC_INSTALL_HTML "Install HTML documentation?" OFF)
else()
unset(DOC_INSTALL_HTML CACHE)
endif()
if (DOC_GENERATE_PDF)
option(DOC_INSTALL_PDF "Install Latex documentation?" OFF)
else()
unset(DOC_INSTALL_PDF CACHE)
endif()
if (DOC_GENERATE_MAN)
option(DOC_INSTALL_MAN "Install man pages" OFF)
else()
unset(DOC_INSTALL_MAN CACHE)
endif()
# If git is found, set document file version filter to last
# commit where file was changed
if (GIT_FOUND)
set(DOX_FILE_VERSION_FILTER
"${GIT_EXECUTABLE} log -n 1 --pretty=%h --")
endif()
# Linux/OSX options
if (UNIX)
# Create links to OpenCL API when OpenCL functions are mentioned?
# This is slow and requires Bash and other command-line utilities
option(DOC_OPENCL_FUNCTION_URLS
"Create links to OpenCL API (much slower)?" OFF)
if (DOC_OPENCL_FUNCTION_URLS)
# Create those links
set(DOX_OPENCL_FUNCTION_URLS_FILTER
"${PROJECT_SOURCE_DIR}/auxbuild/docfilter.sh")
endif()
endif()
# Copy and configure doxigen configuration file
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in
${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
# Add a build docs target
if (DOC_GENERATE_HTML OR DOC_GENERATE_LATEX OR DOC_GENERATE_MAN)
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating documentation with Doxygen" VERBATIM)
else()
add_custom_target(doc
${CMAKE_COMMAND} -E echo "Enable at least one document format."
COMMENT "All document generation formats are disabled!" VERBATIM)
endif()
# Generate PDF from latex files
if (DOC_GENERATE_PDF)
add_custom_command(TARGET doc POST_BUILD
COMMAND ${CMAKE_MAKE_PROGRAM}
COMMAND ${CMAKE_COMMAND} -E make_directory ../pdf
COMMAND ${CMAKE_COMMAND} -E copy refman.pdf ../pdf
WORKING_DIRECTORY ${DOCS_DIRECTORY}/latex)
endif()
# Post-process man pages created by Doxygen
if(DOC_GENERATE_MAN)
add_custom_command(TARGET doc POST_BUILD
COMMAND ${CMAKE_SOURCE_DIR}/auxbuild/buildman.sh
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${DOCS_DIRECTORY}/man/)
endif()
# Add documentation installation target (if the docs have been built)
if (DOC_INSTALL_HTML)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${DOCS_DIRECTORY}/html/
DESTINATION ${CMAKE_INSTALL_DOCDIR}/${PROJECT_NAME}/html OPTIONAL)
endif()
if (DOC_INSTALL_PDF)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${DOCS_DIRECTORY}/latex/refman.pdf
DESTINATION ${CMAKE_INSTALL_DOCDIR}/${PROJECT_NAME} OPTIONAL)
endif()
if (DOC_INSTALL_MAN)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${DOCS_DIRECTORY}/man/
DESTINATION ${CMAKE_INSTALL_MANDIR} OPTIONAL
FILES_MATCHING REGEX "(ccl|CCL).*gz")
endif()
else()
# No doc builds
unset(DOC_BUILD CACHE)
# Add doc target which warns that some document build dependencies
# are missing
add_custom_target(doc
${CMAKE_COMMAND} -E echo "Documentation generation is disabled."
COMMENT "One or more tools required for documentation generation were not found!"
VERBATIM)
endif()
# ############### #
# PROCESS SUBDIRS #
# ############### #
# Add src folder
add_subdirectory(src)
# Add tests folder
enable_testing()
add_subdirectory(tests)
# Add scripts folder
add_subdirectory(scripts)
# ################# #
# PACKAGING SECTION #
# ################# #
# pkg-config support
configure_file(${CMAKE_SOURCE_DIR}/cf4ocl2.pc.in
${CMAKE_BINARY_DIR}/generated/cf4ocl2.pc @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/generated/cf4ocl2.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
COMPONENT utilities)
# build a CPack driven installer package
include(InstallRequiredSystemLibraries)
# Determine architecture
target_architecture(BUILD_ARCH_GET)
set(PACKAGE_ARCH_NAME "${BUILD_ARCH_GET}" CACHE STRING "Build architecture (for packaging only)" FORCE)
mark_as_advanced(PACKAGE_ARCH_NAME)
# Generic packaging settings
set(CPACK_GENERATOR "TGZ")
set(CPACK_PACKAGE_VERSION_MAJOR "${${PROJECT_NAME}_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${${PROJECT_NAME}_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${${PROJECT_NAME}_VERSION_PATCH}")
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}-${${PROJECT_NAME}_VERSION_TWEAK}")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A cross-platform pure C99 object-oriented framework for developing and benchmarking OpenCL projects in C/C++")
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}-${CMAKE_SYSTEM_NAME}.${PACKAGE_ARCH_NAME}")
set(CPACK_RESOURCE_VENDOR "fakenmc.com")
if(WIN32)
# Windows packaging settings
set(CPACK_GENERATOR "NSIS" "ZIP")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}")
set(CPACK_NSIS_URL_INFO_ABOUT "http://nunofachada.github.io/cf4ocl/" )
elseif(APPLE)
# OSX packaging settings
# Use defaults
elseif(UNIX)
# Linux packaging settings
set(CPACK_GENERATOR "DEB" "RPM" "TGZ")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Nuno Fachada <[email protected]>")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libglib2.0-0 (>= 2.32.1), ocl-icd-libopencl1 (>= 1.3)")
set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "ocl-icd-opencl-dev (>= 1.3), opencl-headers (>= 1.2)")
set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
set(CPACK_RPM_PACKAGE_REQUIRES "glib2 >= 2.32.1, ocl-icd >= 1.3")
set(CPACK_RPM_PACKAGE_SUGGESTS "ocl-icd-devel >= 1.3, opencl-headers >= 1.2")
endif()
include (CPack)