3
3
##
4
4
5
5
cmake_minimum_required (VERSION 2.8.5 )
6
- project (OpenBLAS )
6
+ project (OpenBLAS C ASM )
7
7
set (OpenBLAS_MAJOR_VERSION 0 )
8
8
set (OpenBLAS_MINOR_VERSION 3 )
9
9
set (OpenBLAS_PATCH_VERSION 0.dev )
10
10
set (OpenBLAS_VERSION "${OpenBLAS_MAJOR_VERSION} .${OpenBLAS_MINOR_VERSION} .${OpenBLAS_PATCH_VERSION} " )
11
11
12
- enable_language (ASM )
13
- enable_language (C )
14
-
15
12
# Adhere to GNU filesystem layout conventions
16
13
include (GNUInstallDirs )
17
14
18
- if (MSVC )
19
- set (OpenBLAS_LIBNAME libopenblas )
20
- else ()
21
15
set (OpenBLAS_LIBNAME openblas )
22
- endif ()
23
16
24
17
#######
25
18
if (MSVC )
26
19
option (BUILD_WITHOUT_LAPACK "Without LAPACK and LAPACKE (Only BLAS or CBLAS)" ON )
27
20
endif ()
28
21
option (BUILD_WITHOUT_CBLAS "Without CBLAS" OFF )
29
- option (BUILD_DEBUG "Build Debug Version" OFF )
30
22
option (DYNAMIC_ARCH "Build with DYNAMIC_ARCH" OFF )
23
+ option (BUILD_RELAPACK "Build with ReLAPACK (recursive LAPACK" OFF )
31
24
#######
32
25
if (BUILD_WITHOUT_LAPACK )
33
26
set (NO_LAPACK 1 )
34
27
set (NO_LAPACKE 1 )
35
28
endif ()
36
29
37
- if (CMAKE_CONFIGURATION_TYPES ) # multiconfig generator?
38
- set (CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE )
39
- set (CMAKE_BUILD_TYPE
40
- Debug Debug
41
- Release Release
42
- )
43
- else ()
44
- if ( NOT CMAKE_BUILD_TYPE )
45
- if (BUILD_DEBUG )
46
- set (CMAKE_BUILD_TYPE Debug )
47
- else ()
48
- set (CMAKE_BUILD_TYPE Release )
49
- endif ()
50
- endif ()
51
- endif ()
52
-
53
30
if (BUILD_WITHOUT_CBLAS )
54
31
set (NO_CBLAS 1 )
55
32
endif ()
@@ -75,6 +52,9 @@ endif ()
75
52
set (SUBDIRS ${BLASDIRS} )
76
53
if (NOT NO_LAPACK )
77
54
list (APPEND SUBDIRS lapack )
55
+ if (BUILD_RELAPACK )
56
+ list (APPEND SUBDIRS relapack/src )
57
+ endif ()
78
58
endif ()
79
59
80
60
# set which float types we want to build for
@@ -86,6 +66,10 @@ if (NOT DEFINED BUILD_SINGLE AND NOT DEFINED BUILD_DOUBLE AND NOT DEFINED BUILD_
86
66
set (BUILD_COMPLEX16 true )
87
67
endif ()
88
68
69
+ if (NOT DEFINED BUILD_MATGEN )
70
+ set (BUILD_MATGEN true )
71
+ endif ()
72
+
89
73
set (FLOAT_TYPES "" )
90
74
if (BUILD_SINGLE )
91
75
message (STATUS "Building Single Precision" )
@@ -107,19 +91,10 @@ if (BUILD_COMPLEX16)
107
91
list (APPEND FLOAT_TYPES "ZCOMPLEX" ) # defines COMPLEX and DOUBLE
108
92
endif ()
109
93
110
- set (SUBDIRS_ALL ${SUBDIRS} test ctest utest exports benchmark ../laswp ../bench )
111
-
112
- # all :: libs netlib tests shared
113
-
114
- # libs :
115
94
if (NOT DEFINED CORE OR "${CORE} " STREQUAL "UNKNOWN" )
116
95
message (FATAL_ERROR "Detecting CPU failed. Please set TARGET explicitly, e.g. make TARGET=your_cpu_target. Please read README for details." )
117
96
endif ()
118
97
119
- if (${NO_STATIC} AND ${NO_SHARED} )
120
- message (FATAL_ERROR "Neither static nor shared are enabled." )
121
- endif ()
122
-
123
98
#Set default output directory
124
99
set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} /lib )
125
100
set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} /lib )
@@ -141,26 +116,20 @@ endforeach ()
141
116
# Not using add_subdirectory here because lapack-netlib already has its own CMakeLists.txt. Instead include a cmake script with the sources we want.
142
117
if (NOT NOFORTRAN AND NOT NO_LAPACK )
143
118
include ("${PROJECT_SOURCE_DIR} /cmake/lapack.cmake" )
144
- if (NOT NO_LAPACKE )
145
- include ("${PROJECT_SOURCE_DIR} /cmake/lapacke.cmake" )
146
- endif ()
119
+ if (NOT NO_LAPACKE )
120
+ include ("${PROJECT_SOURCE_DIR} /cmake/lapacke.cmake" )
121
+ endif ()
147
122
endif ()
148
123
149
124
# Only generate .def for dll on MSVC and always produce pdb files for debug and release
150
125
if (MSVC )
151
- set (OpenBLAS_DEF_FILE "${PROJECT_BINARY_DIR} /openblas.def" )
152
- set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi" )
153
- set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi" )
154
- set (CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF" )
126
+ if (${CMAKE_MAJOR_VERSION} .${CMAKE_MINOR_VERSION} LESS 3.4 )
127
+ set (OpenBLAS_DEF_FILE "${PROJECT_BINARY_DIR} /openblas.def" )
128
+ endif ()
129
+ set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi" )
130
+ set (CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF" )
155
131
endif ()
156
132
157
- #ifeq ($(DYNAMIC_ARCH), 1)
158
- # @$(MAKE) -C kernel commonlibs || exit 1
159
- # @for d in $(DYNAMIC_CORE) ; \
160
- # do $(MAKE) GOTOBLAS_MAKEFILE= -C kernel TARGET_CORE=$$d kernel || exit 1 ;\
161
- # done
162
- # @echo DYNAMIC_ARCH=1 >> Makefile.conf_last
163
- #endif
164
133
if (${DYNAMIC_ARCH} )
165
134
add_subdirectory (kernel )
166
135
foreach (TARGET_CORE ${DYNAMIC_CORE} )
@@ -169,98 +138,108 @@ if (${DYNAMIC_ARCH})
169
138
endforeach ()
170
139
endif ()
171
140
141
+ # Only build shared libs for MSVC
142
+ if (MSVC )
143
+ set (BUILD_SHARED_LIBS ON )
144
+ endif ()
145
+
172
146
173
147
# add objects to the openblas lib
174
- add_library (${OpenBLAS_LIBNAME} SHARED ${LA_SOURCES} ${LAPACKE_SOURCES} ${TARGET_OBJS} ${OpenBLAS_DEF_FILE} )
148
+ add_library (${OpenBLAS_LIBNAME} ${LA_SOURCES} ${LAPACKE_SOURCES} ${RELA_SOURCES} ${TARGET_OBJS} ${OpenBLAS_DEF_FILE} )
149
+
150
+ # Android needs to explicitly link against libm
151
+ if (ANDROID )
152
+ target_link_libraries (${OpenBLAS_LIBNAME} m )
153
+ endif ()
175
154
176
- include ("${PROJECT_SOURCE_DIR} /cmake/export.cmake" )
155
+ # Handle MSVC exports
156
+ if (MSVC AND BUILD_SHARED_LIBS )
157
+ if (${CMAKE_MAJOR_VERSION} .${CMAKE_MINOR_VERSION} LESS 3.4 )
158
+ include ("${PROJECT_SOURCE_DIR} /cmake/export.cmake" )
159
+ else ()
160
+ # Creates verbose .def file (51KB vs 18KB)
161
+ set_target_properties (${OpenBLAS_LIBNAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS true )
162
+ endif ()
163
+ endif ()
177
164
178
165
# Set output for libopenblas
179
166
set_target_properties ( ${OpenBLAS_LIBNAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} /lib )
180
167
set_target_properties ( ${OpenBLAS_LIBNAME} PROPERTIES LIBRARY_OUTPUT_NAME_DEBUG "${OpenBLAS_LIBNAME} _d" )
181
168
182
169
foreach (OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
183
170
string ( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
184
-
171
+
185
172
set_target_properties ( ${OpenBLAS_LIBNAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR} /lib/${OUTPUTCONFIG} )
186
173
set_target_properties ( ${OpenBLAS_LIBNAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR} /lib/${OUTPUTCONFIG} )
187
174
set_target_properties ( ${OpenBLAS_LIBNAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR} /lib/${OUTPUTCONFIG} )
188
175
endforeach ()
189
176
190
177
enable_testing ()
191
- add_subdirectory (utest )
192
-
193
- if (NOT MSVC )
194
- #only build shared library for MSVC
195
178
196
- add_library (${OpenBLAS_LIBNAME} _static STATIC ${LA_SOURCES} ${LAPACKE_SOURCES} ${TARGET_OBJS} )
197
- set_target_properties (${OpenBLAS_LIBNAME} _static PROPERTIES OUTPUT_NAME ${OpenBLAS_LIBNAME} )
198
- set_target_properties (${OpenBLAS_LIBNAME} _static PROPERTIES CLEAN_DIRECT_OUTPUT 1 )
199
-
200
- if (SMP )
201
- target_link_libraries (${OpenBLAS_LIBNAME} pthread )
202
- target_link_libraries (${OpenBLAS_LIBNAME} _static pthread )
179
+ if (USE_THREAD )
180
+ # Add threading library to linker
181
+ find_package (Threads )
182
+ if (THREADS_HAVE_PTHREAD_ARG )
183
+ set_property (TARGET ${OpenBLAS_LIBNAME} PROPERTY COMPILE_OPTIONS "-pthread" )
184
+ set_property (TARGET ${OpenBLAS_LIBNAME} PROPERTY INTERFACE_COMPILE_OPTIONS "-pthread" )
185
+ endif ()
186
+ target_link_libraries (${OpenBLAS_LIBNAME} ${CMAKE_THREAD_LIBS_INIT} )
203
187
endif ()
204
188
205
- #build test and ctest
206
- add_subdirectory (test )
207
- if (NOT NO_CBLAS )
208
- add_subdirectory (ctest )
189
+ if (MSVC OR NOT NOFORTRAN )
190
+ # Broken without fortran on unix
191
+ add_subdirectory (utest )
209
192
endif ()
193
+
194
+ if (NOT MSVC AND NOT NOFORTRAN )
195
+ # Build test and ctest
196
+ add_subdirectory (test )
197
+ if (NOT NO_CBLAS )
198
+ add_subdirectory (ctest )
199
+ endif ()
210
200
endif ()
211
201
212
- set_target_properties (${OpenBLAS_LIBNAME} PROPERTIES
202
+ set_target_properties (${OpenBLAS_LIBNAME} PROPERTIES
213
203
VERSION ${OpenBLAS_MAJOR_VERSION} .${OpenBLAS_MINOR_VERSION}
214
204
SOVERSION ${OpenBLAS_MAJOR_VERSION}
215
205
)
216
206
217
-
218
- # TODO: Why is the config saved here? Is this necessary with CMake?
219
- #Save the config files for installation
220
- # @cp Makefile.conf Makefile.conf_last
221
- # @cp config.h config_last.h
222
- #ifdef QUAD_PRECISION
223
- # @echo "#define QUAD_PRECISION">> config_last.h
224
- #endif
225
- #ifeq ($(EXPRECISION), 1)
226
- # @echo "#define EXPRECISION">> config_last.h
227
- #endif
228
- ###
229
-
230
- #ifdef USE_THREAD
231
- # @echo USE_THREAD=$(USE_THREAD) >> Makefile.conf_last
232
- #endif
233
- # @touch lib.grd
234
-
235
207
# Install project
236
208
237
209
# Install libraries
238
210
install (TARGETS ${OpenBLAS_LIBNAME}
239
211
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
240
212
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
241
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} )
213
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} )
242
214
243
- # Install include files
244
- set (GENCONFIG_BIN ${CMAKE_BINARY_DIR} /gen_config_h${CMAKE_EXECUTABLE_SUFFIX} )
215
+ message (STATUS "Generating openblas_config.h in ${CMAKE_INSTALL_INCLUDEDIR} " )
245
216
246
- execute_process (COMMAND ${GENCONFIG_BIN}
247
- ${CMAKE_CURRENT_SOURCE_DIR} /config.h
248
- ${CMAKE_CURRENT_SOURCE_DIR} /openblas_config_template.h
249
- OUTPUT_VARIABLE OPENBLAS_CONFIG_H_CONTENTS )
250
-
251
- file (WRITE ${CMAKE_BINARY_DIR} /openblas_config.tmp "${OPENBLAS_CONFIG_H_CONTENTS} " )
252
- configure_file (${CMAKE_BINARY_DIR} /openblas_config.tmp ${CMAKE_BINARY_DIR} /openblas_config.h COPYONLY )
253
-
254
- install (FILES ${CMAKE_BINARY_DIR} /openblas_config.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
255
-
256
- message (STATUS "Generating f77blas.h in ${CMAKE_INSTALL_INCLUDEDIR} " )
257
-
258
- file (WRITE ${CMAKE_BINARY_DIR} /f77blas.h "" )
259
- file (APPEND ${CMAKE_BINARY_DIR} /f77blas.h "#ifndef OPENBLAS_F77BLAS_H\n #define OPENBLAS_F77BLAS_H\n #include \" openblas_config.h\"\n " )
260
- file (READ ${CMAKE_CURRENT_SOURCE_DIR} /common_interface.h COMMON_INTERFACE_H_CONTENTS )
261
- file (APPEND ${CMAKE_BINARY_DIR} /f77blas.h "${COMMON_INTERFACE_H_CONTENTS} " )
262
- file (APPEND ${CMAKE_BINARY_DIR} /f77blas.h "#endif" )
263
- install (FILES ${CMAKE_BINARY_DIR} /f77blas.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
217
+ set (OPENBLAS_CONFIG_H ${CMAKE_BINARY_DIR} /openblas_config.h )
218
+ file (WRITE ${OPENBLAS_CONFIG_H} "#ifndef OPENBLAS_CONFIG_H\n " )
219
+ file (APPEND ${OPENBLAS_CONFIG_H} "#define OPENBLAS_CONFIG_H\n " )
220
+ file (STRINGS ${PROJECT_BINARY_DIR} /config.h __lines )
221
+ foreach (line ${__lines} )
222
+ string (REPLACE "#define " "" line ${line} )
223
+ file (APPEND ${OPENBLAS_CONFIG_H} "#define OPENBLAS_${line} \n " )
224
+ endforeach ()
225
+ file (APPEND ${OPENBLAS_CONFIG_H} "#define OPENBLAS_VERSION \" OpenBLAS ${OpenBLAS_VERSION} \"\n " )
226
+ file (READ ${CMAKE_CURRENT_SOURCE_DIR} /openblas_config_template.h OPENBLAS_CONFIG_TEMPLATE_H_CONTENTS )
227
+ file (APPEND ${OPENBLAS_CONFIG_H} "${OPENBLAS_CONFIG_TEMPLATE_H_CONTENTS} \n " )
228
+ file (APPEND ${OPENBLAS_CONFIG_H} "#endif /* OPENBLAS_CONFIG_H */\n " )
229
+ install (FILES ${OPENBLAS_CONFIG_H} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
230
+
231
+ if (NOT NOFORTRAN )
232
+ message (STATUS "Generating f77blas.h in ${CMAKE_INSTALL_INCLUDEDIR} " )
233
+
234
+ set (F77BLAS_H ${CMAKE_BINARY_DIR} /f77blas.h )
235
+ file (WRITE ${F77BLAS_H} "#ifndef OPENBLAS_F77BLAS_H\n " )
236
+ file (APPEND ${F77BLAS_H} "#define OPENBLAS_F77BLAS_H\n " )
237
+ file (APPEND ${F77BLAS_H} "#include \" openblas_config.h\"\n " )
238
+ file (READ ${CMAKE_CURRENT_SOURCE_DIR} /common_interface.h COMMON_INTERFACE_H_CONTENTS )
239
+ file (APPEND ${F77BLAS_H} "${COMMON_INTERFACE_H_CONTENTS} \n " )
240
+ file (APPEND ${F77BLAS_H} "#endif" )
241
+ install (FILES ${F77BLAS_H} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
242
+ endif ()
264
243
265
244
if (NOT NO_CBLAS )
266
245
message (STATUS "Generating cblas.h in ${CMAKE_INSTALL_INCLUDEDIR} " )
@@ -276,16 +255,12 @@ if(NOT NO_LAPACKE)
276
255
add_dependencies ( ${OpenBLAS_LIBNAME} genlapacke )
277
256
FILE (GLOB_RECURSE INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR} /lapack-netlib/LAPACKE/*.h" )
278
257
install (FILES ${INCLUDE_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
279
-
258
+
280
259
ADD_CUSTOM_TARGET (genlapacke
281
260
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"
282
261
)
283
262
install (FILES ${CMAKE_BINARY_DIR} /lapacke_mangling.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
284
263
endif ()
285
-
286
- if (NOT MSVC )
287
- install (TARGETS ${OpenBLAS_LIBNAME} _static DESTINATION ${CMAKE_INSTALL_LIBDIR} )
288
- endif ()
289
264
290
265
include (FindPkgConfig QUIET )
291
266
if (PKG_CONFIG_FOUND )
0 commit comments