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 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 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} -fltconsistency -fp_port" )
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}")
50 find_package(PythonInterp)
51 message(STATUS "Looking for Python found - ${PYTHONINTERP_FOUND}")
52 if (PYTHONINTERP_FOUND)
53 message(STATUS "Using Python version ${PYTHON_VERSION_STRING}")
55 # --------------------------------------------------
57 set(LAPACK_INSTALL_EXPORT_NAME lapack-targets)
60 include(GNUInstallDirs)
61 set(ARCHIVE_DIR ${CMAKE_INSTALL_LIBDIR})
62 set(LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR})
63 set(RUNTIME_DIR ${CMAKE_INSTALL_BINDIR})
65 set(ARCHIVE_DIR lib${LIB_SUFFIX})
66 set(LIBRARY_DIR lib${LIB_SUFFIX})
70 macro(lapack_install_library lib)
71 install(TARGETS ${lib}
72 EXPORT ${LAPACK_INSTALL_EXPORT_NAME}
73 ARCHIVE DESTINATION ${ARCHIVE_DIR}
74 LIBRARY DESTINATION ${LIBRARY_DIR}
75 RUNTIME DESTINATION ${RUNTIME_DIR}
79 # --------------------------------------------------
85 # --------------------------------------------------
87 # Organize output files. On Windows this also keeps .dll files next
88 # to the .exe files that need them, making tests easy to run.
89 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/bin)
90 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/lib)
91 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/lib)
93 # --------------------------------------------------
94 # Check for any necessary platform specific compiler flags
95 include( CheckLAPACKCompilerFlags )
96 CheckLAPACKCompilerFlags()
98 # --------------------------------------------------
99 # Check second function
101 include(CheckTimeFunction)
102 set(TIME_FUNC NONE ${TIME_FUNC})
103 CHECK_TIME_FUNCTION(NONE TIME_FUNC)
104 CHECK_TIME_FUNCTION(INT_CPU_TIME TIME_FUNC)
105 CHECK_TIME_FUNCTION(EXT_ETIME TIME_FUNC)
106 CHECK_TIME_FUNCTION(EXT_ETIME_ TIME_FUNC)
107 CHECK_TIME_FUNCTION(INT_ETIME TIME_FUNC)
108 message(STATUS "--> Will use second_${TIME_FUNC}.f and dsecnd_${TIME_FUNC}.f as timing function.")
110 set(SECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/second_${TIME_FUNC}.f)
111 set(DSECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/dsecnd_${TIME_FUNC}.f)
112 set(PKG_CONFIG_DIR ${LIBRARY_DIR}/pkgconfig)
114 # --------------------------------------------------
116 # By default all precisions are generated
119 # --------------------------------------------------
120 # Subdirectories that need to be processed
122 option(USE_OPTIMIZED_BLAS "Whether or not to use an optimized BLAS library instead of included netlib BLAS" OFF)
125 # Check the usage of the user provided BLAS libraries
127 include(CheckFortranFunctionExists)
128 set(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})
129 CHECK_FORTRAN_FUNCTION_EXISTS("dgemm" BLAS_FOUND)
130 unset( CMAKE_REQUIRED_LIBRARIES )
132 message(STATUS "--> BLAS supplied by user is WORKING, will use ${BLAS_LIBRARIES}.")
134 message(ERROR "--> BLAS supplied by user is not WORKING, CANNOT USE ${BLAS_LIBRARIES}.")
135 message(ERROR "--> Will use REFERENCE BLAS (by default)")
136 message(ERROR "--> Or Correct your BLAS_LIBRARIES entry ")
137 message(ERROR "--> Or Consider checking USE_OPTIMIZED_BLAS")
140 # User did not provide a BLAS Library but specified to search for one
141 elseif( USE_OPTIMIZED_BLAS )
143 endif (BLAS_LIBRARIES)
145 # Neither user specified or optimized BLAS libraries can be used
147 message(STATUS "Using supplied NETLIB BLAS implementation")
148 add_subdirectory(BLAS)
149 set( BLAS_LIBRARIES blas )
151 set( CMAKE_EXE_LINKER_FLAGS
152 "${CMAKE_EXE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
153 CACHE STRING "Linker flags for executables" FORCE)
154 set( CMAKE_MODULE_LINKER_FLAGS
155 "${CMAKE_MODULE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
156 CACHE STRING "Linker flags for modules" FORCE)
157 set( CMAKE_SHARED_LINKER_FLAGS
158 "${CMAKE_SHARED_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
159 CACHE STRING "Linker flags for shared libs" FORCE)
160 endif( NOT BLAS_FOUND )
163 # --------------------------------------------------
165 option(CBLAS "Build CBLAS" OFF)
168 add_subdirectory(CBLAS)
171 # --------------------------------------------------
174 option(USE_XBLAS "Build extended precision (needs XBLAS)" OFF)
176 find_library(XBLAS_LIBRARY NAMES xblas)
179 option(USE_OPTIMIZED_LAPACK "Whether or not to use an optimized LAPACK library instead of included netlib LAPACK" OFF)
181 # --------------------------------------------------
183 # User did not provide a LAPACK Library but specified to search for one
184 if( USE_OPTIMIZED_LAPACK )
185 find_package( LAPACK )
186 endif (USE_OPTIMIZED_LAPACK)
188 # Check the usage of the user provided or automatically found LAPACK libraries
190 include(CheckFortranFunctionExists)
191 set(CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARIES})
192 # Check if new routine of 3.4.0 is in LAPACK_LIBRARIES
193 CHECK_FORTRAN_FUNCTION_EXISTS("dgeqrt" LATESTLAPACK_FOUND)
194 unset( CMAKE_REQUIRED_LIBRARIES )
195 if(LATESTLAPACK_FOUND)
196 message(STATUS "--> LAPACK supplied by user is WORKING, will use ${LAPACK_LIBRARIES}.")
198 message(ERROR "--> LAPACK supplied by user is not WORKING or is older than LAPACK 3.4.0, CANNOT USE ${LAPACK_LIBRARIES}.")
199 message(ERROR "--> Will use REFERENCE LAPACK (by default)")
200 message(ERROR "--> Or Correct your LAPACK_LIBRARIES entry ")
201 message(ERROR "--> Or Consider checking USE_OPTIMIZED_LAPACK")
202 endif(LATESTLAPACK_FOUND)
203 endif (LAPACK_LIBRARIES)
205 # Neither user specified or optimized LAPACK libraries can be used
206 if(NOT LATESTLAPACK_FOUND)
207 message(STATUS "Using supplied NETLIB LAPACK implementation")
208 set( LAPACK_LIBRARIES lapack )
209 option(BUILD_SINGLE "Build LAPACK Single Precision" ON)
210 option(BUILD_DOUBLE "Build LAPACK Double Precision" ON)
211 option(BUILD_COMPLEX "Build LAPACK Complex Precision" ON)
212 option(BUILD_COMPLEX16 "Build LAPACK Double Complex Precision" ON)
213 add_subdirectory(SRC)
215 set( CMAKE_EXE_LINKER_FLAGS
216 "${CMAKE_EXE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
217 CACHE STRING "Linker flags for executables" FORCE)
218 set( CMAKE_MODULE_LINKER_FLAGS
219 "${CMAKE_MODULE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
220 CACHE STRING "Linker flags for modules" FORCE)
221 set( CMAKE_SHARED_LINKER_FLAGS
222 "${CMAKE_SHARED_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
223 CACHE STRING "Linker flags for shared libs" FORCE)
224 endif( NOT LATESTLAPACK_FOUND )
226 message(STATUS "BUILD TESTING : ${BUILD_TESTING}" )
228 add_subdirectory(TESTING)
231 # deprecated LAPACK routines
232 option(BUILD_DEPRECATED "Build deprecated routines" OFF)
234 # --------------------------------------------------
236 option(LAPACKE "Build LAPACKE" OFF)
238 # LAPACKE has also the interface to some routines from tmglib,
239 # if LAPACKE_WITH_TMG is selected, we need to add those routines to LAPACKE
240 option(LAPACKE_WITH_TMG "Build LAPACKE with tmglib routines" OFF)
241 if (LAPACKE_WITH_TMG)
243 if(NOT BUILD_TESTING)
244 add_subdirectory(TESTING/MATGEN)
245 endif(NOT BUILD_TESTING)
246 endif(LAPACKE_WITH_TMG)
249 add_subdirectory(LAPACKE)
252 # --------------------------------------------------
255 SET(CPACK_PACKAGE_NAME "LAPACK")
256 SET(CPACK_PACKAGE_VENDOR "University of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd")
257 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LAPACK- Linear Algebra Package")
258 set(CPACK_PACKAGE_VERSION_MAJOR 3)
259 set(CPACK_PACKAGE_VERSION_MINOR 5)
260 set(CPACK_PACKAGE_VERSION_PATCH 0)
261 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
262 SET(CPACK_PACKAGE_INSTALL_DIRECTORY "LAPACK")
263 IF(WIN32 AND NOT UNIX)
264 # There is a bug in NSI that does not handle full unix paths properly. Make
265 # sure there is at least one set of four (4) backlasshes.
266 SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\http://icl.cs.utk.edu/lapack-forum")
267 SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.netlib.org/lapack")
268 SET(CPACK_NSIS_CONTACT "lapack@eecs.utk.edu")
269 SET(CPACK_NSIS_MODIFY_PATH ON)
270 SET(CPACK_NSIS_DISPLAY_NAME "LAPACK-${LAPACK_VERSION}")
271 set(CPACK_PACKAGE_RELOCATABLE "true")
272 ELSE(WIN32 AND NOT UNIX)
273 SET(CPACK_GENERATOR "TGZ")
274 SET(CPACK_SOURCE_GENERATOR TGZ)
275 SET(CPACK_SOURCE_PACKAGE_FILE_NAME "lapack-${LAPACK_VERSION}" )
276 SET(CPACK_SOURCE_IGNORE_FILES ~$ .svn ${CPACK_SOURCE_IGNORE_FILES} )
277 ENDIF(WIN32 AND NOT UNIX)
281 # --------------------------------------------------
282 # By default static library
283 OPTION(BUILD_SHARED_LIBS "Build shared libraries" OFF )
284 OPTION(BUILD_STATIC_LIBS "Build static libraries" ON )
285 #OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON )
288 set(ALL_TARGETS ${ALL_TARGETS} blas)
289 endif(NOT BLAS_FOUND)
291 if(NOT LATESTLAPACK_FOUND)
292 set(ALL_TARGETS ${ALL_TARGETS} lapack)
293 endif(NOT LATESTLAPACK_FOUND)
295 if(BUILD_TESTING OR LAPACKE_WITH_TMG)
296 set(ALL_TARGETS ${ALL_TARGETS} tmglib)
297 endif(BUILD_TESTING OR LAPACKE_WITH_TMG)
299 # Export lapack targets, not including lapacke, from the
300 # install tree, if any.
301 set(_lapack_config_install_guard_target "")
303 install(EXPORT lapack-targets
304 DESTINATION ${LIBRARY_DIR}/cmake/lapack-${LAPACK_VERSION})
306 # Choose one of the lapack targets to use as a guard for
307 # lapack-config.cmake to load targets from the install tree.
308 list(GET ALL_TARGETS 0 _lapack_config_install_guard_target)
311 # Include cblas in targets exported from the build tree.
313 set(ALL_TARGETS ${ALL_TARGETS} cblas)
316 # Include lapacke in targets exported from the build tree.
318 set(ALL_TARGETS ${ALL_TARGETS} lapacke)
321 # Export lapack and lapacke targets from the build tree, if any.
322 set(_lapack_config_build_guard_target "")
324 export(TARGETS ${ALL_TARGETS} FILE lapack-targets.cmake)
326 # Choose one of the lapack or lapacke targets to use as a guard
327 # for lapack-config.cmake to load targets from the build tree.
328 list(GET ALL_TARGETS 0 _lapack_config_build_guard_target)
331 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-build.cmake.in
332 ${LAPACK_BINARY_DIR}/lapack-config.cmake @ONLY)
335 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lapack.pc.in ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc)
337 ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc
338 DESTINATION ${PKG_CONFIG_DIR}
341 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-install.cmake.in
342 ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake @ONLY)
344 include(CMakePackageConfigHelpers)
345 write_basic_package_version_file(
346 ${LAPACK_BINARY_DIR}/lapack-config-version.cmake
347 VERSION ${LAPACK_VERSION}
348 COMPATIBILITY SameMajorVersion
352 ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake
353 ${LAPACK_BINARY_DIR}/lapack-config-version.cmake
354 DESTINATION ${LIBRARY_DIR}/cmake/lapack-${LAPACK_VERSION}