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
@@ -26,30 +23,13 @@ if(MSVC)
26
23
option (BUILD_WITHOUT_LAPACK "Without LAPACK and LAPACKE (Only BLAS or CBLAS)" ON )
27
24
endif ()
28
25
option (BUILD_WITHOUT_CBLAS "Without CBLAS" OFF )
29
- option (BUILD_DEBUG "Build Debug Version" OFF )
30
26
option (DYNAMIC_ARCH "Build with DYNAMIC_ARCH" OFF )
31
27
#######
32
28
if (BUILD_WITHOUT_LAPACK )
33
29
set (NO_LAPACK 1 )
34
30
set (NO_LAPACKE 1 )
35
31
endif ()
36
32
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
33
if (BUILD_WITHOUT_CBLAS )
54
34
set (NO_CBLAS 1 )
55
35
endif ()
@@ -107,19 +87,10 @@ if (BUILD_COMPLEX16)
107
87
list (APPEND FLOAT_TYPES "ZCOMPLEX" ) # defines COMPLEX and DOUBLE
108
88
endif ()
109
89
110
- set (SUBDIRS_ALL ${SUBDIRS} test ctest utest exports benchmark ../laswp ../bench )
111
-
112
- # all :: libs netlib tests shared
113
-
114
- # libs :
115
90
if (NOT DEFINED CORE OR "${CORE} " STREQUAL "UNKNOWN" )
116
91
message (FATAL_ERROR "Detecting CPU failed. Please set TARGET explicitly, e.g. make TARGET=your_cpu_target. Please read README for details." )
117
92
endif ()
118
93
119
- if (${NO_STATIC} AND ${NO_SHARED} )
120
- message (FATAL_ERROR "Neither static nor shared are enabled." )
121
- endif ()
122
-
123
94
#Set default output directory
124
95
set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} /lib )
125
96
set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} /lib )
@@ -141,26 +112,20 @@ endforeach ()
141
112
# 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
113
if (NOT NOFORTRAN AND NOT NO_LAPACK )
143
114
include ("${PROJECT_SOURCE_DIR} /cmake/lapack.cmake" )
144
- if (NOT NO_LAPACKE )
145
- include ("${PROJECT_SOURCE_DIR} /cmake/lapacke.cmake" )
146
- endif ()
115
+ if (NOT NO_LAPACKE )
116
+ include ("${PROJECT_SOURCE_DIR} /cmake/lapacke.cmake" )
117
+ endif ()
147
118
endif ()
148
119
149
120
# Only generate .def for dll on MSVC and always produce pdb files for debug and release
150
121
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" )
122
+ if (${CMAKE_MAJOR_VERSION} .${CMAKE_MINOR_VERSION} LESS 3.4 )
123
+ set (OpenBLAS_DEF_FILE "${PROJECT_BINARY_DIR} /openblas.def" )
124
+ endif ()
125
+ set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi" )
126
+ set (CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF" )
155
127
endif ()
156
128
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
129
if (${DYNAMIC_ARCH} )
165
130
add_subdirectory (kernel )
166
131
foreach (TARGET_CORE ${DYNAMIC_CORE} )
@@ -169,11 +134,24 @@ if (${DYNAMIC_ARCH})
169
134
endforeach ()
170
135
endif ()
171
136
137
+ # Only build shared libs for MSVC
138
+ if (MSVC )
139
+ set (BUILD_SHARED_LIBS ON )
140
+ endif ()
172
141
173
- # add objects to the openblas lib
174
- add_library (${OpenBLAS_LIBNAME} SHARED ${LA_SOURCES} ${LAPACKE_SOURCES} ${TARGET_OBJS} ${OpenBLAS_DEF_FILE} )
175
142
176
- include ("${PROJECT_SOURCE_DIR} /cmake/export.cmake" )
143
+ # add objects to the openblas lib
144
+ add_library (${OpenBLAS_LIBNAME} ${LA_SOURCES} ${LAPACKE_SOURCES} ${TARGET_OBJS} ${OpenBLAS_DEF_FILE} )
145
+
146
+ # Handle MSVC exports
147
+ if (MSVC AND BUILD_SHARED_LIBS )
148
+ if (${CMAKE_MAJOR_VERSION} .${CMAKE_MINOR_VERSION} LESS 3.4 )
149
+ include ("${PROJECT_SOURCE_DIR} /cmake/export.cmake" )
150
+ else ()
151
+ # Creates verbose .def file (51KB vs 18KB)
152
+ set_target_properties (${OpenBLAS_LIBNAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS true )
153
+ endif ()
154
+ endif ()
177
155
178
156
# Set output for libopenblas
179
157
set_target_properties ( ${OpenBLAS_LIBNAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} /lib )
@@ -188,79 +166,71 @@ foreach (OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
188
166
endforeach ()
189
167
190
168
enable_testing ()
191
- add_subdirectory (utest )
192
-
193
- if (NOT MSVC )
194
- #only build shared library for MSVC
195
-
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
169
200
- if (SMP )
201
- target_link_libraries (${OpenBLAS_LIBNAME} pthread )
202
- target_link_libraries (${OpenBLAS_LIBNAME} _static pthread )
170
+ if (USE_THREAD )
171
+ # Add threading library to linker
172
+ find_package (Threads )
173
+ if (THREADS_HAVE_PTHREAD_ARG )
174
+ set_property (TARGET ${OpenBLAS_LIBNAME} PROPERTY COMPILE_OPTIONS "-pthread" )
175
+ set_property (TARGET ${OpenBLAS_LIBNAME} PROPERTY INTERFACE_COMPILE_OPTIONS "-pthread" )
176
+ endif ()
177
+ target_link_libraries (${OpenBLAS_LIBNAME} ${CMAKE_THREAD_LIBS_INIT} )
203
178
endif ()
204
179
205
- #build test and ctest
206
- add_subdirectory (test )
207
- if (NOT NO_CBLAS )
208
- add_subdirectory (ctest )
180
+ if (MSVC OR NOT NOFORTRAN )
181
+ # Broken without fortran on unix
182
+ add_subdirectory (utest )
209
183
endif ()
184
+
185
+ if (NOT MSVC AND NOT NOFORTRAN )
186
+ # Build test and ctest
187
+ add_subdirectory (test )
188
+ if (NOT NO_CBLAS )
189
+ add_subdirectory (ctest )
190
+ endif ()
210
191
endif ()
211
192
212
193
set_target_properties (${OpenBLAS_LIBNAME} PROPERTIES
213
194
VERSION ${OpenBLAS_MAJOR_VERSION} .${OpenBLAS_MINOR_VERSION}
214
195
SOVERSION ${OpenBLAS_MAJOR_VERSION}
215
196
)
216
197
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
198
# Install project
236
199
237
200
# Install libraries
238
201
install (TARGETS ${OpenBLAS_LIBNAME}
239
202
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
240
203
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
241
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} )
242
-
243
- # Install include files
244
- set (GENCONFIG_BIN ${CMAKE_BINARY_DIR} /gen_config_h${CMAKE_EXECUTABLE_SUFFIX} )
245
-
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} )
204
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} )
205
+
206
+ message (STATUS "Generating openblas_config.h in ${CMAKE_INSTALL_INCLUDEDIR} " )
207
+
208
+ set (OPENBLAS_CONFIG_H ${CMAKE_BINARY_DIR} /openblas_config.h )
209
+ file (WRITE ${OPENBLAS_CONFIG_H} "#ifndef OPENBLAS_CONFIG_H\n " )
210
+ file (APPEND ${OPENBLAS_CONFIG_H} "#define OPENBLAS_CONFIG_H\n " )
211
+ file (STRINGS ${PROJECT_BINARY_DIR} /config.h __lines )
212
+ foreach (line ${__lines} )
213
+ string (REPLACE "#define " "" line ${line} )
214
+ file (APPEND ${OPENBLAS_CONFIG_H} "#define OPENBLAS_${line} \n " )
215
+ endforeach ()
216
+ file (APPEND ${OPENBLAS_CONFIG_H} "#define OPENBLAS_VERSION \" OpenBLAS ${OpenBLAS_VERSION} \"\n " )
217
+ file (READ ${CMAKE_CURRENT_SOURCE_DIR} /openblas_config_template.h OPENBLAS_CONFIG_TEMPLATE_H_CONTENTS )
218
+ file (APPEND ${OPENBLAS_CONFIG_H} "${OPENBLAS_CONFIG_TEMPLATE_H_CONTENTS} \n " )
219
+ file (APPEND ${OPENBLAS_CONFIG_H} "#endif /* OPENBLAS_CONFIG_H */\n " )
220
+ install (FILES ${OPENBLAS_CONFIG_H} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
221
+
222
+ if (NOT NOFORTRAN )
223
+ message (STATUS "Generating f77blas.h in ${CMAKE_INSTALL_INCLUDEDIR} " )
224
+
225
+ set (F77BLAS_H ${CMAKE_BINARY_DIR} /f77blas.h )
226
+ file (WRITE ${F77BLAS_H} "#ifndef OPENBLAS_F77BLAS_H\n " )
227
+ file (APPEND ${F77BLAS_H} "#define OPENBLAS_F77BLAS_H\n " )
228
+ file (APPEND ${F77BLAS_H} "#include \" openblas_config.h\"\n " )
229
+ file (READ ${CMAKE_CURRENT_SOURCE_DIR} /common_interface.h COMMON_INTERFACE_H_CONTENTS )
230
+ file (APPEND ${F77BLAS_H} "${COMMON_INTERFACE_H_CONTENTS} \n " )
231
+ file (APPEND ${F77BLAS_H} "#endif" )
232
+ install (FILES ${F77BLAS_H} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
233
+ endif ()
264
234
265
235
if (NOT NO_CBLAS )
266
236
message (STATUS "Generating cblas.h in ${CMAKE_INSTALL_INCLUDEDIR} " )
@@ -282,10 +252,6 @@ if(NOT NO_LAPACKE)
282
252
)
283
253
install (FILES ${CMAKE_BINARY_DIR} /lapacke_mangling.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
284
254
endif ()
285
-
286
- if (NOT MSVC )
287
- install (TARGETS ${OpenBLAS_LIBNAME} _static DESTINATION ${CMAKE_INSTALL_LIBDIR} )
288
- endif ()
289
255
290
256
include (FindPkgConfig QUIET )
291
257
if (PKG_CONFIG_FOUND )
0 commit comments