1 cmake_minimum_required(VERSION 2.8.10)
2 project(LAPACK Fortran)
4 set(LAPACK_MAJOR_VERSION 3)
5 set(LAPACK_MINOR_VERSION 5)
6 set(LAPACK_PATCH_VERSION 0)
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 set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
21 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
22 list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
23 if("${isSystemDir}" STREQUAL "-1")
24 set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
28 # Configure the warning and code coverage suppression file
30 "${LAPACK_SOURCE_DIR}/CTestCustom.cmake.in"
31 "${LAPACK_BINARY_DIR}/CTestCustom.cmake"
35 # Add the CMake directory for custon CMake modules
36 set(CMAKE_MODULE_PATH "${LAPACK_SOURCE_DIR}/CMAKE" ${CMAKE_MODULE_PATH})
39 if ( "${CMAKE_Fortran_COMPILER}" MATCHES "ifort" )
40 set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fltconsistency -fp_port" )
42 if ( "${CMAKE_Fortran_COMPILER}" MATCHES "xlf" )
43 set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qnosave -qstrict=none" )
45 # Delete libmtsk in linking sequence for Sun/Oracle Fortran Compiler.
46 # This library is not present in the Sun package SolarisStudio12.3-linux-x86-bin
47 STRING(REPLACE \;mtsk\; \; CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}")
51 find_package(PythonInterp)
52 message(STATUS "Looking for Python found - ${PYTHONINTERP_FOUND}")
53 if (PYTHONINTERP_FOUND)
54 message(STATUS "Using Python version ${PYTHON_VERSION_STRING}")
56 # --------------------------------------------------
58 set(LAPACK_INSTALL_EXPORT_NAME lapack-targets)
61 include(GNUInstallDirs)
62 set(ARCHIVE_DIR ${CMAKE_INSTALL_LIBDIR})
63 set(LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR})
64 set(RUNTIME_DIR ${CMAKE_INSTALL_BINDIR})
66 set(ARCHIVE_DIR lib${LIB_SUFFIX})
67 set(LIBRARY_DIR lib${LIB_SUFFIX})
71 macro(lapack_install_library lib)
72 install(TARGETS ${lib}
73 EXPORT ${LAPACK_INSTALL_EXPORT_NAME}
74 ARCHIVE DESTINATION ${ARCHIVE_DIR}
75 LIBRARY DESTINATION ${LIBRARY_DIR}
76 RUNTIME DESTINATION ${RUNTIME_DIR}
80 # --------------------------------------------------
86 # --------------------------------------------------
88 # Organize output files. On Windows this also keeps .dll files next
89 # to the .exe files that need them, making tests easy to run.
90 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/bin)
91 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/lib)
92 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/lib)
94 # --------------------------------------------------
95 # Check for any necessary platform specific compiler flags
96 include( CheckLAPACKCompilerFlags )
97 CheckLAPACKCompilerFlags()
99 # --------------------------------------------------
100 # Check second function
102 include(CheckTimeFunction)
103 set(TIME_FUNC NONE ${TIME_FUNC})
104 CHECK_TIME_FUNCTION(NONE TIME_FUNC)
105 CHECK_TIME_FUNCTION(INT_CPU_TIME TIME_FUNC)
106 CHECK_TIME_FUNCTION(EXT_ETIME TIME_FUNC)
107 CHECK_TIME_FUNCTION(EXT_ETIME_ TIME_FUNC)
108 CHECK_TIME_FUNCTION(INT_ETIME TIME_FUNC)
109 message(STATUS "--> Will use second_${TIME_FUNC}.f and dsecnd_${TIME_FUNC}.f as timing function.")
111 set(SECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/second_${TIME_FUNC}.f)
112 set(DSECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/dsecnd_${TIME_FUNC}.f)
113 set(PKG_CONFIG_DIR ${LIBRARY_DIR}/pkgconfig)
115 # --------------------------------------------------
117 # By default all precisions are generated
120 # --------------------------------------------------
121 # Subdirectories that need to be processed
123 option(USE_OPTIMIZED_BLAS "Whether or not to use an optimized BLAS library instead of included netlib BLAS" OFF)
126 # Check the usage of the user provided BLAS libraries
128 include(CheckFortranFunctionExists)
129 set(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})
130 CHECK_FORTRAN_FUNCTION_EXISTS("dgemm" BLAS_FOUND)
131 unset( CMAKE_REQUIRED_LIBRARIES )
133 message(STATUS "--> BLAS supplied by user is WORKING, will use ${BLAS_LIBRARIES}.")
135 message(ERROR "--> BLAS supplied by user is not WORKING, CANNOT USE ${BLAS_LIBRARIES}.")
136 message(ERROR "--> Will use REFERENCE BLAS (by default)")
137 message(ERROR "--> Or Correct your BLAS_LIBRARIES entry ")
138 message(ERROR "--> Or Consider checking USE_OPTIMIZED_BLAS")
141 # User did not provide a BLAS Library but specified to search for one
142 elseif( USE_OPTIMIZED_BLAS )
144 endif (BLAS_LIBRARIES)
146 # Neither user specified or optimized BLAS libraries can be used
148 message(STATUS "Using supplied NETLIB BLAS implementation")
149 add_subdirectory(BLAS)
150 set( BLAS_LIBRARIES blas )
152 set( CMAKE_EXE_LINKER_FLAGS
153 "${CMAKE_EXE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
154 CACHE STRING "Linker flags for executables" FORCE)
155 set( CMAKE_MODULE_LINKER_FLAGS
156 "${CMAKE_MODULE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
157 CACHE STRING "Linker flags for modules" FORCE)
158 set( CMAKE_SHARED_LINKER_FLAGS
159 "${CMAKE_SHARED_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
160 CACHE STRING "Linker flags for shared libs" FORCE)
161 endif( NOT BLAS_FOUND )
164 # --------------------------------------------------
166 option(CBLAS "Build CBLAS" OFF)
169 add_subdirectory(CBLAS)
172 # --------------------------------------------------
175 option(USE_XBLAS "Build extended precision (needs XBLAS)" OFF)
177 find_library(XBLAS_LIBRARY NAMES xblas)
180 option(USE_OPTIMIZED_LAPACK "Whether or not to use an optimized LAPACK library instead of included netlib LAPACK" OFF)
182 # --------------------------------------------------
184 # User did not provide a LAPACK Library but specified to search for one
185 if( USE_OPTIMIZED_LAPACK )
186 find_package( LAPACK )
187 endif (USE_OPTIMIZED_LAPACK)
189 # Check the usage of the user provided or automatically found LAPACK libraries
191 include(CheckFortranFunctionExists)
192 set(CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARIES})
193 # Check if new routine of 3.4.0 is in LAPACK_LIBRARIES
194 CHECK_FORTRAN_FUNCTION_EXISTS("dgeqrt" LATESTLAPACK_FOUND)
195 unset( CMAKE_REQUIRED_LIBRARIES )
196 if(LATESTLAPACK_FOUND)
197 message(STATUS "--> LAPACK supplied by user is WORKING, will use ${LAPACK_LIBRARIES}.")
199 message(ERROR "--> LAPACK supplied by user is not WORKING or is older than LAPACK 3.4.0, CANNOT USE ${LAPACK_LIBRARIES}.")
200 message(ERROR "--> Will use REFERENCE LAPACK (by default)")
201 message(ERROR "--> Or Correct your LAPACK_LIBRARIES entry ")
202 message(ERROR "--> Or Consider checking USE_OPTIMIZED_LAPACK")
203 endif(LATESTLAPACK_FOUND)
204 endif (LAPACK_LIBRARIES)
206 # Neither user specified or optimized LAPACK libraries can be used
207 if(NOT LATESTLAPACK_FOUND)
208 message(STATUS "Using supplied NETLIB LAPACK implementation")
209 set( LAPACK_LIBRARIES lapack )
210 option(BUILD_SINGLE "Build LAPACK Single Precision" ON)
211 option(BUILD_DOUBLE "Build LAPACK Double Precision" ON)
212 option(BUILD_COMPLEX "Build LAPACK Complex Precision" ON)
213 option(BUILD_COMPLEX16 "Build LAPACK Double Complex Precision" ON)
214 add_subdirectory(SRC)
216 set( CMAKE_EXE_LINKER_FLAGS
217 "${CMAKE_EXE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
218 CACHE STRING "Linker flags for executables" FORCE)
219 set( CMAKE_MODULE_LINKER_FLAGS
220 "${CMAKE_MODULE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
221 CACHE STRING "Linker flags for modules" FORCE)
222 set( CMAKE_SHARED_LINKER_FLAGS
223 "${CMAKE_SHARED_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
224 CACHE STRING "Linker flags for shared libs" FORCE)
225 endif( NOT LATESTLAPACK_FOUND )
227 message(STATUS "BUILD TESTING : ${BUILD_TESTING}" )
229 add_subdirectory(TESTING)
232 # deprecated LAPACK routines
233 option(BUILD_DEPRECATED "Build deprecated routines" OFF)
235 # --------------------------------------------------
237 option(LAPACKE "Build LAPACKE" OFF)
239 # LAPACKE has also the interface to some routines from tmglib,
240 # if LAPACKE_WITH_TMG is selected, we need to add those routines to LAPACKE
241 option(LAPACKE_WITH_TMG "Build LAPACKE with tmglib routines" OFF)
242 if (LAPACKE_WITH_TMG)
244 if(NOT BUILD_TESTING)
245 add_subdirectory(TESTING/MATGEN)
246 endif(NOT BUILD_TESTING)
247 endif(LAPACKE_WITH_TMG)
250 add_subdirectory(LAPACKE)
253 # --------------------------------------------------
256 SET(CPACK_PACKAGE_NAME "LAPACK")
257 SET(CPACK_PACKAGE_VENDOR "University of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd")
258 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LAPACK- Linear Algebra Package")
259 set(CPACK_PACKAGE_VERSION_MAJOR 3)
260 set(CPACK_PACKAGE_VERSION_MINOR 5)
261 set(CPACK_PACKAGE_VERSION_PATCH 0)
262 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
263 SET(CPACK_PACKAGE_INSTALL_DIRECTORY "LAPACK")
264 IF(WIN32 AND NOT UNIX)
265 # There is a bug in NSI that does not handle full unix paths properly. Make
266 # sure there is at least one set of four (4) backlasshes.
267 SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\http://icl.cs.utk.edu/lapack-forum")
268 SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.netlib.org/lapack")
269 SET(CPACK_NSIS_CONTACT "lapack@eecs.utk.edu")
270 SET(CPACK_NSIS_MODIFY_PATH ON)
271 SET(CPACK_NSIS_DISPLAY_NAME "LAPACK-${LAPACK_VERSION}")
272 set(CPACK_PACKAGE_RELOCATABLE "true")
273 ELSE(WIN32 AND NOT UNIX)
274 SET(CPACK_GENERATOR "TGZ")
275 SET(CPACK_SOURCE_GENERATOR TGZ)
276 SET(CPACK_SOURCE_PACKAGE_FILE_NAME "lapack-${LAPACK_VERSION}" )
277 SET(CPACK_SOURCE_IGNORE_FILES ~$ .svn ${CPACK_SOURCE_IGNORE_FILES} )
278 ENDIF(WIN32 AND NOT UNIX)
282 # --------------------------------------------------
283 # By default static library
284 OPTION(BUILD_SHARED_LIBS "Build shared libraries" OFF )
285 OPTION(BUILD_STATIC_LIBS "Build static libraries" ON )
286 #OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON )
289 set(ALL_TARGETS ${ALL_TARGETS} blas)
290 endif(NOT BLAS_FOUND)
292 if(NOT LATESTLAPACK_FOUND)
293 set(ALL_TARGETS ${ALL_TARGETS} lapack)
294 endif(NOT LATESTLAPACK_FOUND)
296 if(BUILD_TESTING OR LAPACKE_WITH_TMG)
297 set(ALL_TARGETS ${ALL_TARGETS} tmglib)
298 endif(BUILD_TESTING OR LAPACKE_WITH_TMG)
300 # Export lapack targets, not including lapacke, from the
301 # install tree, if any.
302 set(_lapack_config_install_guard_target "")
304 install(EXPORT lapack-targets
305 DESTINATION ${LIBRARY_DIR}/cmake/lapack-${LAPACK_VERSION})
307 # Choose one of the lapack targets to use as a guard for
308 # lapack-config.cmake to load targets from the install tree.
309 list(GET ALL_TARGETS 0 _lapack_config_install_guard_target)
312 # Include cblas in targets exported from the build tree.
314 set(ALL_TARGETS ${ALL_TARGETS} cblas)
317 # Include lapacke in targets exported from the build tree.
319 set(ALL_TARGETS ${ALL_TARGETS} lapacke)
322 # Export lapack and lapacke targets from the build tree, if any.
323 set(_lapack_config_build_guard_target "")
325 export(TARGETS ${ALL_TARGETS} FILE lapack-targets.cmake)
327 # Choose one of the lapack or lapacke targets to use as a guard
328 # for lapack-config.cmake to load targets from the build tree.
329 list(GET ALL_TARGETS 0 _lapack_config_build_guard_target)
332 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-build.cmake.in
333 ${LAPACK_BINARY_DIR}/lapack-config.cmake @ONLY)
336 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lapack.pc.in ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc)
338 ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc
339 DESTINATION ${PKG_CONFIG_DIR}
342 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-install.cmake.in
343 ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake @ONLY)
345 include(CMakePackageConfigHelpers)
346 write_basic_package_version_file(
347 ${LAPACK_BINARY_DIR}/lapack-config-version.cmake
348 VERSION ${LAPACK_VERSION}
349 COMPATIBILITY SameMajorVersion
353 ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake
354 ${LAPACK_BINARY_DIR}/lapack-config-version.cmake
355 DESTINATION ${LIBRARY_DIR}/cmake/lapack-${LAPACK_VERSION}