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