forked from arrayfire/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
339 lines (284 loc) · 11.2 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
# Copyright (c) 2017, ArrayFire
# All rights reserved.
#
# This file is distributed under 3-clause BSD license.
# The complete license agreement can be obtained at:
# http://arrayfire.com/licenses/BSD-3-Clause
cmake_minimum_required(VERSION 3.5)
project(ArrayFire
VERSION 3.7.0
LANGUAGES C CXX )
if(POLICY CMP0073)
cmake_policy(SET CMP0073 NEW)
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
include(AFInstallDirs)
include(CMakeDependentOption)
include(InternalUtils)
include(Version)
include(build_cl2hpp)
include(platform)
include(GetPrerequisites)
include(CheckCXXCompilerFlag)
arrayfire_set_cmake_default_variables()
#Set Intel OpenMP as default MKL thread layer
set(MKL_THREAD_LAYER "Intel OpenMP" CACHE STRING "The thread layer to choose for MKL")
find_package(CUDA 7.0)
find_package(OpenCL 1.2)
find_package(OpenGL)
find_package(FreeImage)
find_package(Threads)
find_package(FFTW)
find_package(CBLAS)
find_package(LAPACKE)
find_package(Doxygen)
find_package(MKL)
include(boost_package)
option(AF_BUILD_CPU "Build ArrayFire with a CPU backend" ON)
option(AF_BUILD_CUDA "Build ArrayFire with a CUDA backend" ${CUDA_FOUND})
option(AF_BUILD_OPENCL "Build ArrayFire with a OpenCL backend" ${OpenCL_FOUND})
option(AF_BUILD_UNIFIED "Build Backend-Independent ArrayFire API" ON)
option(AF_BUILD_DOCS "Create ArrayFire Documentation" ${DOXYGEN_FOUND})
option(AF_BUILD_EXAMPLES "Build Examples" ON)
option(AF_BUILD_FORGE
"Forge libs are not built by default as it is not link time dependency" OFF)
option(AF_WITH_NONFREE "Build ArrayFire nonfree algorithms" OFF)
option(AF_WITH_LOGGING "Build ArrayFire with logging support" ON)
option(AF_INSTALL_STANDALONE "Build installers that include all dependencies" OFF)
cmake_dependent_option(AF_WITH_RELATIVE_TEST_DIR "Use relative paths for the test data directory(For continious integration(CI) purposes only)" OFF
"BUILD_TESTING" OFF)
cmake_dependent_option(AF_WITH_IMAGEIO "Build ArrayFire with Image IO support" ${FreeImage_FOUND}
"FreeImage_FOUND" OFF)
cmake_dependent_option(AF_BUILD_FRAMEWORK "Build an ArrayFire framework for Apple platforms.(Experimental)" OFF
"APPLE" OFF)
option(AF_WITH_STATIC_FREEIMAGE "Use Static FreeImage Lib" OFF)
set(AF_WITH_CPUID ON CACHE BOOL "Build with CPUID integration")
af_deprecate(BUILD_CPU AF_BUILD_CPU)
af_deprecate(BUILD_CUDA AF_BUILD_CUDA)
af_deprecate(BUILD_OPENCL AF_BUILD_OPENCL)
af_deprecate(BUILD_UNIFIED AF_BUILD_UNIFIED)
af_deprecate(BUILD_DOCS AF_BUILD_DOCS)
af_deprecate(BUILD_NONFREE AF_WITH_NONFREE)
af_deprecate(BUILD_EXAMPLES AF_BUILD_EXAMPLES)
af_deprecate(USE_RELATIVE_TEST_DIR AF_WITH_RELATIVE_TEST_DIR)
af_deprecate(USE_FREEIMAGE_STATIC AF_WITH_STATIC_FREEIMAGE)
af_deprecate(USE_CPUID AF_WITH_CPUID)
mark_as_advanced(
AF_BUILD_FRAMEWORK
AF_INSTALL_STANDALONE
AF_WITH_CPUID
CUDA_HOST_COMPILER
CUDA_USE_STATIC_CUDA_RUNTIME
CUDA_rt_LIBRARY
SPDLOG_BUILD_EXAMPLES
SPDLOG_BUILD_TESTING)
#Configure forge submodule
#forge is included in ALL target if AF_BUILD_FORGE is ON
#otherwise, forge is not built at all
include(AFconfigure_forge_submodule)
configure_file(
${ArrayFire_SOURCE_DIR}/CMakeModules/version.hpp.in
${ArrayFire_BINARY_DIR}/version.hpp
)
if(AF_WITH_NONFREE)
message("Building with NONFREE requires the following patents")
message("Method and apparatus for identifying scale invariant features\n"
"in an image and use of same for locating an object in an image, David\n"
"G. Lowe, US Patent 6,711,293 (March 23, 2004). Provisional application\n"
"filed March 8, 1999. Asignee: The University of British Columbia. For\n"
"further details, contact David Lowe (lowe@cs.ubc.ca) or the\n"
"University-Industry Liaison Office of the University of British\n"
"Columbia.")
endif()
# when crosscompiling use the bin2cpp file from the native bin directory
if(CMAKE_CROSSCOMPILING)
set(NATIVE_BIN_DIR "NATIVE_BIN_DIR-NOTFOUND"
CACHE FILEPATH "Path to the Native build directory.")
if(NATIVE_BIN_DIR)
include(${NATIVE_BIN_DIR}/ImportExecutables.cmake)
else()
message(SEND_ERROR "Native Directory not found. Run cmake in a separate"
"directory and build the bin2cpp target.")
endif()
else()
add_executable(bin2cpp ${ArrayFire_SOURCE_DIR}/CMakeModules/bin2cpp.cpp)
target_link_libraries(bin2cpp)
export(TARGETS bin2cpp FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake)
endif()
if(NOT LAPACK_FOUND)
if(APPLE)
# UNSET THE VARIABLES FROM LAPACKE
unset(LAPACKE_LIB CACHE)
unset(LAPACK_LIB CACHE)
unset(LAPACKE_INCLUDES CACHE)
unset(LAPACKE_ROOT_DIR CACHE)
find_package(LAPACK)
endif()
endif()
set(SPDLOG_BUILD_TESTING OFF)
add_subdirectory(extern/spdlog EXCLUDE_FROM_ALL)
add_subdirectory(extern/glad)
add_subdirectory(src/backend/common)
add_subdirectory(src/api/c)
add_subdirectory(src/api/cpp)
conditional_directory(AF_BUILD_CPU src/backend/cpu)
conditional_directory(AF_BUILD_CUDA src/backend/cuda)
conditional_directory(AF_BUILD_OPENCL src/backend/opencl)
conditional_directory(AF_BUILD_UNIFIED src/api/unified)
if(TARGET af)
list(APPEND built_backends af)
endif()
if(TARGET afcpu)
list(APPEND built_backends afcpu)
endif()
if(TARGET afcuda)
list(APPEND built_backends afcuda)
endif()
if(TARGET afopencl)
list(APPEND built_backends afopencl)
endif()
set_target_properties(${built_backends} PROPERTIES
VERSION "${ArrayFire_VERSION}"
SOVERSION "${ArrayFire_VERSION_MAJOR}")
# On some distributions the linker will not add a library to the ELF header if
# the symbols are not needed when the library was first parsed by the linker.
# This causes undefined references issues when linking with libraries which have
# circular dependencies.
if(UNIX AND NOT APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set_target_properties(${built_backends} PROPERTIES
LINK_FLAGS "-Wl,--no-as-needed")
endif()
foreach(backend ${built_backends})
target_compile_definitions(${backend} PRIVATE AFDLL)
if(AF_WITH_LOGGING)
target_compile_definitions(${backend}
PRIVATE AF_WITH_LOGGING)
endif()
endforeach()
if(AF_BUILD_FRAMEWORK)
set_target_properties(${built_backends}
PROPERTIES
FRAMEWORK TRUE
FRAMEWORK_VERSION A
MACOSX_FRAMEWORK_IDENTIFIER com.arrayfire.arrayfireFramework
#MACOSX_FRAMEWORK_INFO_PLIST Info.plist
#PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/include/arrayfire.h;${af_headers}"
#XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer"
)
endif()
install(DIRECTORY include/ DESTINATION ${AF_INSTALL_INC_DIR}
COMPONENT headers
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp"
PATTERN ".gitignore" EXCLUDE
)
## The ArrayFire version file is generated and won't be included above, install
## it separately.
install(FILES ${ArrayFire_BINARY_DIR}/include/af/version.h
DESTINATION "${AF_INSTALL_INC_DIR}/af/"
COMPONENT headers)
#TODO(pradeep) install forge dependency for packaging - not required for builds
# install the examples irrespective of the AF_BUILD_EXAMPLES value
# only the examples source files are installed, so the installation of these
# source files does not depend on AF_BUILD_EXAMPLES
# when AF_BUILD_EXAMPLES is OFF, the examples source is installed without
# building the example executables
install(DIRECTORY examples/ #NOTE The slash at the end is important
DESTINATION ${AF_INSTALL_EXAMPLE_DIR}
COMPONENT examples)
install(DIRECTORY assets/examples/ #NOTE The slash at the end is important
DESTINATION ${AF_INSTALL_EXAMPLE_DIR}
COMPONENT examples)
install(DIRECTORY "${ArrayFire_SOURCE_DIR}/LICENSES/"
DESTINATION LICENSES
COMPONENT licenses)
foreach(backend CPU CUDA OpenCL Unified)
string(TOUPPER ${backend} upper_backend)
string(TOLOWER ${backend} lower_backend)
if(AF_BUILD_${upper_backend})
install(EXPORT ArrayFire${backend}Targets
NAMESPACE ArrayFire::
DESTINATION ${AF_INSTALL_CMAKE_DIR}
COMPONENT ${lower_backend})
export( EXPORT ArrayFire${backend}Targets
NAMESPACE ArrayFire::
FILE cmake/ArrayFire${backend}Targets.cmake)
endif()
endforeach()
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${ArrayFire_BINARY_DIR}/ArrayFireConfigVersion.cmake"
COMPATIBILITY SameMajorVersion
)
# This config file will be installed so we need to set the install_destination
# path relitive to the install path
set(INCLUDE_DIRS include)
set(CMAKE_DIR ${AF_INSTALL_CMAKE_DIR})
configure_package_config_file(
${CMAKE_MODULE_PATH}/ArrayFireConfig.cmake.in
cmake/install/ArrayFireConfig.cmake
INSTALL_DESTINATION "${AF_INSTALL_CMAKE_DIR}"
PATH_VARS INCLUDE_DIRS CMAKE_DIR
)
install(FILES ${ArrayFire_BINARY_DIR}/cmake/install/ArrayFireConfig.cmake
${ArrayFire_BINARY_DIR}/ArrayFireConfigVersion.cmake
DESTINATION ${AF_INSTALL_CMAKE_DIR}
COMPONENT cmake)
if((USE_CPU_MKL OR USE_OPENCL_MKL) AND TARGET MKL::MKL AND AF_INSTALL_STANDALONE)
if(TARGET MKL::ThreadingLibrary)
install(FILES
$<TARGET_FILE:MKL::ThreadingLibrary>
DESTINATION ${AF_INSTALL_LIB_DIR}
COMPONENT mkl_dependencies)
endif()
if(NOT WIN32)
install(FILES
$<TARGET_FILE:MKL::Interface>
DESTINATION ${AF_INSTALL_LIB_DIR}
COMPONENT mkl_dependencies)
endif()
install(FILES
$<TARGET_FILE:MKL::MKL>
$<TARGET_FILE:MKL::ThreadLayer>
${MKL_RUNTIME_KERNEL_LIBRARIES}
# This variable is used to add tbb.so.2 library because the main lib
# is a linker script and not a symlink so it cant be resolved using
# get_filename_component
${AF_ADDITIONAL_MKL_LIBRARIES}
DESTINATION ${AF_INSTALL_LIB_DIR}
COMPONENT mkl_dependencies)
endif()
# This file will be used to create the config file for the build directory.
# These config files will be used by the examples to find the ArrayFire
# libraries
set(INCLUDE_DIRS "${ArrayFire_SOURCE_DIR}/include" "${ArrayFire_BINARY_DIR}/include")
set(CMAKE_DIR "${ArrayFire_BINARY_DIR}/cmake")
configure_package_config_file(
${CMAKE_MODULE_PATH}/ArrayFireConfig.cmake.in
ArrayFireConfig.cmake
INSTALL_DESTINATION "${ArrayFire_BINARY_DIR}"
PATH_VARS INCLUDE_DIRS CMAKE_DIR
INSTALL_PREFIX "${ArrayFire_BINARY_DIR}"
)
# Registers the current build directory with the user's cmake config. This will
# create a file at $HOME/.cmake/packages/ArrayFire which will point to this source
# build directory.
# TODO(umar): Disable for now. Causing issues with builds on windows.
#export(PACKAGE ArrayFire)
# Unset the visibility to avoid setting policy commands for older versions of
# CMake for examples and tests.
unset(CMAKE_CXX_VISIBILITY_PRESET)
include(CTest)
configure_file(
${CMAKE_MODULE_PATH}/CTestCustom.cmake
${PROJECT_BINARY_DIR}/CTestCustom.cmake)
# Handle depricated BUILD_TEST variable if found.
if(BUILD_TEST)
set(BUILD_TESTING ${BUILD_TEST})
endif()
conditional_directory(BUILD_TESTING test)
set(ASSETS_DIR "${ArrayFire_SOURCE_DIR}/assets")
conditional_directory(AF_BUILD_EXAMPLES examples)
conditional_directory(AF_BUILD_DOCS docs)
include(CPackConfig)