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