1 cmake_minimum_required(VERSION 2.8.10)
2 project(LAPACK Fortran)
4 set(LAPACK_VERSION 3.4.2)
6 # Configure the warning and code coverage suppression file
8 "${LAPACK_SOURCE_DIR}/CTestCustom.cmake.in"
9 "${LAPACK_BINARY_DIR}/CTestCustom.cmake"
13 # Add the CMake directory for custon CMake modules
14 set(CMAKE_MODULE_PATH "${LAPACK_SOURCE_DIR}/CMAKE" ${CMAKE_MODULE_PATH})
17 if ( "${CMAKE_Fortran_COMPILER}" MATCHES "ifort" )
18 set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fltconsistency -fp_port" )
20 if ( "${CMAKE_Fortran_COMPILER}" MATCHES "xlf" )
21 set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qnosave -qstrict=none" )
23 # Delete libmtsk in linking sequence for Sun/Oracle Fortran Compiler.
24 # This library is not present in the Sun package SolarisStudio12.3-linux-x86-bin
25 STRING(REPLACE \;mtsk\; \; CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}")
29 find_package(PythonInterp)
30 message(STATUS "Looking for Python found - ${PYTHONINTERP_FOUND}")
31 if (PYTHONINTERP_FOUND)
32 message(STATUS "Using Python version ${PYTHON_VERSION_STRING}")
34 # --------------------------------------------------
36 set(LAPACK_INSTALL_EXPORT_NAME lapack-targets)
38 macro(lapack_install_library lib)
39 install(TARGETS ${lib}
40 EXPORT ${LAPACK_INSTALL_EXPORT_NAME}
41 ARCHIVE DESTINATION lib${LIB_SUFFIX}
42 LIBRARY DESTINATION lib${LIB_SUFFIX}
43 RUNTIME DESTINATION bin
47 # --------------------------------------------------
53 # --------------------------------------------------
55 # Organize output files. On Windows this also keeps .dll files next
56 # to the .exe files that need them, making tests easy to run.
57 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/bin)
58 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/lib)
59 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/lib)
61 # --------------------------------------------------
62 # Check for any necessary platform specific compiler flags
63 include( CheckLAPACKCompilerFlags )
64 CheckLAPACKCompilerFlags()
66 # --------------------------------------------------
67 # Check second function
69 include(CheckTimeFunction)
70 set(TIME_FUNC NONE ${TIME_FUNC})
71 CHECK_TIME_FUNCTION(NONE TIME_FUNC)
72 CHECK_TIME_FUNCTION(INT_CPU_TIME TIME_FUNC)
73 CHECK_TIME_FUNCTION(EXT_ETIME TIME_FUNC)
74 CHECK_TIME_FUNCTION(EXT_ETIME_ TIME_FUNC)
75 CHECK_TIME_FUNCTION(INT_ETIME TIME_FUNC)
76 message(STATUS "--> Will use second_${TIME_FUNC}.f and dsecnd_${TIME_FUNC}.f as timing function.")
78 set(SECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/second_${TIME_FUNC}.f)
79 set(DSECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/dsecnd_${TIME_FUNC}.f)
80 set(prefix ${CMAKE_INSTALL_PREFIX})
81 set(libdir ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX})
82 set(PKG_CONFIG_DIR ${libdir}/pkgconfig)
84 # --------------------------------------------------
86 # By default all precisions are generated
89 # --------------------------------------------------
90 # Subdirectories that need to be processed
92 option(USE_OPTIMIZED_BLAS "Whether or not to use an optimized BLAS library instead of included netlib BLAS" OFF)
95 # Check the usage of the user provided BLAS libraries
97 include(CheckFortranFunctionExists)
98 set(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})
99 CHECK_FORTRAN_FUNCTION_EXISTS("dgemm" BLAS_FOUND)
100 unset( CMAKE_REQUIRED_LIBRARIES )
102 message(STATUS "--> BLAS supplied by user is WORKING, will use ${BLAS_LIBRARIES}.")
104 message(ERROR "--> BLAS supplied by user is not WORKING, CANNOT USE ${BLAS_LIBRARIES}.")
105 message(ERROR "--> Will use REFERENCE BLAS (by default)")
106 message(ERROR "--> Or Correct your BLAS_LIBRARIES entry ")
107 message(ERROR "--> Or Consider checking USE_OPTIMIZED_BLAS")
110 # User did not provide a BLAS Library but specified to search for one
111 elseif( USE_OPTIMIZED_BLAS )
113 endif (BLAS_LIBRARIES)
115 # Neither user specified or optimized BLAS libraries can be used
117 message(STATUS "Using supplied NETLIB BLAS implementation")
118 add_subdirectory(BLAS)
119 set( BLAS_LIBRARIES blas )
121 set( CMAKE_EXE_LINKER_FLAGS
122 "${CMAKE_EXE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
123 CACHE STRING "Linker flags for executables" FORCE)
124 set( CMAKE_MODULE_LINKER_FLAGS
125 "${CMAKE_MODULE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
126 CACHE STRING "Linker flags for modules" FORCE)
127 set( CMAKE_SHARED_LINKER_FLAGS
128 "${CMAKE_SHARED_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
129 CACHE STRING "Linker flags for shared libs" FORCE)
130 endif( NOT BLAS_FOUND )
132 option(USE_XBLAS "Build extended precision (needs XBLAS)" OFF)
134 find_library(XBLAS_LIBRARY NAMES xblas)
137 option(USE_OPTIMIZED_LAPACK "Whether or not to use an optimized LAPACK library instead of included netlib LAPACK" OFF)
139 # User did not provide a LAPACK Library but specified to search for one
140 if( USE_OPTIMIZED_LAPACK )
141 find_package( LAPACK )
142 endif (USE_OPTIMIZED_LAPACK)
144 # Check the usage of the user provided or automatically found LAPACK libraries
146 include(CheckFortranFunctionExists)
147 set(CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARIES})
148 # Check if new routine of 3.4.0 is in LAPACK_LIBRARIES
149 CHECK_FORTRAN_FUNCTION_EXISTS("dgeqrt" LATESTLAPACK_FOUND)
150 unset( CMAKE_REQUIRED_LIBRARIES )
151 if(LATESTLAPACK_FOUND)
152 message(STATUS "--> LAPACK supplied by user is WORKING, will use ${LAPACK_LIBRARIES}.")
154 message(ERROR "--> LAPACK supplied by user is not WORKING or is older than LAPACK 3.4.0, CANNOT USE ${LAPACK_LIBRARIES}.")
155 message(ERROR "--> Will use REFERENCE LAPACK (by default)")
156 message(ERROR "--> Or Correct your LAPACK_LIBRARIES entry ")
157 message(ERROR "--> Or Consider checking USE_OPTIMIZED_LAPACK")
158 endif(LATESTLAPACK_FOUND)
159 endif (LAPACK_LIBRARIES)
161 # Neither user specified or optimized LAPACK libraries can be used
162 if(NOT LATESTLAPACK_FOUND)
163 message(STATUS "Using supplied NETLIB LAPACK implementation")
164 set( LAPACK_LIBRARIES lapack )
165 option(BUILD_SINGLE "Build LAPACK Single Precision" ON)
166 option(BUILD_DOUBLE "Build LAPACK Double Precision" ON)
167 option(BUILD_COMPLEX "Build LAPACK Complex Precision" ON)
168 option(BUILD_COMPLEX16 "Build LAPACK Double Complex Precision" ON)
169 add_subdirectory(SRC)
171 set( CMAKE_EXE_LINKER_FLAGS
172 "${CMAKE_EXE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
173 CACHE STRING "Linker flags for executables" FORCE)
174 set( CMAKE_MODULE_LINKER_FLAGS
175 "${CMAKE_MODULE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
176 CACHE STRING "Linker flags for modules" FORCE)
177 set( CMAKE_SHARED_LINKER_FLAGS
178 "${CMAKE_SHARED_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
179 CACHE STRING "Linker flags for shared libs" FORCE)
180 endif( NOT LATESTLAPACK_FOUND )
182 message(STATUS "BUILD TESTING : ${BUILD_TESTING}" )
184 add_subdirectory(TESTING)
187 # --------------------------------------------------
189 option(LAPACKE "Build LAPACKE" OFF)
191 # LAPACKE has also the interface to some routines from tmglib,
192 # if LAPACKE_WITH_TMG is selected, we need to add those routines to LAPACKE
193 option(LAPACKE_WITH_TMG "Build LAPACKE with tmglib routines" OFF)
194 if (LAPACKE_WITH_TMG)
196 if(NOT BUILD_TESTING)
197 add_subdirectory(TESTING/MATGEN)
198 endif(NOT BUILD_TESTING)
199 endif(LAPACKE_WITH_TMG)
202 add_subdirectory(lapacke)
205 # --------------------------------------------------
208 SET(CPACK_PACKAGE_NAME "LAPACK")
209 SET(CPACK_PACKAGE_VENDOR "University of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd")
210 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LAPACK- Linear Algebra Package")
211 set(CPACK_PACKAGE_VERSION_MAJOR 3)
212 set(CPACK_PACKAGE_VERSION_MINOR 4)
213 set(CPACK_PACKAGE_VERSION_PATCH 2)
214 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
215 SET(CPACK_PACKAGE_INSTALL_DIRECTORY "LAPACK")
216 IF(WIN32 AND NOT UNIX)
217 # There is a bug in NSI that does not handle full unix paths properly. Make
218 # sure there is at least one set of four (4) backlasshes.
219 SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\http://icl.cs.utk.edu/lapack-forum")
220 SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.netlib.org/lapack")
221 SET(CPACK_NSIS_CONTACT "lapack@eecs.utk.edu")
222 SET(CPACK_NSIS_MODIFY_PATH ON)
223 SET(CPACK_NSIS_DISPLAY_NAME "LAPACK-${LAPACK_VERSION}")
224 set(CPACK_PACKAGE_RELOCATABLE "true")
225 ELSE(WIN32 AND NOT UNIX)
226 SET(CPACK_GENERATOR "TGZ")
227 SET(CPACK_SOURCE_GENERATOR TGZ)
228 SET(CPACK_SOURCE_PACKAGE_FILE_NAME "lapack-${LAPACK_VERSION}" )
229 SET(CPACK_SOURCE_IGNORE_FILES ~$ .svn ${CPACK_SOURCE_IGNORE_FILES} )
230 ENDIF(WIN32 AND NOT UNIX)
234 # --------------------------------------------------
235 # By default static library
236 OPTION(BUILD_SHARED_LIBS "Build shared libraries" OFF )
237 OPTION(BUILD_STATIC_LIBS "Build static libraries" ON )
238 #OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON )
241 set(ALL_TARGETS ${ALL_TARGETS} blas)
242 endif(NOT BLAS_FOUND)
244 if(NOT LATESTLAPACK_FOUND)
245 set(ALL_TARGETS ${ALL_TARGETS} lapack)
246 endif(NOT LATESTLAPACK_FOUND)
248 if(BUILD_TESTING OR LAPACKE_WITH_TMG)
249 set(ALL_TARGETS ${ALL_TARGETS} tmglib)
250 endif(BUILD_TESTING OR LAPACKE_WITH_TMG)
252 # Export lapack targets, not including lapacke, from the
253 # install tree, if any.
254 set(_lapack_config_install_guard_target "")
256 install(EXPORT lapack-targets
257 DESTINATION lib/cmake/lapack-${LAPACK_VERSION})
259 # Choose one of the lapack targets to use as a guard for
260 # lapack-config.cmake to load targets from the install tree.
261 list(GET ALL_TARGETS 0 _lapack_config_install_guard_target)
264 # Include lapacke in targets exported from the build tree.
266 set(ALL_TARGETS ${ALL_TARGETS} lapacke)
269 # Export lapack and lapacke targets from the build tree, if any.
270 set(_lapack_config_build_guard_target "")
272 export(TARGETS ${ALL_TARGETS} FILE lapack-targets.cmake)
274 # Choose one of the lapack or lapacke targets to use as a guard
275 # for lapack-config.cmake to load targets from the build tree.
276 list(GET ALL_TARGETS 0 _lapack_config_build_guard_target)
279 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-version.cmake.in
280 ${LAPACK_BINARY_DIR}/lapack-config-version.cmake @ONLY)
281 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-build.cmake.in
282 ${LAPACK_BINARY_DIR}/lapack-config.cmake @ONLY)
285 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lapack.pc.in ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc)
287 ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc
288 DESTINATION ${PKG_CONFIG_DIR}
291 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-install.cmake.in
292 ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake @ONLY)
294 ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake
295 ${LAPACK_BINARY_DIR}/lapack-config-version.cmake
296 DESTINATION lib/cmake/lapack-${LAPACK_VERSION}