-
Notifications
You must be signed in to change notification settings - Fork 548
Expand file tree
/
Copy pathInternalUtils.cmake
More file actions
288 lines (257 loc) · 11.7 KB
/
InternalUtils.cmake
File metadata and controls
288 lines (257 loc) · 11.7 KB
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
# 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
function(dependency_check VAR ERROR_MESSAGE)
if(NOT ${VAR})
message(SEND_ERROR ${ERROR_MESSAGE})
endif()
endfunction()
# Includes the directory if the variable is set
function(conditional_directory variable directory)
if(${variable})
add_subdirectory(${directory})
endif()
endfunction()
include(CheckCXXCompilerFlag)
if(WIN32)
check_cxx_compiler_flag(/Zc:__cplusplus cplusplus_define)
check_cxx_compiler_flag(/permissive- cxx_compliance)
endif()
check_cxx_compiler_flag(-ffast-math has_cxx_fast_math)
check_cxx_compiler_flag("-fp-model fast" has_cxx_fp_model)
check_cxx_compiler_flag(-fno-errno-math has_cxx_no_errno_math)
check_cxx_compiler_flag(-fno-trapping-math has_cxx_no_trapping_math)
check_cxx_compiler_flag(-fno-signed-zeros has_cxx_no_signed_zeros)
check_cxx_compiler_flag(-mno-ieee-fp has_cxx_no_ieee_fp)
check_cxx_compiler_flag(-Wno-unqualified-std-cast-call has_cxx_unqualified_std_cast_call)
check_cxx_compiler_flag(-Werror=reorder-ctor has_cxx_error_reorder_ctor)
check_cxx_compiler_flag(-Rno-debug-disables-optimization has_cxx_debug-disables-optimization)
function(arrayfire_set_default_cxx_flags target)
target_compile_options(${target}
PRIVATE
$<$<BOOL:${CMAKE_SYCL_COMPILER}>:
$<$<COMPILE_LANGUAGE:SYCL>:
# OpenCL targets need this flag to avoid
# ignored attribute warnings in the OpenCL
# headers
-Wno-ignored-attributes
-Wall
-Wno-unqualified-std-cast-call
-Werror=reorder-ctor
#-fp-model precise
$<$<BOOL:${AF_WITH_FAST_MATH}>: -ffast-math -fno-errno-math -fno-trapping-math -fno-signed-zeros -mno-ieee-fp>
$<$<NOT:$<BOOL:${AF_WITH_FAST_MATH}>>: $<IF:$<PLATFORM_ID:Windows>,/fp=precise,-fp-model=precise>>
$<$<CONFIG:Debug>:-Rno-debug-disables-optimization>
$<$<PLATFORM_ID:Windows>: /wd4251
/wd4068
/wd4275
/wd4668
/wd4710
/wd4505
/we5038
/bigobj
/EHsc
/nologo
# MSVC incorrectly sets the cplusplus to 199711L even if the compiler supports
# c++11 features. This flag sets it to the correct standard supported by the
# compiler
$<$<BOOL:${cplusplus_define}>:/Zc:__cplusplus>
$<$<BOOL:${cxx_compliance}>:/permissive-> >
>>
$<$<COMPILE_LANGUAGE:CXX>:
# C4068: Warnings about unknown pragmas
# C4668: Warnings about unknown defintions
# C4275: Warnings about using non-exported classes as base class of an
# exported class
$<$<CXX_COMPILER_ID:MSVC>: /wd4251
/wd4068
/wd4275
/wd4668
/wd4710
/wd4505
/we5038
/bigobj
/EHsc
/nologo
# MSVC incorrectly sets the cplusplus to 199711L even if the compiler supports
# c++11 features. This flag sets it to the correct standard supported by the
# compiler
$<$<BOOL:${cplusplus_define}>:/Zc:__cplusplus>
$<$<BOOL:${cxx_compliance}>:/permissive-> >
# OpenCL targets need this flag to avoid
# ignored attribute warnings in the OpenCL
# headers
$<$<BOOL:${has_ignored_attributes_flag}>:-Wno-ignored-attributes>
$<$<BOOL:${has_all_warnings_flag}>:-Wall>
$<$<BOOL:${has_cxx_unqualified_std_cast_call}>:-Wno-unqualified-std-cast-call>
$<$<BOOL:${has_cxx_error_reorder_ctor}>:-Werror=reorder-ctor>
$<$<BOOL:${AF_WITH_FAST_MATH}>:
$<$<BOOL:${has_cxx_fast_math}>:-ffast-math>
$<$<BOOL:${has_cxx_no_errno_math}>:-fno-errno-math>
$<$<BOOL:${has_cxx_no_trapping_math}>:-fno-trapping-math>
$<$<BOOL:${has_cxx_no_signed_zeros}>:-fno-signed-zeros>
$<$<BOOL:${has_cxx_no_ieee_fp}>:-mno-ieee-fp>
>
$<$<NOT:$<BOOL:${AF_WITH_FAST_MATH}>>:
$<$<BOOL:${has_cxx_fp_model}>:-fp-model precise>>
$<$<BOOL:${has_cxx_debug-disables-optimization}>:
$<$<CONFIG:Debug>:-Rno-debug-disables-optimization>>
>
)
target_compile_definitions(${target}
PRIVATE
AFDLL
$<$<PLATFORM_ID:Windows>: OS_WIN
WIN32_LEAN_AND_MEAN
NOMINMAX>
$<$<PLATFORM_ID:Darwin>: OS_MAC>
$<$<PLATFORM_ID:Linux>: OS_LNX>
$<$<BOOL:${AF_WITH_LOGGING}>: AF_WITH_LOGGING>
$<$<BOOL:${AF_CACHE_KERNELS_TO_DISK}>: AF_CACHE_KERNELS_TO_DISK>
$<$<BOOL:${AF_WITH_FAST_MATH}>: AF_WITH_FAST_MATH>
)
endfunction()
function(__af_deprecate_var var access value)
if(access STREQUAL "READ_ACCESS")
message(DEPRECATION "Variable ${var} is deprecated. Use AF_${var} instead.")
endif()
endfunction()
function(af_deprecate var newvar)
if(DEFINED ${var})
message(DEPRECATION "Variable ${var} is deprecated. Use ${newvar} instead.")
get_property(doc CACHE ${newvar} PROPERTY HELPSTRING)
set(${newvar} ${${var}} CACHE BOOL "${doc}" FORCE)
unset(${var} CACHE)
endif()
variable_watch(${var} __af_deprecate_var)
endfunction()
function(get_native_path out_path path)
file(TO_NATIVE_PATH ${path} native_path)
if (WIN32)
string(REPLACE "\\" "\\\\" native_path ${native_path})
set(${out_path} ${native_path} PARENT_SCOPE)
else ()
set(${out_path} ${path} PARENT_SCOPE)
endif ()
endfunction()
macro(arrayfire_set_cmake_default_variables)
set(CMAKE_PREFIX_PATH "${ArrayFire_BINARY_DIR};${CMAKE_PREFIX_PATH}")
set(BUILD_SHARED_LIBS ON)
set(CMAKE_CXX_FLAGS_COVERAGE
"-g -O0"
CACHE STRING "Flags used by the C++ compiler during coverage builds.")
set(CMAKE_C_FLAGS_COVERAGE
"-g -O0"
CACHE STRING "Flags used by the C compiler during coverage builds.")
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE
""
CACHE STRING "Flags used for linking binaries during coverage builds.")
set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
""
CACHE STRING "Flags used by the shared libraries linker during coverage builds.")
set(CMAKE_STATIC_LINKER_FLAGS_COVERAGE
""
CACHE STRING "Flags used by the static libraries linker during coverage builds.")
set(CMAKE_MODULE_LINKER_FLAGS_COVERAGE
""
CACHE STRING "Flags used by the module linker during coverage builds.")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_COVERAGE} --coverage")
set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_COVERAGE} --coverage")
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "${CMAKE_EXE_LINKER_FLAGS_COVERAGE} --coverage")
set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE "${CMAKE_SHARED_LINKER_FLAGS_COVERAGE} --coverage")
set(CMAKE_STATIC_LINKER_FLAGS_COVERAGE "${CMAKE_STATIC_LINKER_FLAGS_COVERAGE}")
set(CMAKE_MODULE_LINKER_FLAGS_COVERAGE "${CMAKE_STATIC_LINKER_FLAGS_COVERAGE} --coverage")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS_COVERAGE "")
set(CMAKE_C_FLAGS_COVERAGE "")
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "")
set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE "")
set(CMAKE_STATIC_LINKER_FLAGS_COVERAGE "")
set(CMAKE_MODULE_LINKER_FLAGS_COVERAGE "")
endif()
mark_as_advanced(
CMAKE_CXX_FLAGS_COVERAGE
CMAKE_C_FLAGS_COVERAGE
CMAKE_EXE_LINKER_FLAGS_COVERAGE
CMAKE_SHARED_LINKER_FLAGS_COVERAGE
CMAKE_STATIC_LINKER_FLAGS_COVERAGE
CMAKE_MODULE_LINKER_FLAGS_COVERAGE)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Store all binaries in the bin/<Config> directory
if(WIN32)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ArrayFire_BINARY_DIR}/bin)
endif()
if(APPLE AND (NOT DEFINED CMAKE_INSTALL_RPATH))
message(WARNING "CMAKE_INSTALL_RPATH is required when installing ArrayFire to the local system. Set it to /opt/arrayfire/lib if making the installer or your own custom install path.")
endif()
# This code is used to generate the compilers.h file in CMakeModules. Not all
# features of this modules are supported in the versions of CMake we wish to
# support so we are directly including the files here
# set(compiler_header_epilogue [=[
# #if defined(AF_COMPILER_CXX_RELAXED_CONSTEXPR) && AF_COMPILER_CXX_RELAXED_CONSTEXPR
# #define AF_CONSTEXPR constexpr
# #else
# #define AF_CONSTEXPR
# #endif
# #if __cpp_if_constexpr || __cplusplus >= 201606L
# #define AF_IF_CONSTEXPR if constexpr
# #else
# #define AF_IF_CONSTEXPR if
# #endif
# ]=])
# include(WriteCompilerDetectionHeader)
# write_compiler_detection_header(
# FILE ${ArrayFire_BINARY_DIR}/include/af/compilers.h
# PREFIX AF
# COMPILERS AppleClang Clang GNU Intel MSVC
# # NOTE: cxx_attribute_deprecated does not work well with C
# FEATURES cxx_rvalue_references cxx_noexcept cxx_variadic_templates cxx_alignas
# cxx_static_assert cxx_generalized_initializers cxx_relaxed_constexpr
# ALLOW_UNKNOWN_COMPILERS
# #[VERSION <version>]
# #[PROLOG <prolog>]
# EPILOG ${compiler_header_epilogue}
# )
configure_file(
${ArrayFire_SOURCE_DIR}/CMakeModules/compilers.h
${ArrayFire_BINARY_DIR}/include/af/compilers.h)
endmacro()
macro(set_policies)
cmake_parse_arguments(SP "" "TYPE" "POLICIES" ${ARGN})
foreach(_policy ${SP_POLICIES})
if(POLICY ${_policy})
cmake_policy(SET ${_policy} ${SP_TYPE})
endif()
endforeach()
endmacro()
macro(af_mkl_batch_check)
set(CMAKE_REQUIRED_LIBRARIES "MKL::RT")
check_symbol_exists(sgetrf_batch_strided "mkl_lapack.h" MKL_BATCH)
endmacro()
# Creates a CACHEd CMake variable which has limited set of possible string values
# Argumehts:
# NAME: The name of the variable
# DEFAULT: The default value of the variable
# DESCRIPTION: The description of the variable
# OPTIONS: The possible set of values for the option
#
# Example:
#
# af_multiple_option(NAME AF_COMPUTE_LIBRARY
# DEFAULT "Intel-MKL"
# DESCRIPTION "Compute library for signal processing and linear algebra routines"
# OPTIONS "Intel-MKL" "FFTW/LAPACK/BLAS")
macro(af_multiple_option)
cmake_parse_arguments(opt "" "NAME;DEFAULT;DESCRIPTION" "OPTIONS" ${ARGN})
set(${opt_NAME} ${opt_DEFAULT} CACHE STRING ${opt_DESCRIPTION})
set_property(CACHE ${opt_NAME} PROPERTY STRINGS ${opt_OPTIONS})
endmacro()
mark_as_advanced(
pkgcfg_lib_PC_CBLAS_cblas
pkgcfg_lib_PC_LAPACKE_lapacke
pkgcfg_lib_PKG_FFTW_fftw3
)