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