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