1 cmake_minimum_required(VERSION 2.8.7)
2 project(LAPACK Fortran)
4 # Configure the warning and code coverage suppression file
6 "${LAPACK_SOURCE_DIR}/CTestCustom.cmake.in"
7 "${LAPACK_BINARY_DIR}/CTestCustom.cmake"
11 # Add the CMake directory for custon CMake modules
12 set(CMAKE_MODULE_PATH "${LAPACK_SOURCE_DIR}/CMAKE" ${CMAKE_MODULE_PATH})
15 if ( "${CMAKE_Fortran_COMPILER}" MATCHES "ifort" )
16 set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fltconsistency -fp_port" )
18 if ( "${CMAKE_Fortran_COMPILER}" MATCHES "xlf" )
19 set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qnosave -qstrict=none" )
21 # Delete libmtsk in linking sequence for Sun/Oracle Fortran Compiler.
22 # This library is not present in the Sun package SolarisStudio12.3-linux-x86-bin
23 STRING(REPLACE \;mtsk\; \; CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}")
27 find_package(PythonInterp)
28 message(STATUS "Looking for Python found - ${PYTHONINTERP_FOUND}")
29 if (PYTHONINTERP_FOUND)
30 message(STATUS "Using Python version ${PYTHON_VERSION_STRING}")
32 # --------------------------------------------------
34 macro(lapack_install_library lib)
35 install(TARGETS ${lib} EXPORT lapack-targets
36 ARCHIVE DESTINATION lib${LIB_SUFFIX}
37 LIBRARY DESTINATION lib${LIB_SUFFIX}
38 RUNTIME DESTINATION bin
42 # --------------------------------------------------
48 # --------------------------------------------------
50 # Organize output files. On Windows this also keeps .dll files next
51 # to the .exe files that need them, making tests easy to run.
52 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/bin)
53 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/lib)
54 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/lib)
56 # --------------------------------------------------
57 # Check for any necessary platform specific compiler flags
58 include( CheckLAPACKCompilerFlags )
59 CheckLAPACKCompilerFlags()
61 # --------------------------------------------------
62 # Check second function
64 include(CheckTimeFunction)
65 set(TIME_FUNC NONE ${TIME_FUNC})
66 CHECK_TIME_FUNCTION(NONE TIME_FUNC)
67 CHECK_TIME_FUNCTION(INT_CPU_TIME TIME_FUNC)
68 CHECK_TIME_FUNCTION(EXT_ETIME TIME_FUNC)
69 CHECK_TIME_FUNCTION(EXT_ETIME_ TIME_FUNC)
70 CHECK_TIME_FUNCTION(INT_ETIME TIME_FUNC)
71 message(STATUS "--> Will use second_${TIME_FUNC}.f and dsecnd_${TIME_FUNC}.f as timing function.")
73 set(SECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/second_${TIME_FUNC}.f)
74 set(DSECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/dsecnd_${TIME_FUNC}.f)
75 set(prefix ${CMAKE_INSTALL_PREFIX})
76 set(libdir ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX})
77 set(PKG_CONFIG_DIR ${libdir}/pkgconfig)
79 # --------------------------------------------------
81 # By default all precisions are generated
84 # --------------------------------------------------
85 # Subdirectories that need to be processed
87 option(USE_OPTIMIZED_BLAS "Whether or not to use an optimized BLAS library instead of included netlib BLAS" OFF)
90 # Check the usage of the user provided BLAS libraries
92 include(CheckFortranFunctionExists)
93 set(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})
94 CHECK_FORTRAN_FUNCTION_EXISTS("dgemm" BLAS_FOUND)
95 unset( CMAKE_REQUIRED_LIBRARIES )
97 message(STATUS "--> BLAS supplied by user is WORKING, will use ${BLAS_LIBRARIES}.")
99 message(ERROR "--> BLAS supplied by user is not WORKING, CANNOT USE ${BLAS_LIBRARIES}.")
100 message(ERROR "--> Will use REFERENCE BLAS (by default)")
101 message(ERROR "--> Or Correct your BLAS_LIBRARIES entry ")
102 message(ERROR "--> Or Consider checking USE_OPTIMIZED_BLAS")
105 # User did not provide a BLAS Library but specified to search for one
106 elseif( USE_OPTIMIZED_BLAS )
108 endif (BLAS_LIBRARIES)
110 # Neither user specified or optimized BLAS libraries can be used
112 message(STATUS "Using supplied NETLIB BLAS implementation")
113 add_subdirectory(BLAS)
114 set( BLAS_LIBRARIES blas )
116 set( CMAKE_EXE_LINKER_FLAGS
117 "${CMAKE_EXE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
118 CACHE STRING "Linker flags for executables" FORCE)
119 set( CMAKE_MODULE_LINKER_FLAGS
120 "${CMAKE_MODULE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
121 CACHE STRING "Linker flags for modules" FORCE)
122 set( CMAKE_SHARED_LINKER_FLAGS
123 "${CMAKE_SHARED_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
124 CACHE STRING "Linker flags for shared libs" FORCE)
125 endif( NOT BLAS_FOUND )
127 option(USE_XBLAS "Build extended precision (needs XBLAS)" OFF)
129 find_library(XBLAS_LIBRARY NAMES xblas)
132 option(USE_OPTIMIZED_LAPACK "Whether or not to use an optimized LAPACK library instead of included netlib LAPACK" OFF)
134 # User did not provide a LAPACK Library but specified to search for one
135 if( USE_OPTIMIZED_LAPACK )
136 find_package( LAPACK )
137 endif (USE_OPTIMIZED_LAPACK)
139 # Check the usage of the user provided or automatically found LAPACK libraries
141 include(CheckFortranFunctionExists)
142 set(CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARIES})
143 # Check if new routine of 3.4.0 is in LAPACK_LIBRARIES
144 CHECK_FORTRAN_FUNCTION_EXISTS("dgeqrt" LATESTLAPACK_FOUND)
145 unset( CMAKE_REQUIRED_LIBRARIES )
146 if(LATESTLAPACK_FOUND)
147 message(STATUS "--> LAPACK supplied by user is WORKING, will use ${LAPACK_LIBRARIES}.")
149 message(ERROR "--> LAPACK supplied by user is not WORKING or is older than LAPACK 3.4.0, CANNOT USE ${LAPACK_LIBRARIES}.")
150 message(ERROR "--> Will use REFERENCE LAPACK (by default)")
151 message(ERROR "--> Or Correct your LAPACK_LIBRARIES entry ")
152 message(ERROR "--> Or Consider checking USE_OPTIMIZED_LAPACK")
153 endif(LATESTLAPACK_FOUND)
154 endif (LAPACK_LIBRARIES)
156 # Neither user specified or optimized LAPACK libraries can be used
157 if(NOT LATESTLAPACK_FOUND)
158 message(STATUS "Using supplied NETLIB LAPACK implementation")
159 set( LAPACK_LIBRARIES lapack )
160 option(BUILD_SINGLE "Build LAPACK Single Precision" ON)
161 option(BUILD_DOUBLE "Build LAPACK Double Precision" ON)
162 option(BUILD_COMPLEX "Build LAPACK Complex Precision" ON)
163 option(BUILD_COMPLEX16 "Build LAPACK Double Complex Precision" ON)
164 add_subdirectory(SRC)
166 set( CMAKE_EXE_LINKER_FLAGS
167 "${CMAKE_EXE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
168 CACHE STRING "Linker flags for executables" FORCE)
169 set( CMAKE_MODULE_LINKER_FLAGS
170 "${CMAKE_MODULE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
171 CACHE STRING "Linker flags for modules" FORCE)
172 set( CMAKE_SHARED_LINKER_FLAGS
173 "${CMAKE_SHARED_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
174 CACHE STRING "Linker flags for shared libs" FORCE)
175 endif( NOT LATESTLAPACK_FOUND )
177 message(STATUS "BUILD TESTING : ${BUILD_TESTING}" )
179 add_subdirectory(TESTING)
182 # --------------------------------------------------
184 option(LAPACKE "Build LAPACKE" OFF)
186 # LAPACKE has also the interface to some routines from tmglib,
187 # if LAPACKE_WITH_TMG is selected, we need to add those routines to LAPACKE
188 option(LAPACKE_WITH_TMG "Build LAPACKE with tmglib routines" OFF)
189 if (LAPACKE_WITH_TMG)
191 if(NOT BUILD_TESTING)
192 add_subdirectory(TESTING/MATGEN)
193 endif(NOT BUILD_TESTING)
194 endif(LAPACKE_WITH_TMG)
197 add_subdirectory(lapacke)
200 # --------------------------------------------------
203 SET(CPACK_PACKAGE_NAME "LAPACK")
204 SET(CPACK_PACKAGE_VENDOR "University of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd")
205 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LAPACK- Linear Algebra Package")
206 set(LAPACK_VERSION 3.4.2)
207 set(CPACK_PACKAGE_VERSION_MAJOR 3)
208 set(CPACK_PACKAGE_VERSION_MINOR 4)
209 set(CPACK_PACKAGE_VERSION_PATCH 2)
210 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
211 SET(CPACK_PACKAGE_INSTALL_DIRECTORY "LAPACK")
212 IF(WIN32 AND NOT UNIX)
213 # There is a bug in NSI that does not handle full unix paths properly. Make
214 # sure there is at least one set of four (4) backlasshes.
215 SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\http://icl.cs.utk.edu/lapack-forum")
216 SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.netlib.org/lapack")
217 SET(CPACK_NSIS_CONTACT "lapack@eecs.utk.edu")
218 SET(CPACK_NSIS_MODIFY_PATH ON)
219 SET(CPACK_NSIS_DISPLAY_NAME "LAPACK-${LAPACK_VERSION}")
220 set(CPACK_PACKAGE_RELOCATABLE "true")
221 ELSE(WIN32 AND NOT UNIX)
222 SET(CPACK_GENERATOR "TGZ")
223 SET(CPACK_SOURCE_GENERATOR TGZ)
224 SET(CPACK_SOURCE_PACKAGE_FILE_NAME "lapack-${LAPACK_VERSION}" )
225 SET(CPACK_SOURCE_IGNORE_FILES ~$ .svn ${CPACK_SOURCE_IGNORE_FILES} )
226 ENDIF(WIN32 AND NOT UNIX)
230 # --------------------------------------------------
231 # By default static library
232 OPTION(BUILD_SHARED_LIBS "Build shared libraries" OFF )
233 OPTION(BUILD_STATIC_LIBS "Build static libraries" ON )
234 #OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON )
237 set(ALL_TARGETS ${ALL_TARGETS} blas)
238 endif(NOT BLAS_FOUND)
240 if(NOT LATESTLAPACK_FOUND)
241 set(ALL_TARGETS ${ALL_TARGETS} lapack)
242 endif(NOT LATESTLAPACK_FOUND)
244 if(BUILD_TESTING OR LAPACKE_WITH_TMG)
245 set(ALL_TARGETS ${ALL_TARGETS} tmglib)
246 endif(BUILD_TESTING OR LAPACKE_WITH_TMG)
249 set(ALL_TARGETS ${ALL_TARGETS} lapacke)
252 export(TARGETS ${ALL_TARGETS} FILE lapack-targets.cmake)
254 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-version.cmake.in
255 ${LAPACK_BINARY_DIR}/lapack-config-version.cmake @ONLY)
256 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-build.cmake.in
257 ${LAPACK_BINARY_DIR}/lapack-config.cmake @ONLY)
260 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lapack.pc.in ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc)
262 ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc
263 DESTINATION ${PKG_CONFIG_DIR}
266 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-install.cmake.in
267 ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake @ONLY)
269 ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake
270 ${LAPACK_BINARY_DIR}/lapack-config-version.cmake
271 DESTINATION lib/cmake/lapack-${LAPACK_VERSION}
274 install(EXPORT lapack-targets
275 DESTINATION lib/cmake/lapack-${LAPACK_VERSION})