1 cmake_minimum_required(VERSION 2.8.10)
2 project(LAPACK Fortran)
4 set(LAPACK_MAJOR_VERSION 3)
5 set(LAPACK_MINOR_VERSION 6)
6 set(LAPACK_PATCH_VERSION 1)
9 ${LAPACK_MAJOR_VERSION}.${LAPACK_MINOR_VERSION}.${LAPACK_PATCH_VERSION}
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
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)
27 # Configure the warning and code coverage suppression file
29 "${LAPACK_SOURCE_DIR}/CTestCustom.cmake.in"
30 "${LAPACK_BINARY_DIR}/CTestCustom.cmake"
34 # Add the CMake directory for custon CMake modules
35 set(CMAKE_MODULE_PATH "${LAPACK_SOURCE_DIR}/CMAKE" ${CMAKE_MODULE_PATH})
38 if ( "${CMAKE_Fortran_COMPILER}" MATCHES "ifort" )
39 set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fp-model strict" )
41 if ( "${CMAKE_Fortran_COMPILER}" MATCHES "xlf" )
42 set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qnosave -qstrict=none" )
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}")
49 if ( CMAKE_Fortran_COMPILER_ID STREQUAL "Compaq" )
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.")
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>")
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}")
82 # --------------------------------------------------
84 set(LAPACK_INSTALL_EXPORT_NAME lapack-targets)
87 include(GNUInstallDirs)
88 set(ARCHIVE_DIR ${CMAKE_INSTALL_LIBDIR})
89 set(LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR})
90 set(RUNTIME_DIR ${CMAKE_INSTALL_BINDIR})
92 set(ARCHIVE_DIR lib${LIB_SUFFIX})
93 set(LIBRARY_DIR lib${LIB_SUFFIX})
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}
106 # --------------------------------------------------
112 # --------------------------------------------------
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)
120 # --------------------------------------------------
121 # Check for any necessary platform specific compiler flags
122 include( CheckLAPACKCompilerFlags )
123 CheckLAPACKCompilerFlags()
125 # --------------------------------------------------
126 # Check second function
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.")
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)
141 # --------------------------------------------------
143 # By default all precisions are generated
146 # --------------------------------------------------
147 # Subdirectories that need to be processed
149 option(USE_OPTIMIZED_BLAS "Whether or not to use an optimized BLAS library instead of included netlib BLAS" OFF)
152 # Check the usage of the user provided 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 )
159 message(STATUS "--> BLAS supplied by user is WORKING, will use ${BLAS_LIBRARIES}.")
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")
167 # User did not provide a BLAS Library but specified to search for one
168 elseif( USE_OPTIMIZED_BLAS )
172 # Neither user specified or optimized BLAS libraries can be used
174 message(STATUS "Using supplied NETLIB BLAS implementation")
175 add_subdirectory(BLAS)
176 set( BLAS_LIBRARIES blas )
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)
190 # --------------------------------------------------
192 option(CBLAS "Build CBLAS" OFF)
195 add_subdirectory(CBLAS)
198 # --------------------------------------------------
201 option(USE_XBLAS "Build extended precision (needs XBLAS)" OFF)
203 find_library(XBLAS_LIBRARY NAMES xblas)
206 option(USE_OPTIMIZED_LAPACK "Whether or not to use an optimized LAPACK library instead of included netlib LAPACK" OFF)
208 # --------------------------------------------------
210 # User did not provide a LAPACK Library but specified to search for one
211 if( USE_OPTIMIZED_LAPACK )
212 find_package( LAPACK )
215 # Check the usage of the user provided or automatically found 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}.")
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")
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)
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)
253 message(STATUS "BUILD TESTING : ${BUILD_TESTING}" )
255 add_subdirectory(TESTING)
258 # deprecated LAPACK routines
259 option(BUILD_DEPRECATED "Build deprecated routines" OFF)
261 # --------------------------------------------------
263 option(LAPACKE "Build LAPACKE" OFF)
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)
270 if(NOT BUILD_TESTING)
271 add_subdirectory(TESTING/MATGEN)
276 add_subdirectory(LAPACKE)
279 # --------------------------------------------------
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")
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} )
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 )
315 set(ALL_TARGETS ${ALL_TARGETS} blas)
318 if(NOT LATESTLAPACK_FOUND)
319 set(ALL_TARGETS ${ALL_TARGETS} lapack)
322 if(BUILD_TESTING OR LAPACKE_WITH_TMG)
323 set(ALL_TARGETS ${ALL_TARGETS} tmglib)
326 # Export lapack targets, not including lapacke, from the
327 # install tree, if any.
328 set(_lapack_config_install_guard_target "")
330 install(EXPORT lapack-targets
331 DESTINATION ${LIBRARY_DIR}/cmake/lapack-${LAPACK_VERSION})
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)
338 # Include cblas in targets exported from the build tree.
340 set(ALL_TARGETS ${ALL_TARGETS} cblas)
343 # Include lapacke in targets exported from the build tree.
345 set(ALL_TARGETS ${ALL_TARGETS} lapacke)
348 # Export lapack and lapacke targets from the build tree, if any.
349 set(_lapack_config_build_guard_target "")
351 export(TARGETS ${ALL_TARGETS} FILE lapack-targets.cmake)
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)
358 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-build.cmake.in
359 ${LAPACK_BINARY_DIR}/lapack-config.cmake @ONLY)
362 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lapack.pc.in ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc)
364 ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc
365 DESTINATION ${PKG_CONFIG_DIR}
368 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-install.cmake.in
369 ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake @ONLY)
371 include(CMakePackageConfigHelpers)
372 write_basic_package_version_file(
373 ${LAPACK_BINARY_DIR}/lapack-config-version.cmake
374 VERSION ${LAPACK_VERSION}
375 COMPATIBILITY SameMajorVersion
379 ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake
380 ${LAPACK_BINARY_DIR}/lapack-config-version.cmake
381 DESTINATION ${LIBRARY_DIR}/cmake/lapack-${LAPACK_VERSION}