1 cmake_minimum_required(VERSION 2.8.10)
2 project(LAPACK Fortran)
4 set(LAPACK_VERSION 3.5.0)
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 )
133 # --------------------------------------------------
135 option(CBLAS "Build CBLAS" OFF)
138 add_subdirectory(CBLAS)
141 # --------------------------------------------------
144 option(USE_XBLAS "Build extended precision (needs XBLAS)" OFF)
146 find_library(XBLAS_LIBRARY NAMES xblas)
149 option(USE_OPTIMIZED_LAPACK "Whether or not to use an optimized LAPACK library instead of included netlib LAPACK" OFF)
151 # --------------------------------------------------
153 # User did not provide a LAPACK Library but specified to search for one
154 if( USE_OPTIMIZED_LAPACK )
155 find_package( LAPACK )
156 endif (USE_OPTIMIZED_LAPACK)
158 # Check the usage of the user provided or automatically found LAPACK libraries
160 include(CheckFortranFunctionExists)
161 set(CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARIES})
162 # Check if new routine of 3.4.0 is in LAPACK_LIBRARIES
163 CHECK_FORTRAN_FUNCTION_EXISTS("dgeqrt" LATESTLAPACK_FOUND)
164 unset( CMAKE_REQUIRED_LIBRARIES )
165 if(LATESTLAPACK_FOUND)
166 message(STATUS "--> LAPACK supplied by user is WORKING, will use ${LAPACK_LIBRARIES}.")
168 message(ERROR "--> LAPACK supplied by user is not WORKING or is older than LAPACK 3.4.0, CANNOT USE ${LAPACK_LIBRARIES}.")
169 message(ERROR "--> Will use REFERENCE LAPACK (by default)")
170 message(ERROR "--> Or Correct your LAPACK_LIBRARIES entry ")
171 message(ERROR "--> Or Consider checking USE_OPTIMIZED_LAPACK")
172 endif(LATESTLAPACK_FOUND)
173 endif (LAPACK_LIBRARIES)
175 # Neither user specified or optimized LAPACK libraries can be used
176 if(NOT LATESTLAPACK_FOUND)
177 message(STATUS "Using supplied NETLIB LAPACK implementation")
178 set( LAPACK_LIBRARIES lapack )
179 option(BUILD_SINGLE "Build LAPACK Single Precision" ON)
180 option(BUILD_DOUBLE "Build LAPACK Double Precision" ON)
181 option(BUILD_COMPLEX "Build LAPACK Complex Precision" ON)
182 option(BUILD_COMPLEX16 "Build LAPACK Double Complex Precision" ON)
183 add_subdirectory(SRC)
185 set( CMAKE_EXE_LINKER_FLAGS
186 "${CMAKE_EXE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
187 CACHE STRING "Linker flags for executables" FORCE)
188 set( CMAKE_MODULE_LINKER_FLAGS
189 "${CMAKE_MODULE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
190 CACHE STRING "Linker flags for modules" FORCE)
191 set( CMAKE_SHARED_LINKER_FLAGS
192 "${CMAKE_SHARED_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
193 CACHE STRING "Linker flags for shared libs" FORCE)
194 endif( NOT LATESTLAPACK_FOUND )
196 message(STATUS "BUILD TESTING : ${BUILD_TESTING}" )
198 add_subdirectory(TESTING)
201 # deprecated LAPACK routines
202 option(BUILD_DEPRECATED "Build deprecated routines" OFF)
204 # --------------------------------------------------
206 option(LAPACKE "Build LAPACKE" OFF)
208 # LAPACKE has also the interface to some routines from tmglib,
209 # if LAPACKE_WITH_TMG is selected, we need to add those routines to LAPACKE
210 option(LAPACKE_WITH_TMG "Build LAPACKE with tmglib routines" OFF)
211 if (LAPACKE_WITH_TMG)
213 if(NOT BUILD_TESTING)
214 add_subdirectory(TESTING/MATGEN)
215 endif(NOT BUILD_TESTING)
216 endif(LAPACKE_WITH_TMG)
219 add_subdirectory(LAPACKE)
222 # --------------------------------------------------
225 SET(CPACK_PACKAGE_NAME "LAPACK")
226 SET(CPACK_PACKAGE_VENDOR "University of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd")
227 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LAPACK- Linear Algebra Package")
228 set(CPACK_PACKAGE_VERSION_MAJOR 3)
229 set(CPACK_PACKAGE_VERSION_MINOR 5)
230 set(CPACK_PACKAGE_VERSION_PATCH 0)
231 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
232 SET(CPACK_PACKAGE_INSTALL_DIRECTORY "LAPACK")
233 IF(WIN32 AND NOT UNIX)
234 # There is a bug in NSI that does not handle full unix paths properly. Make
235 # sure there is at least one set of four (4) backlasshes.
236 SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\http://icl.cs.utk.edu/lapack-forum")
237 SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.netlib.org/lapack")
238 SET(CPACK_NSIS_CONTACT "lapack@eecs.utk.edu")
239 SET(CPACK_NSIS_MODIFY_PATH ON)
240 SET(CPACK_NSIS_DISPLAY_NAME "LAPACK-${LAPACK_VERSION}")
241 set(CPACK_PACKAGE_RELOCATABLE "true")
242 ELSE(WIN32 AND NOT UNIX)
243 SET(CPACK_GENERATOR "TGZ")
244 SET(CPACK_SOURCE_GENERATOR TGZ)
245 SET(CPACK_SOURCE_PACKAGE_FILE_NAME "lapack-${LAPACK_VERSION}" )
246 SET(CPACK_SOURCE_IGNORE_FILES ~$ .svn ${CPACK_SOURCE_IGNORE_FILES} )
247 ENDIF(WIN32 AND NOT UNIX)
251 # --------------------------------------------------
252 # By default static library
253 OPTION(BUILD_SHARED_LIBS "Build shared libraries" OFF )
254 OPTION(BUILD_STATIC_LIBS "Build static libraries" ON )
255 #OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON )
258 set(ALL_TARGETS ${ALL_TARGETS} blas)
259 endif(NOT BLAS_FOUND)
261 if(NOT LATESTLAPACK_FOUND)
262 set(ALL_TARGETS ${ALL_TARGETS} lapack)
263 endif(NOT LATESTLAPACK_FOUND)
265 if(BUILD_TESTING OR LAPACKE_WITH_TMG)
266 set(ALL_TARGETS ${ALL_TARGETS} tmglib)
267 endif(BUILD_TESTING OR LAPACKE_WITH_TMG)
269 # Export lapack targets, not including lapacke, from the
270 # install tree, if any.
271 set(_lapack_config_install_guard_target "")
273 install(EXPORT lapack-targets
274 DESTINATION lib/cmake/lapack-${LAPACK_VERSION})
276 # Choose one of the lapack targets to use as a guard for
277 # lapack-config.cmake to load targets from the install tree.
278 list(GET ALL_TARGETS 0 _lapack_config_install_guard_target)
281 # Include cblas in targets exported from the build tree.
283 set(ALL_TARGETS ${ALL_TARGETS} cblas)
286 # Include lapacke in targets exported from the build tree.
288 set(ALL_TARGETS ${ALL_TARGETS} lapacke)
291 # Export lapack and lapacke targets from the build tree, if any.
292 set(_lapack_config_build_guard_target "")
294 export(TARGETS ${ALL_TARGETS} FILE lapack-targets.cmake)
296 # Choose one of the lapack or lapacke targets to use as a guard
297 # for lapack-config.cmake to load targets from the build tree.
298 list(GET ALL_TARGETS 0 _lapack_config_build_guard_target)
301 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-version.cmake.in
302 ${LAPACK_BINARY_DIR}/lapack-config-version.cmake @ONLY)
303 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-build.cmake.in
304 ${LAPACK_BINARY_DIR}/lapack-config.cmake @ONLY)
307 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lapack.pc.in ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc)
309 ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc
310 DESTINATION ${PKG_CONFIG_DIR}
313 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-install.cmake.in
314 ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake @ONLY)
316 ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake
317 ${LAPACK_BINARY_DIR}/lapack-config-version.cmake
318 DESTINATION lib/cmake/lapack-${LAPACK_VERSION}