Commit to integrate CMAKE and MAKEFILE build system for CBLAS
[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
133 # --------------------------------------------------
134 # CBLAS
135 option(CBLAS "Build CBLAS" OFF)
136
137 if(CBLAS)
138   add_subdirectory(cblas)
139 endif(CBLAS)
140
141 # --------------------------------------------------
142 # XBLAS
143
144 option(USE_XBLAS "Build extended precision (needs XBLAS)" OFF)
145 if (USE_XBLAS)
146   find_library(XBLAS_LIBRARY NAMES xblas)
147 endif(USE_XBLAS)
148    
149 option(USE_OPTIMIZED_LAPACK "Whether or not to use an optimized LAPACK library instead of included netlib LAPACK" OFF)
150
151 # --------------------------------------------------
152 # LAPACK
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)
157
158 # Check the usage of the user provided or automatically found LAPACK libraries
159 if(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}.")
167   else(LAPACK_FOUND)
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)
174
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)
184 else()
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 )
195
196 message(STATUS "BUILD TESTING : ${BUILD_TESTING}" )
197 if(BUILD_TESTING)
198   add_subdirectory(TESTING)
199 endif(BUILD_TESTING)
200
201 # --------------------------------------------------
202 # LAPACKE
203 option(LAPACKE "Build LAPACKE" OFF)
204
205 # LAPACKE has also the interface to some routines from tmglib,
206 # if LAPACKE_WITH_TMG is selected, we need to add those routines to LAPACKE
207 option(LAPACKE_WITH_TMG "Build LAPACKE with tmglib routines" OFF)
208 if (LAPACKE_WITH_TMG)
209   set(LAPACKE ON)
210   if(NOT BUILD_TESTING)
211      add_subdirectory(TESTING/MATGEN)
212    endif(NOT BUILD_TESTING)
213 endif(LAPACKE_WITH_TMG)
214
215 if(LAPACKE)
216   add_subdirectory(lapacke)
217 endif(LAPACKE)
218
219 # --------------------------------------------------
220 # CPACK Packaging 
221
222 SET(CPACK_PACKAGE_NAME "LAPACK")
223 SET(CPACK_PACKAGE_VENDOR "University of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd")
224 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LAPACK- Linear Algebra Package")
225 set(CPACK_PACKAGE_VERSION_MAJOR 3)
226 set(CPACK_PACKAGE_VERSION_MINOR 5)
227 set(CPACK_PACKAGE_VERSION_PATCH 0)
228 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
229 SET(CPACK_PACKAGE_INSTALL_DIRECTORY "LAPACK")
230 IF(WIN32 AND NOT UNIX)
231   # There is a bug in NSI that does not handle full unix paths properly. Make
232   # sure there is at least one set of four (4) backlasshes.
233   SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\http://icl.cs.utk.edu/lapack-forum")
234   SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.netlib.org/lapack")
235   SET(CPACK_NSIS_CONTACT "lapack@eecs.utk.edu")
236   SET(CPACK_NSIS_MODIFY_PATH ON)
237   SET(CPACK_NSIS_DISPLAY_NAME "LAPACK-${LAPACK_VERSION}")
238   set(CPACK_PACKAGE_RELOCATABLE "true")
239 ELSE(WIN32 AND NOT UNIX)
240   SET(CPACK_GENERATOR "TGZ")
241   SET(CPACK_SOURCE_GENERATOR TGZ)
242   SET(CPACK_SOURCE_PACKAGE_FILE_NAME "lapack-${LAPACK_VERSION}" )
243   SET(CPACK_SOURCE_IGNORE_FILES ~$ .svn ${CPACK_SOURCE_IGNORE_FILES} )
244 ENDIF(WIN32 AND NOT UNIX)
245 INCLUDE(CPack)
246
247
248 # --------------------------------------------------
249 # By default static library
250 OPTION(BUILD_SHARED_LIBS "Build shared libraries" OFF )
251 OPTION(BUILD_STATIC_LIBS "Build static libraries" ON )
252 #OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON )
253
254 if(NOT BLAS_FOUND)
255   set(ALL_TARGETS ${ALL_TARGETS} blas)
256 endif(NOT BLAS_FOUND)
257
258 if(NOT LATESTLAPACK_FOUND)
259   set(ALL_TARGETS ${ALL_TARGETS} lapack)
260 endif(NOT LATESTLAPACK_FOUND)
261
262 if(BUILD_TESTING OR LAPACKE_WITH_TMG)
263   set(ALL_TARGETS ${ALL_TARGETS} tmglib)
264 endif(BUILD_TESTING OR LAPACKE_WITH_TMG)
265
266 # Export lapack targets, not including lapacke, from the
267 # install tree, if any.
268 set(_lapack_config_install_guard_target "")
269 if(ALL_TARGETS)
270   install(EXPORT lapack-targets
271     DESTINATION lib/cmake/lapack-${LAPACK_VERSION})
272
273   # Choose one of the lapack targets to use as a guard for
274   # lapack-config.cmake to load targets from the install tree.
275   list(GET ALL_TARGETS 0 _lapack_config_install_guard_target)
276 endif()
277
278 # Include cblas in targets exported from the build tree.
279 if(CBLAS)
280   set(ALL_TARGETS ${ALL_TARGETS} cblas)
281 endif(CBLAS)
282
283 # Include lapacke in targets exported from the build tree.
284 if(LAPACKE)
285   set(ALL_TARGETS ${ALL_TARGETS} lapacke)
286 endif(LAPACKE)
287
288 # Export lapack and lapacke targets from the build tree, if any.
289 set(_lapack_config_build_guard_target "")
290 if(ALL_TARGETS)
291   export(TARGETS ${ALL_TARGETS} FILE lapack-targets.cmake)
292
293   # Choose one of the lapack or lapacke targets to use as a guard
294   # for lapack-config.cmake to load targets from the build tree.
295   list(GET ALL_TARGETS 0 _lapack_config_build_guard_target)
296 endif()
297
298 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-version.cmake.in
299   ${LAPACK_BINARY_DIR}/lapack-config-version.cmake @ONLY)
300 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-build.cmake.in
301   ${LAPACK_BINARY_DIR}/lapack-config.cmake @ONLY)
302
303
304 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lapack.pc.in ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc)
305   install(FILES
306   ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc
307   DESTINATION ${PKG_CONFIG_DIR}
308    )
309
310 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-install.cmake.in
311   ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake @ONLY)
312 install(FILES
313   ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake
314   ${LAPACK_BINARY_DIR}/lapack-config-version.cmake
315   DESTINATION lib/cmake/lapack-${LAPACK_VERSION}
316   )