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