forked from Foadsf/CrossBLAS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
321 lines (260 loc) · 9.55 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
cmake_minimum_required(VERSION 3.2)
project(
BLAS
VERSION 3.12.0.1
LANGUAGES Fortran)
set(CMAKE_CONFIGURATION_TYPES "Debug" "Release" "MinSizeRel" "RelWithDebInfo"
"Coverage")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE
"Release"
CACHE STRING "Choose the type of build." FORCE)
message(STATUS "Setting build type to 'Release' as none was specified.")
endif()
# Set the Fortran compilation flags depending on the compiler
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -O3 -w")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
set(CMAKE_Fortran_FLAGS
"${CMAKE_Fortran_FLAGS} /Qipo /MP /Qdiag-disable:10448 /Qdiag-disable:warn"
)
endif()
# Add the CMake directory for custom CMake modules
set(CMAKE_MODULE_PATH "${BLAS_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
# specify the standard of Fortran if needed
if(NOT CMAKE_Fortran_STANDARD)
set(CMAKE_Fortran_STANDARD 95)
set(CMAKE_Fortran_STANDARD_REQUIRED True)
endif()
# Add subdirectories add_subdirectory(src)
# Configuration for building shared libraries
option(BUILD_SHARED_LIBS "Build as a shared library" OFF)
# Coverage
set(_is_coverage_build 0)
set(_msg "Checking if build type is 'Coverage'")
message(STATUS "${_msg}")
if(NOT CMAKE_CONFIGURATION_TYPES)
string(TOLOWER ${CMAKE_BUILD_TYPE} _build_type_lc)
if(${_build_type_lc} STREQUAL "coverage")
set(_is_coverage_build 1)
endif()
endif()
message(STATUS "${_msg}: ${_is_coverage_build}")
if(_is_coverage_build)
message(STATUS "Adding coverage")
find_package(codecov)
endif()
include(CTest)
enable_testing()
add_subdirectory(tests)
# Export all symbols on Windows when building shared libraries
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
# By default build index32 library
option(BUILD_INDEX64 "Build Index-64 API libraries" OFF)
if(BUILD_INDEX64)
set(BLASLIB "blas64")
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} -DWeirdNEC -DLAPACK_ILP64 -DHAVE_LAPACK_CONFIG_H")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fdefault-integer-8")
else()
set(BLASLIB "blas")
endif()
# --------------------------------------------------
set(BLAS_INSTALL_EXPORT_NAME ${BLASLIB}-targets)
macro(blas_install_library lib)
install(
TARGETS ${lib}
EXPORT ${BLAS_INSTALL_EXPORT_NAME}
ARCHIVE DESTINATION lib COMPONENT Development
LIBRARY DESTINATION lib COMPONENT RuntimeLibraries
RUNTIME DESTINATION lib COMPONENT RuntimeLibraries)
endmacro()
set(PKG_CONFIG_DIR lib/pkgconfig)
# --------------------------------------------------
# Precision to build By default all precisions are generated
option(BUILD_SINGLE "Build single precision real" ON)
option(BUILD_DOUBLE "Build double precision real" ON)
option(BUILD_COMPLEX "Build single precision complex" ON)
option(BUILD_COMPLEX16 "Build double precision complex" ON)
message(STATUS "Build single precision real: ${BUILD_SINGLE}")
message(STATUS "Build double precision real: ${BUILD_DOUBLE}")
message(STATUS "Build single precision complex: ${BUILD_COMPLEX}")
message(STATUS "Build double precision complex: ${BUILD_COMPLEX16}")
if(NOT
(BUILD_SINGLE
OR BUILD_DOUBLE
OR BUILD_COMPLEX
OR BUILD_COMPLEX16))
message(
FATAL_ERROR
"Nothing to build, no precision selected.
Please enable at least one of these:
BUILD_SINGLE, BUILD_DOUBLE, BUILD_COMPLEX, BUILD_COMPLEX16.")
endif()
include(GNUInstallDirs)
include(PlatformSpecificSettings)
include(PreventInSourceBuilds)
include(PreventInBuildInstalls)
# --------------------------------------------------
# Check for any necessary platform specific compiler flags
include(CheckLAPACKCompilerFlags)
checklapackcompilerflags("-recursive" _recursiveFlag)
checklapackcompilerflags("-frecursive" _frecursiveFlag)
checklapackcompilerflags("-Mrecursive" _MrecursiveFlag)
# Add recursive flag
if(_recursiveFlag)
string(REGEX MATCH "-recursive" output_test <string> "${CMAKE_Fortran_FLAGS}")
if(NOT output_test)
set(CMAKE_Fortran_FLAGS
"${CMAKE_Fortran_FLAGS} -recursive"
CACHE STRING "Recursive flag must be set" FORCE)
endif()
elseif(_frecursiveFlag)
string(REGEX MATCH "-frecursive" output_test <string>
"${CMAKE_Fortran_FLAGS}")
if(NOT output_test)
set(CMAKE_Fortran_FLAGS
"${CMAKE_Fortran_FLAGS} -frecursive"
CACHE STRING "Recursive flag must be set" FORCE)
endif()
elseif(_MrecursiveFlag)
string(REGEX MATCH "-Mrecursive" output_test <string>
"${CMAKE_Fortran_FLAGS}")
if(NOT output_test)
set(CMAKE_Fortran_FLAGS
"${CMAKE_Fortran_FLAGS} -Mrecursive"
CACHE STRING "Recursive flag must be set" FORCE)
endif()
endif()
set(BLAS_LIBRARIES ${BLASLIB})
# ##############################################################################
# This is the makefile to create a library for the BLAS. The files are grouped
# as follows:
#
# SBLAS1 -- Single precision real BLAS routines CBLAS1 -- Single precision
# complex BLAS routines DBLAS1 -- Double precision real BLAS routines ZBLAS1 --
# Double precision complex BLAS routines
#
# CB1AUX -- Real BLAS routines called by complex routines ZB1AUX -- D.P. real
# BLAS routines called by d.p. complex routines
#
# ALLBLAS -- Auxiliary routines for Level 2 and 3 BLAS
#
# SBLAS2 -- Single precision real BLAS2 routines CBLAS2 -- Single precision
# complex BLAS2 routines DBLAS2 -- Double precision real BLAS2 routines ZBLAS2
# -- Double precision complex BLAS2 routines
#
# SBLAS3 -- Single precision real BLAS3 routines CBLAS3 -- Single precision
# complex BLAS3 routines DBLAS3 -- Double precision real BLAS3 routines ZBLAS3
# -- Double precision complex BLAS3 routines
#
# ##############################################################################
# ---------------------------------------------------------
# Level 1 BLAS
# ---------------------------------------------------------
file(GLOB CB1AUX "src/l1/CB1AUX/*")
file(GLOB SBLAS1 "src/l1/SBLAS1/*" ${CB1AUX})
file(GLOB CBLAS1 "src/l1/CBLAS1/*")
file(GLOB ZB1AUX "src/l1/ZB1AUX/*")
file(GLOB DBLAS1 "src/l1/DBLAS1/*" ${ZB1AUX})
file(GLOB ZBLAS1 "src/l1/ZBLAS1/*")
# ---------------------------------------------------------------------
# Auxiliary routines needed by both the Level 2 and Level 3 BLAS
# ---------------------------------------------------------------------
file(GLOB ALLBLAS "src/aux_/*")
# ---------------------------------------------------------
# Level 2 BLAS
# ---------------------------------------------------------
file(GLOB SBLAS2 "src/l2/SBLAS2/*")
file(GLOB CBLAS2 "src/l2/CBLAS2/*")
file(GLOB DBLAS2 "src/l2/DBLAS2/*")
file(GLOB ZBLAS2 "src/l2/ZBLAS2/*")
# ---------------------------------------------------------
# Level 3 BLAS
# ---------------------------------------------------------
file(GLOB SBLAS3 "src/l3/SBLAS3/*")
file(GLOB CBLAS3 "src/l3/CBLAS3/*")
file(GLOB DBLAS3 "src/l3/DBLAS3/*")
file(GLOB ZBLAS3 "src/l3/ZBLAS3/*")
set(SINGLE_SOURCES)
set(DOUBLE_SOURCES)
set(COMPLEX_SOURCES)
set(COMPLEX16_SOURCES)
if(BUILD_SINGLE)
list(APPEND SINGLE_SOURCES ${SBLAS1} ${ALLBLAS} ${SBLAS2} ${SBLAS3})
endif()
if(BUILD_DOUBLE)
list(APPEND DOUBLE_SOURCES ${DBLAS1} ${ALLBLAS} ${DBLAS2} ${DBLAS3})
endif()
if(BUILD_COMPLEX)
list(
APPEND
COMPLEX_SOURCES
${CBLAS1}
${CB1AUX}
${ALLBLAS}
${CBLAS2}
${CBLAS3})
endif()
if(BUILD_COMPLEX16)
list(
APPEND
COMPLEX16_SOURCES
${ZBLAS1}
${ZB1AUX}
${ALLBLAS}
${ZBLAS2}
${ZBLAS3})
endif()
# Include the make.inc file include(${BLAS_SOURCE_DIR}/make.inc)
add_library(${BLASLIB} ${ALLBLAS}) # Add ALLBLAS sources unconditionally
if(BUILD_SINGLE)
target_sources(${BLASLIB} PRIVATE ${SINGLE_SOURCES})
endif()
if(BUILD_DOUBLE)
target_sources(${BLASLIB} PRIVATE ${DOUBLE_SOURCES})
endif()
if(BUILD_COMPLEX)
target_sources(${BLASLIB} PRIVATE ${COMPLEX_SOURCES})
endif()
if(BUILD_COMPLEX16)
target_sources(${BLASLIB} PRIVATE ${COMPLEX16_SOURCES})
endif()
set_target_properties(${BLASLIB} PROPERTIES VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR})
setup_macos_rpath(${BLASLIB})
# Export the library target
install(
TARGETS ${BLASLIB}
EXPORT ${BLAS_INSTALL_EXPORT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
include(CMakePackageConfigHelpers)
# Generate the Config.cmake file
set(CONFIG_INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${BLASLIB}")
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in"
"${PROJECT_BINARY_DIR}/${BLASLIB}-config.cmake"
INSTALL_DESTINATION "${CONFIG_INSTALL_DESTINATION}"
PATH_VARS CMAKE_INSTALL_LIBDIR)
# Generate the ConfigVersion.cmake file
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/${BLASLIB}-config-version.cmake"
VERSION ${BLAS_VERSION}
COMPATIBILITY SameMajorVersion)
# Install the Config.cmake and ConfigVersion.cmake files
install(FILES "${PROJECT_BINARY_DIR}/${BLASLIB}-config.cmake"
"${PROJECT_BINARY_DIR}/${BLASLIB}-config-version.cmake"
DESTINATION "${CONFIG_INSTALL_DESTINATION}")
# Install the export set for the build tree
export(EXPORT ${BLAS_INSTALL_EXPORT_NAME}
FILE "${PROJECT_BINARY_DIR}/${BLASLIB}-targets.cmake")
# Add custom targets for building test executables
add_custom_target(single DEPENDS xblat1s xblat2s xblat3s)
add_custom_target(double DEPENDS xblat1d xblat2d xblat3d)
add_custom_target(complex DEPENDS xblat1c xblat2c xblat3c)
add_custom_target(complex16 DEPENDS xblat1z xblat2z xblat3z)
add_custom_target(build_all DEPENDS single double complex complex16)