f5dfb818722c654b03f273f194ed31edfde5bffb
[platform/upstream/openblas.git] / CMakeLists.txt
1 ##
2 ## Author: Hank Anderson <hank@statease.com>
3 ##
4
5 cmake_minimum_required(VERSION 2.8.4)
6 project(OpenBLAS)
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}")
11
12 enable_language(ASM)
13 enable_language(C)
14
15 if(MSVC)
16 set(OpenBLAS_LIBNAME libopenblas)
17 else()
18 set(OpenBLAS_LIBNAME openblas)
19 endif()
20
21 #######
22 if(MSVC)
23 option(BUILD_WITHOUT_LAPACK "Without LAPACK and LAPACKE (Only BLAS or CBLAS)" ON)
24 endif()
25 option(BUILD_WITHOUT_CBLAS "Without CBLAS" OFF)
26 option(BUILD_DEBUG "Build Debug Version" OFF)
27 #######
28 if(BUILD_WITHOUT_LAPACK)
29 set(NO_LAPACK 1)
30 set(NO_LAPACKE 1)
31 endif()
32
33 if(BUILD_DEBUG)
34 set(CMAKE_BUILD_TYPE Debug)
35 else()
36 set(CMAKE_BUILD_TYPE Release)
37 endif()
38
39 if(BUILD_WITHOUT_CBLAS)
40 set(NO_CBLAS 1)
41 endif()
42
43 #######
44
45
46 message(WARNING "CMake support is experimental. This will not produce the same Makefiles that OpenBLAS ships with. Only x86 support is currently available.")
47
48 include("${CMAKE_SOURCE_DIR}/cmake/utils.cmake")
49 include("${CMAKE_SOURCE_DIR}/cmake/system.cmake")
50
51 set(BLASDIRS interface driver/level2 driver/level3 driver/others)
52
53 if (NOT DYNAMIC_ARCH)
54   list(APPEND BLASDIRS kernel)
55 endif ()
56
57 if (DEFINED SANITY_CHECK)
58   list(APPEND BLASDIRS reference)
59 endif ()
60
61 set(SUBDIRS     ${BLASDIRS})
62 if (NOT NO_LAPACK)
63   list(APPEND SUBDIRS lapack)
64 endif ()
65
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)
73 endif ()
74
75 set(FLOAT_TYPES "")
76 if (BUILD_SINGLE)
77   message(STATUS "Building Single Precision")
78   list(APPEND FLOAT_TYPES "SINGLE") # defines nothing
79 endif ()
80
81 if (BUILD_DOUBLE)
82   message(STATUS "Building Double Precision")
83   list(APPEND FLOAT_TYPES "DOUBLE") # defines DOUBLE
84 endif ()
85
86 if (BUILD_COMPLEX)
87   message(STATUS "Building Complex Precision")
88   list(APPEND FLOAT_TYPES "COMPLEX") # defines COMPLEX
89 endif ()
90
91 if (BUILD_COMPLEX16)
92   message(STATUS "Building Double Complex Precision")
93   list(APPEND FLOAT_TYPES "ZCOMPLEX") # defines COMPLEX and DOUBLE
94 endif ()
95
96 set(SUBDIRS_ALL ${SUBDIRS} test ctest utest exports benchmark ../laswp ../bench)
97
98 # all :: libs netlib tests shared
99
100 # libs :
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.")
103 endif ()
104
105 if (${NO_STATIC} AND ${NO_SHARED})
106   message(FATAL_ERROR "Neither static nor shared are enabled.")
107 endif ()
108
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 )
112
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)
114 set(TARGET_OBJS "")
115 foreach (SUBDIR ${SUBDIRS})
116   add_subdirectory(${SUBDIR})
117   string(REPLACE "/" "_" subdir_obj ${SUBDIR})
118   list(APPEND TARGET_OBJS "$<TARGET_OBJECTS:${subdir_obj}>")
119 endforeach ()
120
121 # netlib:
122
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("${CMAKE_SOURCE_DIR}/cmake/lapack.cmake")
127 if (NOT NO_LAPACKE)
128   include("${CMAKE_SOURCE_DIR}/cmake/lapacke.cmake")
129 endif ()
130 endif ()
131
132 #Only generate .def for dll on MSVC
133 if(MSVC)
134 set(OpenBLAS_DEF_FILE "${PROJECT_BINARY_DIR}/openblas.def")
135 endif()
136
137 # add objects to the openblas lib
138 add_library(${OpenBLAS_LIBNAME} SHARED ${LA_SOURCES} ${LAPACKE_SOURCES} ${TARGET_OBJS} ${OpenBLAS_DEF_FILE})
139
140 include("${CMAKE_SOURCE_DIR}/cmake/export.cmake")
141
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)
149 endforeach()
150
151 enable_testing()
152 add_subdirectory(utest)
153
154 if(NOT MSVC)
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)
159
160 if(SMP)
161 target_link_libraries(${OpenBLAS_LIBNAME} pthread)
162 target_link_libraries(${OpenBLAS_LIBNAME}_static pthread)
163 endif()
164
165 #build test and ctest
166 add_subdirectory(test)
167 if(NOT NO_CBLAS)
168 add_subdirectory(ctest)
169 endif()
170 endif()
171
172 set_target_properties(${OpenBLAS_LIBNAME} PROPERTIES 
173   VERSION ${OpenBLAS_MAJOR_VERSION}.${OpenBLAS_MINOR_VERSION}
174   SOVERSION ${OpenBLAS_MAJOR_VERSION}
175 )
176
177
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
184 #endif
185 #ifeq ($(EXPRECISION), 1)
186 #       @echo "#define EXPRECISION">> config_last.h
187 #endif
188 ###
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 ;\
193 #       done
194 #       @echo DYNAMIC_ARCH=1 >> Makefile.conf_last
195 #endif
196 #ifdef USE_THREAD
197 #       @echo USE_THREAD=$(USE_THREAD) >>  Makefile.conf_last
198 #endif
199 #       @touch lib.grd
200