Update version number in CMAKE - Thanks Allan Wollaber for the bug report (April...
[platform/upstream/lapack.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8.10)
2 project(LAPACK Fortran)
3
4 set(LAPACK_VERSION 3.5.0)
5
6 # Configure the warning and code coverage suppression file
7 configure_file( 
8   "${LAPACK_SOURCE_DIR}/CTestCustom.cmake.in"
9   "${LAPACK_BINARY_DIR}/CTestCustom.cmake"
10   COPYONLY
11 )
12
13 # Add the CMake directory for custon CMake modules
14 set(CMAKE_MODULE_PATH "${LAPACK_SOURCE_DIR}/CMAKE" ${CMAKE_MODULE_PATH})
15
16 if (UNIX)
17    if ( "${CMAKE_Fortran_COMPILER}" MATCHES "ifort" )
18   set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fltconsistency -fp_port" )
19    endif ()
20    if ( "${CMAKE_Fortran_COMPILER}" MATCHES "xlf" )
21   set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qnosave -qstrict=none" )
22    endif ()
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}")
26 endif ()
27
28 # Get Python
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}")
33 endif()
34 # --------------------------------------------------
35
36 set(LAPACK_INSTALL_EXPORT_NAME lapack-targets)
37
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
44   )
45 endmacro()
46
47 # --------------------------------------------------
48 # Testing
49
50 enable_testing()
51 include(CTest)
52 enable_testing()
53 # --------------------------------------------------
54
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)
60
61 # --------------------------------------------------
62 # Check for any necessary platform specific compiler flags
63 include( CheckLAPACKCompilerFlags )
64 CheckLAPACKCompilerFlags()
65
66 # --------------------------------------------------
67 # Check second function
68
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.")
77
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)
83
84 # --------------------------------------------------
85 # Precision to build
86 # By default all precisions are generated
87
88
89 # --------------------------------------------------
90 # Subdirectories that need to be processed
91
92 option(USE_OPTIMIZED_BLAS "Whether or not to use an optimized BLAS library instead of included netlib BLAS" OFF)
93
94
95 # Check the usage of the user provided BLAS libraries
96 if(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 )
101   if(BLAS_FOUND)
102     message(STATUS "--> BLAS supplied by user is WORKING, will use ${BLAS_LIBRARIES}.")
103   else(BLAS_FOUND)
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")
108   endif(BLAS_FOUND)
109
110 # User did not provide a BLAS Library but specified to search for one
111 elseif( USE_OPTIMIZED_BLAS )
112   find_package( BLAS )
113 endif (BLAS_LIBRARIES)
114
115 # Neither user specified or optimized BLAS libraries can be used
116 if(NOT BLAS_FOUND)
117   message(STATUS "Using supplied NETLIB BLAS implementation")
118   add_subdirectory(BLAS)
119   set( BLAS_LIBRARIES blas )
120 else()
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 )
131
132 option(USE_XBLAS "Build extended precision (needs XBLAS)" OFF)
133 if (USE_XBLAS)
134   find_library(XBLAS_LIBRARY NAMES xblas)
135 endif(USE_XBLAS)
136    
137 option(USE_OPTIMIZED_LAPACK "Whether or not to use an optimized LAPACK library instead of included netlib LAPACK" OFF)
138
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)
143
144 # Check the usage of the user provided or automatically found LAPACK libraries
145 if(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}.")
153   else(LAPACK_FOUND)
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)
160
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)
170 else()
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 )
181
182 message(STATUS "BUILD TESTING : ${BUILD_TESTING}" )
183 if(BUILD_TESTING)
184   add_subdirectory(TESTING)
185 endif(BUILD_TESTING)
186
187 # --------------------------------------------------
188 # LAPACKE
189 option(LAPACKE "Build LAPACKE" OFF)
190
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)
195   set(LAPACKE ON)
196   if(NOT BUILD_TESTING)
197      add_subdirectory(TESTING/MATGEN)
198    endif(NOT BUILD_TESTING)
199 endif(LAPACKE_WITH_TMG)
200
201 if(LAPACKE)
202   add_subdirectory(lapacke)
203 endif(LAPACKE)
204
205 # --------------------------------------------------
206 # CPACK Packaging 
207
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 5)
213 set(CPACK_PACKAGE_VERSION_PATCH 0)
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)
231 INCLUDE(CPack)
232
233
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 )
239
240 if(NOT BLAS_FOUND)
241   set(ALL_TARGETS ${ALL_TARGETS} blas)
242 endif(NOT BLAS_FOUND)
243
244 if(NOT LATESTLAPACK_FOUND)
245   set(ALL_TARGETS ${ALL_TARGETS} lapack)
246 endif(NOT LATESTLAPACK_FOUND)
247
248 if(BUILD_TESTING OR LAPACKE_WITH_TMG)
249   set(ALL_TARGETS ${ALL_TARGETS} tmglib)
250 endif(BUILD_TESTING OR LAPACKE_WITH_TMG)
251
252 # Export lapack targets, not including lapacke, from the
253 # install tree, if any.
254 set(_lapack_config_install_guard_target "")
255 if(ALL_TARGETS)
256   install(EXPORT lapack-targets
257     DESTINATION lib/cmake/lapack-${LAPACK_VERSION})
258
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)
262 endif()
263
264 # Include lapacke in targets exported from the build tree.
265 if(LAPACKE)
266   set(ALL_TARGETS ${ALL_TARGETS} lapacke)
267 endif(LAPACKE)
268
269 # Export lapack and lapacke targets from the build tree, if any.
270 set(_lapack_config_build_guard_target "")
271 if(ALL_TARGETS)
272   export(TARGETS ${ALL_TARGETS} FILE lapack-targets.cmake)
273
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)
277 endif()
278
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)
283
284
285 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lapack.pc.in ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc)
286   install(FILES
287   ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc
288   DESTINATION ${PKG_CONFIG_DIR}
289    )
290
291 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-install.cmake.in
292   ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake @ONLY)
293 install(FILES
294   ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake
295   ${LAPACK_BINARY_DIR}/lapack-config-version.cmake
296   DESTINATION lib/cmake/lapack-${LAPACK_VERSION}
297   )