33##
44
55cmake_minimum_required (VERSION 2.8.5 )
6- project (OpenBLAS)
6+ project (OpenBLAS C ASM )
77set (OpenBLAS_MAJOR_VERSION 0)
88set (OpenBLAS_MINOR_VERSION 3)
99set (OpenBLAS_PATCH_VERSION 0.dev)
1010set (OpenBLAS_VERSION "${OpenBLAS_MAJOR_VERSION} .${OpenBLAS_MINOR_VERSION} .${OpenBLAS_PATCH_VERSION} " )
1111
12- enable_language (ASM )
13- enable_language (C )
14-
1512# Adhere to GNU filesystem layout conventions
1613include (GNUInstallDirs )
1714
18- if (MSVC )
19- set (OpenBLAS_LIBNAME libopenblas)
20- else ()
2115set (OpenBLAS_LIBNAME openblas)
22- endif ()
2316
2417#######
2518if (MSVC )
2619option (BUILD_WITHOUT_LAPACK "Without LAPACK and LAPACKE (Only BLAS or CBLAS)" ON )
2720endif ()
2821option (BUILD_WITHOUT_CBLAS "Without CBLAS" OFF )
29- option (BUILD_DEBUG "Build Debug Version" OFF )
3022option (DYNAMIC_ARCH "Build with DYNAMIC_ARCH" OFF )
23+ option (BUILD_RELAPACK "Build with ReLAPACK (recursive LAPACK" OFF )
3124#######
3225if (BUILD_WITHOUT_LAPACK)
3326set (NO_LAPACK 1)
3427set (NO_LAPACKE 1)
3528endif ()
3629
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-
5330if (BUILD_WITHOUT_CBLAS)
5431set (NO_CBLAS 1)
5532endif ()
@@ -75,6 +52,9 @@ endif ()
7552set (SUBDIRS ${BLASDIRS} )
7653if (NOT NO_LAPACK)
7754 list (APPEND SUBDIRS lapack)
55+ if (BUILD_RELAPACK)
56+ list (APPEND SUBDIRS relapack/src)
57+ endif ()
7858endif ()
7959
8060# 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_
8666 set (BUILD_COMPLEX16 true )
8767endif ()
8868
69+ if (NOT DEFINED BUILD_MATGEN)
70+ set (BUILD_MATGEN true )
71+ endif ()
72+
8973set (FLOAT_TYPES "" )
9074if (BUILD_SINGLE)
9175 message (STATUS "Building Single Precision" )
@@ -107,19 +91,10 @@ if (BUILD_COMPLEX16)
10791 list (APPEND FLOAT_TYPES "ZCOMPLEX" ) # defines COMPLEX and DOUBLE
10892endif ()
10993
110- set (SUBDIRS_ALL ${SUBDIRS} test ctest utest exports benchmark ../laswp ../bench)
111-
112- # all :: libs netlib tests shared
113-
114- # libs :
11594if (NOT DEFINED CORE OR "${CORE} " STREQUAL "UNKNOWN" )
11695 message (FATAL_ERROR "Detecting CPU failed. Please set TARGET explicitly, e.g. make TARGET=your_cpu_target. Please read README for details." )
11796endif ()
11897
119- if (${NO_STATIC} AND ${NO_SHARED} )
120- message (FATAL_ERROR "Neither static nor shared are enabled." )
121- endif ()
122-
12398#Set default output directory
12499set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} /lib)
125100set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} /lib)
@@ -141,26 +116,20 @@ endforeach ()
141116# Not using add_subdirectory here because lapack-netlib already has its own CMakeLists.txt. Instead include a cmake script with the sources we want.
142117if (NOT NOFORTRAN AND NOT NO_LAPACK)
143118 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 ()
147122endif ()
148123
149124# Only generate .def for dll on MSVC and always produce pdb files for debug and release
150125if (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" )
155131endif ()
156132
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
164133if (${DYNAMIC_ARCH} )
165134 add_subdirectory (kernel )
166135 foreach (TARGET_CORE ${DYNAMIC_CORE} )
@@ -169,98 +138,108 @@ if (${DYNAMIC_ARCH})
169138 endforeach ()
170139endif ()
171140
141+ # Only build shared libs for MSVC
142+ if (MSVC )
143+ set (BUILD_SHARED_LIBS ON )
144+ endif ()
145+
172146
173147# 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 ()
175154
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 ()
177164
178165# Set output for libopenblas
179166set_target_properties ( ${OpenBLAS_LIBNAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} /lib )
180167set_target_properties ( ${OpenBLAS_LIBNAME} PROPERTIES LIBRARY_OUTPUT_NAME_DEBUG "${OpenBLAS_LIBNAME} _d" )
181168
182169foreach (OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
183170 string ( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
184-
171+
185172 set_target_properties ( ${OpenBLAS_LIBNAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR} /lib/${OUTPUTCONFIG} )
186173 set_target_properties ( ${OpenBLAS_LIBNAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR} /lib/${OUTPUTCONFIG} )
187174 set_target_properties ( ${OpenBLAS_LIBNAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR} /lib/${OUTPUTCONFIG} )
188175endforeach ()
189176
190177enable_testing ()
191- add_subdirectory (utest )
192-
193- if (NOT MSVC )
194- #only build shared library for MSVC
195178
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} )
203187endif ()
204188
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 )
209192endif ()
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 ()
210200endif ()
211201
212- set_target_properties (${OpenBLAS_LIBNAME} PROPERTIES
202+ set_target_properties (${OpenBLAS_LIBNAME} PROPERTIES
213203 VERSION ${OpenBLAS_MAJOR_VERSION} .${OpenBLAS_MINOR_VERSION}
214204 SOVERSION ${OpenBLAS_MAJOR_VERSION}
215205)
216206
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-
235207# Install project
236208
237209# Install libraries
238210install (TARGETS ${OpenBLAS_LIBNAME}
239211 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
240212 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
241- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} )
213+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} )
242214
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} " )
245216
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 ()
264243
265244if (NOT NO_CBLAS)
266245 message (STATUS "Generating cblas.h in ${CMAKE_INSTALL_INCLUDEDIR} " )
@@ -276,16 +255,12 @@ if(NOT NO_LAPACKE)
276255 add_dependencies ( ${OpenBLAS_LIBNAME} genlapacke )
277256 FILE (GLOB_RECURSE INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR} /lapack-netlib/LAPACKE/*.h" )
278257 install (FILES ${INCLUDE_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
279-
258+
280259 ADD_CUSTOM_TARGET (genlapacke
281260 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"
282261 )
283262 install (FILES ${CMAKE_BINARY_DIR} /lapacke_mangling.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
284263endif ()
285-
286- if (NOT MSVC )
287- install (TARGETS ${OpenBLAS_LIBNAME} _static DESTINATION ${CMAKE_INSTALL_LIBDIR} )
288- endif ()
289264
290265include (FindPkgConfig QUIET )
291266if (PKG_CONFIG_FOUND)
0 commit comments