@@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 2.8.5)
6
6
project (OpenBLAS C ASM )
7
7
set (OpenBLAS_MAJOR_VERSION 0 )
8
8
set (OpenBLAS_MINOR_VERSION 3 )
9
- set (OpenBLAS_PATCH_VERSION 3 .dev )
9
+ set (OpenBLAS_PATCH_VERSION 6 .dev )
10
10
set (OpenBLAS_VERSION "${OpenBLAS_MAJOR_VERSION} .${OpenBLAS_MINOR_VERSION} .${OpenBLAS_PATCH_VERSION} " )
11
11
12
12
# Adhere to GNU filesystem layout conventions
@@ -15,16 +15,21 @@ include(GNUInstallDirs)
15
15
include (CMakePackageConfigHelpers )
16
16
17
17
18
- set (OpenBLAS_LIBNAME openblas )
19
-
20
18
#######
21
19
if (MSVC )
22
- option (BUILD_WITHOUT_LAPACK "Without LAPACK and LAPACKE (Only BLAS or CBLAS)" ON )
20
+ option (BUILD_WITHOUT_LAPACK "Do not build LAPACK and LAPACKE (Only BLAS or CBLAS)" ON )
23
21
endif ()
24
- option (BUILD_WITHOUT_CBLAS "Without CBLAS" OFF )
25
- option (DYNAMIC_ARCH "Build with DYNAMIC_ARCH" OFF )
26
- option (DYNAMIC_OLDER "Support older cpus with DYNAMIC_ARCH" OFF )
27
- option (BUILD_RELAPACK "Build with ReLAPACK (recursive LAPACK" OFF )
22
+ option (BUILD_WITHOUT_CBLAS "Do not build the C interface (CBLAS) to the BLAS functions" OFF )
23
+ option (DYNAMIC_ARCH "Include support for multiple CPU targets, with automatic selection at runtime (x86/x86_64 only)" OFF )
24
+ option (DYNAMIC_OLDER "Include specific support for older cpu models (Penryn,Dunnington,Atom,Nano,Opteron) with DYNAMIC_ARCH" OFF )
25
+ option (BUILD_RELAPACK "Build with ReLAPACK (recursive implementation of several LAPACK functions on top of standard LAPACK)" OFF )
26
+
27
+ # Add a prefix or suffix to all exported symbol names in the shared library.
28
+ # Avoids conflicts with other BLAS libraries, especially when using
29
+ # 64 bit integer interfaces in OpenBLAS.
30
+
31
+ set (SYMBOLPREFIX "" CACHE STRING "Add a prefix to all exported symbol names in the shared library to avoid conflicts with other BLAS libraries" )
32
+ set (SYMBOLSUFFIX "" CACHE STRING "Add a suffix to all exported symbol names in the shared library, e.g. _64 for INTERFACE64 builds" )
28
33
#######
29
34
if (BUILD_WITHOUT_LAPACK )
30
35
set (NO_LAPACK 1 )
@@ -37,12 +42,27 @@ endif()
37
42
38
43
#######
39
44
45
+ if (MSVC AND MSVC_STATIC_CRT )
46
+ set (CompilerFlags
47
+ CMAKE_CXX_FLAGS
48
+ CMAKE_CXX_FLAGS_DEBUG
49
+ CMAKE_CXX_FLAGS_RELEASE
50
+ CMAKE_C_FLAGS
51
+ CMAKE_C_FLAGS_DEBUG
52
+ CMAKE_C_FLAGS_RELEASE
53
+ )
54
+ foreach (CompilerFlag ${CompilerFlags} )
55
+ string (REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag} }" )
56
+ endforeach ()
57
+ endif ()
40
58
41
- message (WARNING "CMake support is experimental. This will not produce the same Makefiles that OpenBLAS ships with. Only x86 support is currently available ." )
59
+ message (WARNING "CMake support is experimental. It does not yet support all build options and may not produce the same Makefiles that OpenBLAS ships with." )
42
60
43
61
include ("${PROJECT_SOURCE_DIR} /cmake/utils.cmake" )
44
62
include ("${PROJECT_SOURCE_DIR} /cmake/system.cmake" )
45
63
64
+ set (OpenBLAS_LIBNAME openblas${SUFFIX64_UNDERSCORE} )
65
+
46
66
set (BLASDIRS interface driver/level2 driver/level3 driver/others )
47
67
48
68
if (NOT DYNAMIC_ARCH )
@@ -127,7 +147,7 @@ endif ()
127
147
128
148
# Only generate .def for dll on MSVC and always produce pdb files for debug and release
129
149
if (MSVC )
130
- if (${CMAKE_MAJOR_VERSION} .${CMAKE_MINOR_VERSION} LESS 3.4 )
150
+ if (${CMAKE_MAJOR_VERSION} .${CMAKE_MINOR_VERSION} VERSION_LESS 3.4 )
131
151
set (OpenBLAS_DEF_FILE "${PROJECT_BINARY_DIR} /openblas.def" )
132
152
endif ()
133
153
set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi" )
@@ -142,15 +162,9 @@ if (${DYNAMIC_ARCH})
142
162
endforeach ()
143
163
endif ()
144
164
145
- # Only build shared libs for MSVC
146
- if (MSVC )
147
- set (BUILD_SHARED_LIBS ON )
148
- endif ()
149
-
150
-
151
165
# add objects to the openblas lib
152
166
add_library (${OpenBLAS_LIBNAME} ${LA_SOURCES} ${LAPACKE_SOURCES} ${RELA_SOURCES} ${TARGET_OBJS} ${OpenBLAS_DEF_FILE} )
153
- target_include_directories (${OpenBLAS_LIBNAME} INTERFACE $< INSTALL_INTERFACE:include> )
167
+ target_include_directories (${OpenBLAS_LIBNAME} INTERFACE $< INSTALL_INTERFACE:include/openblas ${SUFFIX64} > )
154
168
155
169
# Android needs to explicitly link against libm
156
170
if (ANDROID )
@@ -159,7 +173,7 @@ endif()
159
173
160
174
# Handle MSVC exports
161
175
if (MSVC AND BUILD_SHARED_LIBS )
162
- if (${CMAKE_MAJOR_VERSION} .${CMAKE_MINOR_VERSION} LESS 3.4 )
176
+ if (${CMAKE_MAJOR_VERSION} .${CMAKE_MINOR_VERSION} VERSION_LESS 3.4 )
163
177
include ("${PROJECT_SOURCE_DIR} /cmake/export.cmake" )
164
178
else ()
165
179
# Creates verbose .def file (51KB vs 18KB)
@@ -210,15 +224,84 @@ set_target_properties(${OpenBLAS_LIBNAME} PROPERTIES
210
224
SOVERSION ${OpenBLAS_MAJOR_VERSION}
211
225
)
212
226
227
+ if (BUILD_SHARED_LIBS AND NOT ${SYMBOLPREFIX}${SYMBOLSUFIX} STREQUAL "" )
228
+ if (NOT DEFINED ARCH )
229
+ set (ARCH_IN "x86_64" )
230
+ else ()
231
+ set (ARCH_IN ${ARCH} )
232
+ endif ()
233
+
234
+ if (${CORE} STREQUAL "generic" )
235
+ set (ARCH_IN "GENERIC" )
236
+ endif ()
237
+
238
+ if (NOT DEFINED EXPRECISION )
239
+ set (EXPRECISION_IN 0 )
240
+ else ()
241
+ set (EXPRECISION_IN ${EXPRECISION} )
242
+ endif ()
243
+
244
+ if (NOT DEFINED NO_CBLAS )
245
+ set (NO_CBLAS_IN 0 )
246
+ else ()
247
+ set (NO_CBLAS_IN ${NO_CBLAS} )
248
+ endif ()
249
+
250
+ if (NOT DEFINED NO_LAPACK )
251
+ set (NO_LAPACK_IN 0 )
252
+ else ()
253
+ set (NO_LAPACK_IN ${NO_LAPACK} )
254
+ endif ()
255
+
256
+ if (NOT DEFINED NO_LAPACKE )
257
+ set (NO_LAPACKE_IN 0 )
258
+ else ()
259
+ set (NO_LAPACKE_IN ${NO_LAPACKE} )
260
+ endif ()
261
+
262
+ if (NOT DEFINED NEED2UNDERSCORES )
263
+ set (NEED2UNDERSCORES_IN 0 )
264
+ else ()
265
+ set (NEED2UNDERSCORES_IN ${NEED2UNDERSCORES} )
266
+ endif ()
267
+
268
+ if (NOT DEFINED ONLY_CBLAS )
269
+ set (ONLY_CBLAS_IN 0 )
270
+ else ()
271
+ set (ONLY_CBLAS_IN ${ONLY_CBLAS} )
272
+ endif ()
273
+
274
+ if (NOT DEFINED BU )
275
+ set (BU _ )
276
+ endif ()
277
+
278
+ if (NOT ${SYMBOLPREFIX} STREQUAL "" )
279
+ message (STATUS "adding prefix ${SYMBOLPREFIX} to names of exported symbols in ${OpenBLAS_LIBNAME} " )
280
+ endif ()
281
+ if (NOT ${SYMBOLSUFFIX} STREQUAL "" )
282
+ message (STATUS "adding suffix ${SYMBOLSUFFIX} to names of exported symbols in ${OpenBLAS_LIBNAME} " )
283
+ endif ()
284
+ add_custom_command (TARGET ${OpenBLAS_LIBNAME} POST_BUILD
285
+ COMMAND perl ${PROJECT_SOURCE_DIR} /exports/gensymbol "objcopy" "${ARCH} " "${BU} " "${EXPRECISION_IN} " "${NO_CBLAS_IN} " "${NO_LAPACK_IN} " "${NO_LAPACKE_IN} " "${NEED2UNDERSCORES_IN} " "${ONLY_CBLAS_IN} " \"${SYMBOLPREFIX} \" \" ${SYMBOLSUFFIX} \" " ${BUILD_LAPACK_DEPRECATED} " > ${PROJECT_BINARY_DIR} /objcopy.def
286
+ COMMAND objcopy -v --redefine-syms ${PROJECT_BINARY_DIR} /objcopy.def ${PROJECT_BINARY_DIR} /lib/lib${OpenBLAS_LIBNAME} .so
287
+ COMMENT " renaming symbols "
288
+ )
289
+ endif()
290
+
291
+
213
292
# Install project
214
293
215
294
# Install libraries
216
295
install(TARGETS ${OpenBLAS_LIBNAME}
217
- EXPORT "OpenBLASTargets "
296
+ EXPORT " OpenBLAS${SUFFIX64}Targets "
218
297
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
219
298
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
220
299
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} )
221
300
301
+ # Install headers
302
+ set(CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR} /openblas${SUFFIX64} )
303
+ set(CMAKE_INSTALL_FULL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX} /${CMAKE_INSTALL_INCLUDEDIR} )
304
+
222
305
message(STATUS " Generating openblas_config.h in ${CMAKE_INSTALL_INCLUDEDIR} ")
223
306
224
307
set(OPENBLAS_CONFIG_H ${CMAKE_BINARY_DIR} /openblas_config.h)
@@ -238,7 +321,7 @@ install (FILES ${OPENBLAS_CONFIG_H} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
238
321
if (NOT NOFORTRAN )
239
322
message (STATUS "Generating f77blas.h in ${CMAKE_INSTALL_INCLUDEDIR} " )
240
323
241
- set (F77BLAS_H ${CMAKE_BINARY_DIR} /f77blas.h )
324
+ set (F77BLAS_H ${CMAKE_BINARY_DIR} /generated/ f77blas.h )
242
325
file (WRITE ${F77BLAS_H} "#ifndef OPENBLAS_F77BLAS_H\n " )
243
326
file (APPEND ${F77BLAS_H} "#define OPENBLAS_F77BLAS_H\n " )
244
327
file (APPEND ${F77BLAS_H} "#include \" openblas_config.h\"\n " )
@@ -251,10 +334,11 @@ endif()
251
334
if (NOT NO_CBLAS )
252
335
message (STATUS "Generating cblas.h in ${CMAKE_INSTALL_INCLUDEDIR} " )
253
336
337
+ set (CBLAS_H ${CMAKE_BINARY_DIR} /generated/cblas.h )
254
338
file (READ ${CMAKE_CURRENT_SOURCE_DIR} /cblas.h CBLAS_H_CONTENTS )
255
339
string (REPLACE "common" "openblas_config" CBLAS_H_CONTENTS_NEW "${CBLAS_H_CONTENTS} " )
256
- file (WRITE ${CMAKE_BINARY_DIR} /cblas.tmp "${CBLAS_H_CONTENTS_NEW} " )
257
- install (FILES ${CMAKE_BINARY_DIR} /cblas.tmp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} RENAME cblas.h )
340
+ file (WRITE ${CBLAS_H} "${CBLAS_H_CONTENTS_NEW} " )
341
+ install (FILES ${CBLAS_H} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
258
342
endif ()
259
343
260
344
if (NOT NO_LAPACKE )
@@ -266,29 +350,31 @@ if(NOT NO_LAPACKE)
266
350
ADD_CUSTOM_TARGET (genlapacke
267
351
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR} /lapack-netlib/LAPACKE/include/lapacke_mangling_with_flags.h.in "${CMAKE_BINARY_DIR} /lapacke_mangling.h"
268
352
)
269
- install (FILES ${CMAKE_BINARY_DIR} /lapacke_mangling.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
353
+ install (FILES ${CMAKE_BINARY_DIR} /lapacke_mangling.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} /openblas${SUFFIX64} )
270
354
endif ()
271
355
272
356
include (FindPkgConfig QUIET )
273
357
if (PKG_CONFIG_FOUND )
274
- configure_file (${PROJECT_SOURCE_DIR} /cmake/openblas.pc.in ${PROJECT_BINARY_DIR} /openblas.pc @ONLY )
275
- install (FILES ${PROJECT_BINARY_DIR} /openblas.pc DESTINATION ${CMAKE_INSTALL_LIBDIR} /pkgconfig/ )
358
+ configure_file (${PROJECT_SOURCE_DIR} /cmake/openblas.pc.in ${PROJECT_BINARY_DIR} /openblas${SUFFIX64} .pc @ONLY )
359
+ install (FILES ${PROJECT_BINARY_DIR} /openblas${SUFFIX64} .pc DESTINATION ${CMAKE_INSTALL_LIBDIR} /pkgconfig/ )
276
360
endif ()
277
361
278
362
279
363
# GNUInstallDirs "DATADIR" wrong here; CMake search path wants "share".
280
364
set (PN OpenBLAS )
281
- set (CMAKECONFIG_INSTALL_DIR "share/cmake/${PN} " )
365
+ set (CMAKECONFIG_INSTALL_DIR "share/cmake/${PN}${SUFFIX64} " )
282
366
configure_package_config_file (cmake/${PN}Config.cmake.in
283
- "${CMAKE_CURRENT_BINARY_DIR} /${PN} Config.cmake"
367
+ "${CMAKE_CURRENT_BINARY_DIR} /${PN}${SUFFIX64} Config.cmake"
284
368
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} )
285
369
write_basic_package_version_file (${CMAKE_CURRENT_BINARY_DIR} /${PN}ConfigVersion.cmake
286
370
VERSION ${${PN}_VERSION}
287
371
COMPATIBILITY AnyNewerVersion )
288
- install (FILES ${CMAKE_CURRENT_BINARY_DIR} /${PN}Config.cmake
289
- ${CMAKE_CURRENT_BINARY_DIR} /${PN}ConfigVersion.cmake
372
+ install (FILES ${CMAKE_CURRENT_BINARY_DIR} /${PN}${SUFFIX64}Config.cmake
373
+ DESTINATION ${CMAKECONFIG_INSTALL_DIR} )
374
+ install (FILES ${CMAKE_CURRENT_BINARY_DIR} /${PN}ConfigVersion.cmake
375
+ RENAME ${PN}${SUFFIX64} ConfigVersion.cmake
290
376
DESTINATION ${CMAKECONFIG_INSTALL_DIR} )
291
- install (EXPORT "${PN} Targets"
292
- NAMESPACE "${PN} ::"
377
+ install (EXPORT "${PN}${SUFFIX64} Targets"
378
+ NAMESPACE "${PN}${SUFFIX64} ::"
293
379
DESTINATION ${CMAKECONFIG_INSTALL_DIR} )
294
380
0 commit comments