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