2 ## Author: Hank Anderson <hank@statease.com>
5 cmake_minimum_required(VERSION 2.8.4)
7 set(OpenBLAS_MAJOR_VERSION 0)
8 set(OpenBLAS_MINOR_VERSION 2)
9 set(OpenBLAS_PATCH_VERSION 19.dev)
10 set(OpenBLAS_VERSION "${OpenBLAS_MAJOR_VERSION}.${OpenBLAS_MINOR_VERSION}.${OpenBLAS_PATCH_VERSION}")
16 set(OpenBLAS_LIBNAME libopenblas)
18 set(OpenBLAS_LIBNAME openblas)
23 option(BUILD_WITHOUT_LAPACK "Without LAPACK and LAPACKE (Only BLAS or CBLAS)" ON)
25 option(BUILD_WITHOUT_CBLAS "Without CBLAS" OFF)
26 option(BUILD_DEBUG "Build Debug Version" OFF)
28 if(BUILD_WITHOUT_LAPACK)
34 set(CMAKE_BUILD_TYPE Debug)
36 set(CMAKE_BUILD_TYPE Release)
39 if(BUILD_WITHOUT_CBLAS)
46 message(WARNING "CMake support is experimental. This will not produce the same Makefiles that OpenBLAS ships with. Only x86 support is currently available.")
48 include("${PROJECT_SOURCE_DIR}/cmake/utils.cmake")
49 include("${PROJECT_SOURCE_DIR}/cmake/system.cmake")
51 set(BLASDIRS interface driver/level2 driver/level3 driver/others)
54 list(APPEND BLASDIRS kernel)
57 if (DEFINED SANITY_CHECK)
58 list(APPEND BLASDIRS reference)
61 set(SUBDIRS ${BLASDIRS})
63 list(APPEND SUBDIRS lapack)
66 # set which float types we want to build for
67 if (NOT DEFINED BUILD_SINGLE AND NOT DEFINED BUILD_DOUBLE AND NOT DEFINED BUILD_COMPLEX AND NOT DEFINED BUILD_COMPLEX16)
68 # if none are defined, build for all
69 set(BUILD_SINGLE true)
70 set(BUILD_DOUBLE true)
71 set(BUILD_COMPLEX true)
72 set(BUILD_COMPLEX16 true)
77 message(STATUS "Building Single Precision")
78 list(APPEND FLOAT_TYPES "SINGLE") # defines nothing
82 message(STATUS "Building Double Precision")
83 list(APPEND FLOAT_TYPES "DOUBLE") # defines DOUBLE
87 message(STATUS "Building Complex Precision")
88 list(APPEND FLOAT_TYPES "COMPLEX") # defines COMPLEX
92 message(STATUS "Building Double Complex Precision")
93 list(APPEND FLOAT_TYPES "ZCOMPLEX") # defines COMPLEX and DOUBLE
96 set(SUBDIRS_ALL ${SUBDIRS} test ctest utest exports benchmark ../laswp ../bench)
98 # all :: libs netlib tests shared
101 if (NOT DEFINED CORE OR "${CORE}" STREQUAL "UNKNOWN")
102 message(FATAL_ERROR "Detecting CPU failed. Please set TARGET explicitly, e.g. make TARGET=your_cpu_target. Please read README for details.")
105 if (${NO_STATIC} AND ${NO_SHARED})
106 message(FATAL_ERROR "Neither static nor shared are enabled.")
109 #Set default output directory
110 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib )
111 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib )
113 # get obj vars into format that add_library likes: $<TARGET_OBJS:objlib> (see http://www.cmake.org/cmake/help/v3.0/command/add_library.html)
115 foreach (SUBDIR ${SUBDIRS})
116 add_subdirectory(${SUBDIR})
117 string(REPLACE "/" "_" subdir_obj ${SUBDIR})
118 list(APPEND TARGET_OBJS "$<TARGET_OBJECTS:${subdir_obj}>")
123 # Can't just use lapack-netlib's CMake files, since they are set up to search for BLAS, build and install a binary. We just want to build a couple of lib files out of lapack and lapacke.
124 # Not using add_subdirectory here because lapack-netlib already has its own CMakeLists.txt. Instead include a cmake script with the sources we want.
125 if (NOT NOFORTRAN AND NOT NO_LAPACK)
126 include("${PROJECT_SOURCE_DIR}/cmake/lapack.cmake")
128 include("${PROJECT_SOURCE_DIR}/cmake/lapacke.cmake")
132 #Only generate .def for dll on MSVC
134 set(OpenBLAS_DEF_FILE "${PROJECT_BINARY_DIR}/openblas.def")
137 # add objects to the openblas lib
138 add_library(${OpenBLAS_LIBNAME} SHARED ${LA_SOURCES} ${LAPACKE_SOURCES} ${TARGET_OBJS} ${OpenBLAS_DEF_FILE})
140 include("${PROJECT_SOURCE_DIR}/cmake/export.cmake")
142 # Set output for libopenblas
143 set_target_properties( ${OpenBLAS_LIBNAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
144 foreach (OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
145 string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
146 set_target_properties( ${OpenBLAS_LIBNAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR}/lib)
147 set_target_properties( ${OpenBLAS_LIBNAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR}/lib)
148 set_target_properties( ${OpenBLAS_LIBNAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR}/lib)
152 add_subdirectory(utest)
155 #only build shared library for MSVC
156 add_library(${OpenBLAS_LIBNAME}_static STATIC ${LA_SOURCES} ${LAPACKE_SOURCES} ${TARGET_OBJS})
157 set_target_properties(${OpenBLAS_LIBNAME}_static PROPERTIES OUTPUT_NAME ${OpenBLAS_LIBNAME})
158 set_target_properties(${OpenBLAS_LIBNAME}_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
161 target_link_libraries(${OpenBLAS_LIBNAME} pthread)
162 target_link_libraries(${OpenBLAS_LIBNAME}_static pthread)
165 #build test and ctest
166 add_subdirectory(test)
168 add_subdirectory(ctest)
172 set_target_properties(${OpenBLAS_LIBNAME} PROPERTIES
173 VERSION ${OpenBLAS_MAJOR_VERSION}.${OpenBLAS_MINOR_VERSION}
174 SOVERSION ${OpenBLAS_MAJOR_VERSION}
178 # TODO: Why is the config saved here? Is this necessary with CMake?
179 #Save the config files for installation
180 # @cp Makefile.conf Makefile.conf_last
181 # @cp config.h config_last.h
182 #ifdef QUAD_PRECISION
183 # @echo "#define QUAD_PRECISION">> config_last.h
185 #ifeq ($(EXPRECISION), 1)
186 # @echo "#define EXPRECISION">> config_last.h
189 #ifeq ($(DYNAMIC_ARCH), 1)
190 # @$(MAKE) -C kernel commonlibs || exit 1
191 # @for d in $(DYNAMIC_CORE) ; \
192 # do $(MAKE) GOTOBLAS_MAKEFILE= -C kernel TARGET_CORE=$$d kernel || exit 1 ;\
194 # @echo DYNAMIC_ARCH=1 >> Makefile.conf_last
197 # @echo USE_THREAD=$(USE_THREAD) >> Makefile.conf_last