Include complex rather than complex.h in C++ contexts
[platform/upstream/openblas.git] / lapack-netlib / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8.12)
2
3 project(LAPACK Fortran C)
4
5 set(LAPACK_MAJOR_VERSION 3)
6 set(LAPACK_MINOR_VERSION 8)
7 set(LAPACK_PATCH_VERSION 0)
8 set(
9   LAPACK_VERSION
10   ${LAPACK_MAJOR_VERSION}.${LAPACK_MINOR_VERSION}.${LAPACK_PATCH_VERSION}
11   )
12
13 # Add the CMake directory for custon CMake modules
14 set(CMAKE_MODULE_PATH "${LAPACK_SOURCE_DIR}/CMAKE" ${CMAKE_MODULE_PATH})
15
16 # Set a default build type if none was specified
17 if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
18   message(STATUS "Setting build type to 'Release' as none was specified.")
19   set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
20   # Set the possible values of build type for cmake-gui
21   set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo" "Coverage")
22 endif()
23
24 string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER)
25 if(${CMAKE_BUILD_TYPE_UPPER} STREQUAL "COVERAGE")
26   message(STATUS "Adding coverage")
27   find_package(codecov)
28 endif()
29
30 # By default static library
31 option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
32
33 include(GNUInstallDirs)
34
35 # Updated OSX RPATH settings
36 # In response to CMake 3.0 generating warnings regarding policy CMP0042,
37 # the OSX RPATH settings have been updated per recommendations found
38 # in the CMake Wiki:
39 #  http://www.cmake.org/Wiki/CMake_RPATH_handling#Mac_OS_X_and_the_RPATH
40 set(CMAKE_MACOSX_RPATH ON)
41 set(CMAKE_SKIP_BUILD_RPATH FALSE)
42 set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
43 list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES ${CMAKE_INSTALL_FULL_LIBDIR} isSystemDir)
44 if("${isSystemDir}" STREQUAL "-1")
45   set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})
46   set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
47 endif()
48
49
50 # Configure the warning and code coverage suppression file
51 configure_file(
52   "${LAPACK_SOURCE_DIR}/CTestCustom.cmake.in"
53   "${LAPACK_BINARY_DIR}/CTestCustom.cmake"
54   @ONLY
55 )
56
57 include(PreventInSourceBuilds)
58 include(PreventInBuildInstalls)
59
60 if(UNIX)
61   if("${CMAKE_Fortran_COMPILER}" MATCHES "ifort")
62     set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fp-model strict")
63   endif()
64   if("${CMAKE_Fortran_COMPILER}" MATCHES "xlf")
65     set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qnosave -qstrict=none")
66   endif()
67 # Delete libmtsk in linking sequence for Sun/Oracle Fortran Compiler.
68 # This library is not present in the Sun package SolarisStudio12.3-linux-x86-bin
69   string(REPLACE \;mtsk\; \; CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}")
70 endif()
71
72 if(CMAKE_Fortran_COMPILER_ID STREQUAL "Compaq")
73   if(WIN32)
74     if(CMAKE_GENERATOR STREQUAL "NMake Makefiles")
75       get_filename_component(CMAKE_Fortran_COMPILER_CMDNAM ${CMAKE_Fortran_COMPILER} NAME_WE)
76       message(STATUS "Using Compaq Fortran compiler with command name ${CMAKE_Fortran_COMPILER_CMDNAM}")
77       set(cmd ${CMAKE_Fortran_COMPILER_CMDNAM})
78       string(TOLOWER "${cmd}" cmdlc)
79       if(cmdlc STREQUAL "df")
80         message(STATUS "Assume the Compaq Visual Fortran Compiler is being used")
81         set(CMAKE_Fortran_USE_RESPONSE_FILE_FOR_OBJECTS 1)
82         set(CMAKE_Fortran_USE_RESPONSE_FILE_FOR_INCLUDES 1)
83         #This is a workaround that is needed to avoid forward-slashes in the
84         #filenames listed in response files from incorrectly being interpreted as
85         #introducing compiler command options
86         if(${BUILD_SHARED_LIBS})
87           message(FATAL_ERROR "Making of shared libraries with CVF has not been tested.")
88         endif()
89         set(str "NMake version 9 or later should be used. NMake version 6.0 which is\n")
90         set(str "${str}   included with the CVF distribution fails to build Lapack because\n")
91         set(str "${str}   the number of source files exceeds the limit for NMake v6.0\n")
92         message(STATUS ${str})
93         set(CMAKE_Fortran_LINK_EXECUTABLE "LINK /out:<TARGET> <LINK_FLAGS> <LINK_LIBRARIES> <OBJECTS>")
94       endif()
95     endif()
96   endif()
97 endif()
98
99 # Get Python
100 message(STATUS "Looking for Python greater than 2.6 - ${PYTHONINTERP_FOUND}")
101 find_package(PythonInterp 2.7) # lapack_testing.py uses features from python 2.7 and greater
102 if(PYTHONINTERP_FOUND)
103   message(STATUS "Using Python version ${PYTHON_VERSION_STRING}")
104 else()
105   message(STATUS "No suitable Python version found, so skipping summary tests.")
106 endif()
107 # --------------------------------------------------
108
109 set(LAPACK_INSTALL_EXPORT_NAME lapack-targets)
110
111 macro(lapack_install_library lib)
112   install(TARGETS ${lib}
113     EXPORT ${LAPACK_INSTALL_EXPORT_NAME}
114     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
115     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
116     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
117   )
118 endmacro()
119
120 set(PKG_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
121
122 # --------------------------------------------------
123 # Testing
124 option(BUILD_TESTING "Build tests" OFF)
125 enable_testing()
126 include(CTest)
127 enable_testing()
128 message(STATUS "Build tests: ${BUILD_TESTING}")
129
130 # --------------------------------------------------
131 # Organize output files.  On Windows this also keeps .dll files next
132 # to the .exe files that need them, making tests easy to run.
133 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/bin)
134 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/lib)
135 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/lib)
136
137 # --------------------------------------------------
138 # Check for any necessary platform specific compiler flags
139 include(CheckLAPACKCompilerFlags)
140 CheckLAPACKCompilerFlags()
141
142 # --------------------------------------------------
143 # Check second function
144
145 include(CheckTimeFunction)
146 set(TIME_FUNC NONE ${TIME_FUNC})
147 CHECK_TIME_FUNCTION(NONE TIME_FUNC)
148 CHECK_TIME_FUNCTION(INT_CPU_TIME TIME_FUNC)
149 CHECK_TIME_FUNCTION(EXT_ETIME TIME_FUNC)
150 CHECK_TIME_FUNCTION(EXT_ETIME_ TIME_FUNC)
151 CHECK_TIME_FUNCTION(INT_ETIME TIME_FUNC)
152 message(STATUS "--> Will use second_${TIME_FUNC}.f and dsecnd_${TIME_FUNC}.f as timing function.")
153
154 set(SECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/second_${TIME_FUNC}.f)
155 set(DSECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/dsecnd_${TIME_FUNC}.f)
156
157 # deprecated LAPACK and LAPACKE routines
158 option(BUILD_DEPRECATED "Build deprecated routines" OFF)
159 message(STATUS "Build deprecated routines: ${BUILD_DEPRECATED}")
160
161 # --------------------------------------------------
162 # Precision to build
163 # By default all precisions are generated
164 option(BUILD_SINGLE "Build single precision real" ON)
165 option(BUILD_DOUBLE "Build double precision real" ON)
166 option(BUILD_COMPLEX "Build single precision complex" ON)
167 option(BUILD_COMPLEX16 "Build double precision complex" ON)
168 message(STATUS "Build single precision real: ${BUILD_SINGLE}")
169 message(STATUS "Build double precision real: ${BUILD_DOUBLE}")
170 message(STATUS "Build single precision complex: ${BUILD_COMPLEX}")
171 message(STATUS "Build double precision complex: ${BUILD_COMPLEX16}")
172
173 if(NOT (BUILD_SINGLE OR BUILD_DOUBLE OR BUILD_COMPLEX OR BUILD_COMPLEX16))
174   message(FATAL_ERROR "Nothing to build, no precision selected.
175   Please enable at least one of these:
176   BUILD_SINGLE, BUILD_DOUBLE, BUILD_COMPLEX, BUILD_COMPLEX16.")
177 endif()
178
179 # --------------------------------------------------
180 # Subdirectories that need to be processed
181 option(USE_OPTIMIZED_BLAS "Whether or not to use an optimized BLAS library instead of included netlib BLAS" OFF)
182
183 # Check the usage of the user provided BLAS libraries
184 if(BLAS_LIBRARIES)
185   include(CheckFortranFunctionExists)
186   set(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})
187   CHECK_FORTRAN_FUNCTION_EXISTS("dgemm" BLAS_FOUND)
188   unset(CMAKE_REQUIRED_LIBRARIES)
189   if(BLAS_FOUND)
190     message(STATUS "--> BLAS supplied by user is WORKING, will use ${BLAS_LIBRARIES}.")
191   else()
192     message(ERROR "--> BLAS supplied by user is not WORKING, CANNOT USE ${BLAS_LIBRARIES}.")
193     message(ERROR "-->     Will use REFERENCE BLAS (by default)")
194     message(ERROR "-->     Or Correct your BLAS_LIBRARIES entry ")
195     message(ERROR "-->     Or Consider checking USE_OPTIMIZED_BLAS")
196   endif()
197
198 # User did not provide a BLAS Library but specified to search for one
199 elseif(USE_OPTIMIZED_BLAS)
200   find_package(BLAS)
201 endif()
202
203 # Neither user specified or optimized BLAS libraries can be used
204 if(NOT BLAS_FOUND)
205   message(STATUS "Using supplied NETLIB BLAS implementation")
206   add_subdirectory(BLAS)
207   set(BLAS_LIBRARIES blas)
208 else()
209   set(CMAKE_EXE_LINKER_FLAGS
210     "${CMAKE_EXE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
211     CACHE STRING "Linker flags for executables" FORCE)
212   set(CMAKE_MODULE_LINKER_FLAGS
213     "${CMAKE_MODULE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
214     CACHE STRING "Linker flags for modules" FORCE)
215   set(CMAKE_SHARED_LINKER_FLAGS
216     "${CMAKE_SHARED_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
217     CACHE STRING "Linker flags for shared libs" FORCE)
218 endif()
219
220
221 # --------------------------------------------------
222 # CBLAS
223 option(CBLAS "Build CBLAS" OFF)
224
225 if(CBLAS)
226   add_subdirectory(CBLAS)
227 endif()
228
229 # --------------------------------------------------
230 # XBLAS
231
232 option(USE_XBLAS "Build extended precision (needs XBLAS)" OFF)
233 if(USE_XBLAS)
234   find_library(XBLAS_LIBRARY NAMES xblas)
235 endif()
236
237 option(USE_OPTIMIZED_LAPACK "Whether or not to use an optimized LAPACK library instead of included netlib LAPACK" OFF)
238
239 # --------------------------------------------------
240 # LAPACK
241 # User did not provide a LAPACK Library but specified to search for one
242 if(USE_OPTIMIZED_LAPACK)
243   find_package(LAPACK)
244 endif()
245
246 # Check the usage of the user provided or automatically found LAPACK libraries
247 if(LAPACK_LIBRARIES)
248   include(CheckFortranFunctionExists)
249   set(CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARIES})
250   # Check if new routine of 3.4.0 is in LAPACK_LIBRARIES
251   CHECK_FORTRAN_FUNCTION_EXISTS("dgeqrt" LATESTLAPACK_FOUND)
252   unset(CMAKE_REQUIRED_LIBRARIES)
253   if(LATESTLAPACK_FOUND)
254     message(STATUS "--> LAPACK supplied by user is WORKING, will use ${LAPACK_LIBRARIES}.")
255   else()
256     message(ERROR "--> LAPACK supplied by user is not WORKING or is older than LAPACK 3.4.0, CANNOT USE ${LAPACK_LIBRARIES}.")
257     message(ERROR "-->     Will use REFERENCE LAPACK (by default)")
258     message(ERROR "-->     Or Correct your LAPACK_LIBRARIES entry ")
259     message(ERROR "-->     Or Consider checking USE_OPTIMIZED_LAPACK")
260   endif()
261 endif()
262
263 # Neither user specified or optimized LAPACK libraries can be used
264 if(NOT LATESTLAPACK_FOUND)
265   message(STATUS "Using supplied NETLIB LAPACK implementation")
266   set(LAPACK_LIBRARIES lapack)
267   add_subdirectory(SRC)
268 else()
269   set(CMAKE_EXE_LINKER_FLAGS
270     "${CMAKE_EXE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
271     CACHE STRING "Linker flags for executables" FORCE)
272   set(CMAKE_MODULE_LINKER_FLAGS
273     "${CMAKE_MODULE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
274     CACHE STRING "Linker flags for modules" FORCE)
275   set(CMAKE_SHARED_LINKER_FLAGS
276     "${CMAKE_SHARED_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
277     CACHE STRING "Linker flags for shared libs" FORCE)
278 endif()
279
280 if(BUILD_TESTING)
281   add_subdirectory(TESTING)
282 endif()
283
284 # --------------------------------------------------
285 # LAPACKE
286 option(LAPACKE "Build LAPACKE" OFF)
287
288 # LAPACKE has also the interface to some routines from tmglib,
289 # if LAPACKE_WITH_TMG is selected, we need to add those routines to LAPACKE
290 option(LAPACKE_WITH_TMG "Build LAPACKE with tmglib routines" OFF)
291 if(LAPACKE_WITH_TMG)
292   set(LAPACKE ON)
293 endif()
294 if(BUILD_TESTING OR LAPACKE_WITH_TMG) #already included, avoid double inclusion
295   add_subdirectory(TESTING/MATGEN)
296 endif()
297
298 if(LAPACKE)
299   add_subdirectory(LAPACKE)
300 endif()
301
302 # --------------------------------------------------
303 # CPACK Packaging
304
305 set(CPACK_PACKAGE_NAME "LAPACK")
306 set(CPACK_PACKAGE_VENDOR "University of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd")
307 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LAPACK- Linear Algebra Package")
308 set(CPACK_PACKAGE_VERSION_MAJOR 3)
309 set(CPACK_PACKAGE_VERSION_MINOR 5)
310 set(CPACK_PACKAGE_VERSION_PATCH 0)
311 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
312 set(CPACK_PACKAGE_INSTALL_DIRECTORY "LAPACK")
313 if(WIN32 AND NOT UNIX)
314   # There is a bug in NSI that does not handle full unix paths properly. Make
315   # sure there is at least one set of four (4) backlasshes.
316   set(CPACK_NSIS_HELP_LINK "http:\\\\\\\\http://icl.cs.utk.edu/lapack-forum")
317   set(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.netlib.org/lapack")
318   set(CPACK_NSIS_CONTACT "lapack@eecs.utk.edu")
319   set(CPACK_NSIS_MODIFY_PATH ON)
320   set(CPACK_NSIS_DISPLAY_NAME "LAPACK-${LAPACK_VERSION}")
321   set(CPACK_PACKAGE_RELOCATABLE "true")
322 else()
323   set(CPACK_GENERATOR "TGZ")
324   set(CPACK_SOURCE_GENERATOR TGZ)
325   set(CPACK_SOURCE_PACKAGE_FILE_NAME "lapack-${LAPACK_VERSION}")
326   set(CPACK_SOURCE_IGNORE_FILES ~$ .svn ${CPACK_SOURCE_IGNORE_FILES})
327 endif()
328 include(CPack)
329
330
331 # --------------------------------------------------
332
333 if(NOT BLAS_FOUND)
334   set(ALL_TARGETS ${ALL_TARGETS} blas)
335 endif()
336
337 if(NOT LATESTLAPACK_FOUND)
338   set(ALL_TARGETS ${ALL_TARGETS} lapack)
339 endif()
340
341 if(BUILD_TESTING OR LAPACKE_WITH_TMG)
342   set(ALL_TARGETS ${ALL_TARGETS} tmglib)
343 endif()
344
345 # Export lapack targets, not including lapacke, from the
346 # install tree, if any.
347 set(_lapack_config_install_guard_target "")
348 if(ALL_TARGETS)
349   install(EXPORT lapack-targets
350     DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/lapack-${LAPACK_VERSION})
351
352   # Choose one of the lapack targets to use as a guard for
353   # lapack-config.cmake to load targets from the install tree.
354   list(GET ALL_TARGETS 0 _lapack_config_install_guard_target)
355 endif()
356
357 # Include cblas in targets exported from the build tree.
358 if(CBLAS)
359   set(ALL_TARGETS ${ALL_TARGETS} cblas)
360 endif()
361
362 # Include lapacke in targets exported from the build tree.
363 if(LAPACKE)
364   set(ALL_TARGETS ${ALL_TARGETS} lapacke)
365 endif()
366
367 # Export lapack and lapacke targets from the build tree, if any.
368 set(_lapack_config_build_guard_target "")
369 if(ALL_TARGETS)
370   export(TARGETS ${ALL_TARGETS} FILE lapack-targets.cmake)
371
372   # Choose one of the lapack or lapacke targets to use as a guard
373   # for lapack-config.cmake to load targets from the build tree.
374   list(GET ALL_TARGETS 0 _lapack_config_build_guard_target)
375 endif()
376
377 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-build.cmake.in
378   ${LAPACK_BINARY_DIR}/lapack-config.cmake @ONLY)
379
380
381 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lapack.pc.in ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc @ONLY)
382   install(FILES
383   ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc
384   DESTINATION ${PKG_CONFIG_DIR}
385   )
386
387 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-install.cmake.in
388   ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake @ONLY)
389
390 include(CMakePackageConfigHelpers)
391 write_basic_package_version_file(
392   ${LAPACK_BINARY_DIR}/lapack-config-version.cmake
393   VERSION ${LAPACK_VERSION}
394   COMPATIBILITY SameMajorVersion
395   )
396
397 install(FILES
398   ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake
399   ${LAPACK_BINARY_DIR}/lapack-config-version.cmake
400   DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/lapack-${LAPACK_VERSION}
401   )