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