Commit patch submitted by Orion Poplawski on Nov 18th 2015 on LAPACK mailing List
[platform/upstream/lapack.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8.10)
2 project(LAPACK Fortran)
3
4 set(LAPACK_MAJOR_VERSION 3)
5 set(LAPACK_MINOR_VERSION 6)
6 set(LAPACK_PATCH_VERSION 0)
7 set(
8   LAPACK_VERSION
9   ${LAPACK_MAJOR_VERSION}.${LAPACK_MINOR_VERSION}.${LAPACK_PATCH_VERSION}
10   )
11
12 # Updated OSX RPATH settings
13 # In response to CMake 3.0 generating warnings regarding policy CMP0042,
14 # the OSX RPATH settings have been updated per recommendations found
15 # in the CMake Wiki:
16 #  http://www.cmake.org/Wiki/CMake_RPATH_handling#Mac_OS_X_and_the_RPATH
17     set(CMAKE_MACOSX_RPATH ON)
18     set(CMAKE_SKIP_BUILD_RPATH FALSE)
19     set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
20     list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}" isSystemDir)
21     if("${isSystemDir}" STREQUAL "-1")
22         set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
23         set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
24     endif()
25
26
27 # Configure the warning and code coverage suppression file
28 configure_file(
29   "${LAPACK_SOURCE_DIR}/CTestCustom.cmake.in"
30   "${LAPACK_BINARY_DIR}/CTestCustom.cmake"
31   COPYONLY
32 )
33
34 # Add the CMake directory for custon CMake modules
35 set(CMAKE_MODULE_PATH "${LAPACK_SOURCE_DIR}/CMAKE" ${CMAKE_MODULE_PATH})
36
37 if (UNIX)
38    if ( "${CMAKE_Fortran_COMPILER}" MATCHES "ifort" )
39   set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fltconsistency -fp_port" )
40    endif ()
41    if ( "${CMAKE_Fortran_COMPILER}" MATCHES "xlf" )
42   set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qnosave -qstrict=none" )
43    endif ()
44 # Delete libmtsk in linking sequence for Sun/Oracle Fortran Compiler.
45 # This library is not present in the Sun package SolarisStudio12.3-linux-x86-bin
46    STRING(REPLACE \;mtsk\; \; CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}")
47 endif ()
48
49 # Get Python
50 find_package(PythonInterp)
51 message(STATUS "Looking for Python found - ${PYTHONINTERP_FOUND}")
52 if (PYTHONINTERP_FOUND)
53    message(STATUS "Using Python version ${PYTHON_VERSION_STRING}")
54 endif()
55 # --------------------------------------------------
56
57 set(LAPACK_INSTALL_EXPORT_NAME lapack-targets)
58
59 if (UNIX)
60   include(GNUInstallDirs)
61   set(ARCHIVE_DIR ${CMAKE_INSTALL_LIBDIR})
62   set(LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR})
63   set(RUNTIME_DIR ${CMAKE_INSTALL_BINDIR})
64 else()
65   set(ARCHIVE_DIR lib${LIB_SUFFIX})
66   set(LIBRARY_DIR lib${LIB_SUFFIX})
67   set(RUNTIME_DIR bin)
68 endif()
69
70 macro(lapack_install_library lib)
71   install(TARGETS ${lib}
72     EXPORT ${LAPACK_INSTALL_EXPORT_NAME}
73     ARCHIVE DESTINATION ${ARCHIVE_DIR}
74     LIBRARY DESTINATION ${LIBRARY_DIR}
75     RUNTIME DESTINATION ${RUNTIME_DIR}
76   )
77 endmacro()
78
79 # --------------------------------------------------
80 # Testing
81
82 enable_testing()
83 include(CTest)
84 enable_testing()
85 # --------------------------------------------------
86
87 # Organize output files.  On Windows this also keeps .dll files next
88 # to the .exe files that need them, making tests easy to run.
89 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/bin)
90 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/lib)
91 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/lib)
92
93 # --------------------------------------------------
94 # Check for any necessary platform specific compiler flags
95 include( CheckLAPACKCompilerFlags )
96 CheckLAPACKCompilerFlags()
97
98 # --------------------------------------------------
99 # Check second function
100
101 include(CheckTimeFunction)
102 set(TIME_FUNC NONE ${TIME_FUNC})
103 CHECK_TIME_FUNCTION(NONE TIME_FUNC)
104 CHECK_TIME_FUNCTION(INT_CPU_TIME TIME_FUNC)
105 CHECK_TIME_FUNCTION(EXT_ETIME TIME_FUNC)
106 CHECK_TIME_FUNCTION(EXT_ETIME_ TIME_FUNC)
107 CHECK_TIME_FUNCTION(INT_ETIME TIME_FUNC)
108 message(STATUS "--> Will use second_${TIME_FUNC}.f and dsecnd_${TIME_FUNC}.f as timing function.")
109
110 set(SECOND_SRC  ${LAPACK_SOURCE_DIR}/INSTALL/second_${TIME_FUNC}.f)
111 set(DSECOND_SRC  ${LAPACK_SOURCE_DIR}/INSTALL/dsecnd_${TIME_FUNC}.f)
112 set(PKG_CONFIG_DIR ${LIBRARY_DIR}/pkgconfig)
113
114 # --------------------------------------------------
115 # Precision to build
116 # By default all precisions are generated
117
118
119 # --------------------------------------------------
120 # Subdirectories that need to be processed
121
122 option(USE_OPTIMIZED_BLAS "Whether or not to use an optimized BLAS library instead of included netlib BLAS" OFF)
123
124
125 # Check the usage of the user provided BLAS libraries
126 if(BLAS_LIBRARIES)
127   include(CheckFortranFunctionExists)
128   set(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})
129   CHECK_FORTRAN_FUNCTION_EXISTS("dgemm" BLAS_FOUND)
130   unset( CMAKE_REQUIRED_LIBRARIES )
131   if(BLAS_FOUND)
132     message(STATUS "--> BLAS supplied by user is WORKING, will use ${BLAS_LIBRARIES}.")
133   else(BLAS_FOUND)
134     message(ERROR "--> BLAS supplied by user is not WORKING, CANNOT USE ${BLAS_LIBRARIES}.")
135     message(ERROR "-->     Will use REFERENCE BLAS (by default)")
136     message(ERROR "-->     Or Correct your BLAS_LIBRARIES entry ")
137     message(ERROR "-->     Or Consider checking USE_OPTIMIZED_BLAS")
138   endif(BLAS_FOUND)
139
140 # User did not provide a BLAS Library but specified to search for one
141 elseif( USE_OPTIMIZED_BLAS )
142   find_package( BLAS )
143 endif (BLAS_LIBRARIES)
144
145 # Neither user specified or optimized BLAS libraries can be used
146 if(NOT BLAS_FOUND)
147   message(STATUS "Using supplied NETLIB BLAS implementation")
148   add_subdirectory(BLAS)
149   set( BLAS_LIBRARIES blas )
150 else()
151   set( CMAKE_EXE_LINKER_FLAGS 
152     "${CMAKE_EXE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}" 
153     CACHE STRING "Linker flags for executables" FORCE)
154   set( CMAKE_MODULE_LINKER_FLAGS 
155     "${CMAKE_MODULE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}" 
156     CACHE STRING "Linker flags for modules" FORCE)
157   set( CMAKE_SHARED_LINKER_FLAGS 
158     "${CMAKE_SHARED_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}" 
159     CACHE STRING "Linker flags for shared libs" FORCE)
160 endif( NOT BLAS_FOUND )
161
162
163 # --------------------------------------------------
164 # CBLAS
165 option(CBLAS "Build CBLAS" OFF)
166
167 if(CBLAS)
168   add_subdirectory(CBLAS)
169 endif(CBLAS)
170
171 # --------------------------------------------------
172 # XBLAS
173
174 option(USE_XBLAS "Build extended precision (needs XBLAS)" OFF)
175 if (USE_XBLAS)
176   find_library(XBLAS_LIBRARY NAMES xblas)
177 endif(USE_XBLAS)
178    
179 option(USE_OPTIMIZED_LAPACK "Whether or not to use an optimized LAPACK library instead of included netlib LAPACK" OFF)
180
181 # --------------------------------------------------
182 # LAPACK
183 # User did not provide a LAPACK Library but specified to search for one
184 if( USE_OPTIMIZED_LAPACK )
185   find_package( LAPACK )
186 endif (USE_OPTIMIZED_LAPACK)
187
188 # Check the usage of the user provided or automatically found LAPACK libraries
189 if(LAPACK_LIBRARIES)
190   include(CheckFortranFunctionExists)
191   set(CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARIES})
192   # Check if new routine of 3.4.0 is in LAPACK_LIBRARIES
193   CHECK_FORTRAN_FUNCTION_EXISTS("dgeqrt" LATESTLAPACK_FOUND)
194   unset( CMAKE_REQUIRED_LIBRARIES )
195   if(LATESTLAPACK_FOUND)
196     message(STATUS "--> LAPACK supplied by user is WORKING, will use ${LAPACK_LIBRARIES}.")
197   else(LAPACK_FOUND)
198     message(ERROR "--> LAPACK supplied by user is not WORKING or is older than LAPACK 3.4.0,    CANNOT USE ${LAPACK_LIBRARIES}.")
199     message(ERROR "-->     Will use REFERENCE LAPACK (by default)")
200     message(ERROR "-->     Or Correct your LAPACK_LIBRARIES entry ")
201     message(ERROR "-->     Or Consider checking USE_OPTIMIZED_LAPACK")
202   endif(LATESTLAPACK_FOUND)
203 endif (LAPACK_LIBRARIES)
204
205 # Neither user specified or optimized LAPACK libraries can be used
206 if(NOT LATESTLAPACK_FOUND)
207   message(STATUS "Using supplied NETLIB LAPACK implementation")
208   set( LAPACK_LIBRARIES lapack )
209   option(BUILD_SINGLE "Build LAPACK Single Precision" ON)
210   option(BUILD_DOUBLE "Build LAPACK Double Precision" ON)
211   option(BUILD_COMPLEX "Build LAPACK Complex Precision" ON)
212   option(BUILD_COMPLEX16 "Build LAPACK Double Complex Precision" ON)
213   add_subdirectory(SRC)
214 else()
215   set( CMAKE_EXE_LINKER_FLAGS 
216     "${CMAKE_EXE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}" 
217     CACHE STRING "Linker flags for executables" FORCE)
218   set( CMAKE_MODULE_LINKER_FLAGS 
219     "${CMAKE_MODULE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}" 
220     CACHE STRING "Linker flags for modules" FORCE)
221   set( CMAKE_SHARED_LINKER_FLAGS 
222     "${CMAKE_SHARED_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}" 
223     CACHE STRING "Linker flags for shared libs" FORCE)
224 endif( NOT LATESTLAPACK_FOUND )
225
226 message(STATUS "BUILD TESTING : ${BUILD_TESTING}" )
227 if(BUILD_TESTING)
228   add_subdirectory(TESTING)
229 endif(BUILD_TESTING)
230
231 # deprecated LAPACK routines
232 option(BUILD_DEPRECATED "Build deprecated routines" OFF)
233
234 # --------------------------------------------------
235 # LAPACKE
236 option(LAPACKE "Build LAPACKE" OFF)
237
238 # LAPACKE has also the interface to some routines from tmglib,
239 # if LAPACKE_WITH_TMG is selected, we need to add those routines to LAPACKE
240 option(LAPACKE_WITH_TMG "Build LAPACKE with tmglib routines" OFF)
241 if (LAPACKE_WITH_TMG)
242   set(LAPACKE ON)
243   if(NOT BUILD_TESTING)
244      add_subdirectory(TESTING/MATGEN)
245    endif(NOT BUILD_TESTING)
246 endif(LAPACKE_WITH_TMG)
247
248 if(LAPACKE)
249   add_subdirectory(LAPACKE)
250 endif(LAPACKE)
251
252 # --------------------------------------------------
253 # CPACK Packaging 
254
255 SET(CPACK_PACKAGE_NAME "LAPACK")
256 SET(CPACK_PACKAGE_VENDOR "University of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd")
257 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LAPACK- Linear Algebra Package")
258 set(CPACK_PACKAGE_VERSION_MAJOR 3)
259 set(CPACK_PACKAGE_VERSION_MINOR 5)
260 set(CPACK_PACKAGE_VERSION_PATCH 0)
261 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
262 SET(CPACK_PACKAGE_INSTALL_DIRECTORY "LAPACK")
263 IF(WIN32 AND NOT UNIX)
264   # There is a bug in NSI that does not handle full unix paths properly. Make
265   # sure there is at least one set of four (4) backlasshes.
266   SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\http://icl.cs.utk.edu/lapack-forum")
267   SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.netlib.org/lapack")
268   SET(CPACK_NSIS_CONTACT "lapack@eecs.utk.edu")
269   SET(CPACK_NSIS_MODIFY_PATH ON)
270   SET(CPACK_NSIS_DISPLAY_NAME "LAPACK-${LAPACK_VERSION}")
271   set(CPACK_PACKAGE_RELOCATABLE "true")
272 ELSE(WIN32 AND NOT UNIX)
273   SET(CPACK_GENERATOR "TGZ")
274   SET(CPACK_SOURCE_GENERATOR TGZ)
275   SET(CPACK_SOURCE_PACKAGE_FILE_NAME "lapack-${LAPACK_VERSION}" )
276   SET(CPACK_SOURCE_IGNORE_FILES ~$ .svn ${CPACK_SOURCE_IGNORE_FILES} )
277 ENDIF(WIN32 AND NOT UNIX)
278 INCLUDE(CPack)
279
280
281 # --------------------------------------------------
282 # By default static library
283 OPTION(BUILD_SHARED_LIBS "Build shared libraries" OFF )
284 OPTION(BUILD_STATIC_LIBS "Build static libraries" ON )
285 #OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON )
286
287 if(NOT BLAS_FOUND)
288   set(ALL_TARGETS ${ALL_TARGETS} blas)
289 endif(NOT BLAS_FOUND)
290
291 if(NOT LATESTLAPACK_FOUND)
292   set(ALL_TARGETS ${ALL_TARGETS} lapack)
293 endif(NOT LATESTLAPACK_FOUND)
294
295 if(BUILD_TESTING OR LAPACKE_WITH_TMG)
296   set(ALL_TARGETS ${ALL_TARGETS} tmglib)
297 endif(BUILD_TESTING OR LAPACKE_WITH_TMG)
298
299 # Export lapack targets, not including lapacke, from the
300 # install tree, if any.
301 set(_lapack_config_install_guard_target "")
302 if(ALL_TARGETS)
303   install(EXPORT lapack-targets
304     DESTINATION ${LIBRARY_DIR}/cmake/lapack-${LAPACK_VERSION})
305
306   # Choose one of the lapack targets to use as a guard for
307   # lapack-config.cmake to load targets from the install tree.
308   list(GET ALL_TARGETS 0 _lapack_config_install_guard_target)
309 endif()
310
311 # Include cblas in targets exported from the build tree.
312 if(CBLAS)
313   set(ALL_TARGETS ${ALL_TARGETS} cblas)
314 endif(CBLAS)
315
316 # Include lapacke in targets exported from the build tree.
317 if(LAPACKE)
318   set(ALL_TARGETS ${ALL_TARGETS} lapacke)
319 endif(LAPACKE)
320
321 # Export lapack and lapacke targets from the build tree, if any.
322 set(_lapack_config_build_guard_target "")
323 if(ALL_TARGETS)
324   export(TARGETS ${ALL_TARGETS} FILE lapack-targets.cmake)
325
326   # Choose one of the lapack or lapacke targets to use as a guard
327   # for lapack-config.cmake to load targets from the build tree.
328   list(GET ALL_TARGETS 0 _lapack_config_build_guard_target)
329 endif()
330
331 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-build.cmake.in
332   ${LAPACK_BINARY_DIR}/lapack-config.cmake @ONLY)
333
334
335 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lapack.pc.in ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc)
336   install(FILES
337   ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc
338   DESTINATION ${PKG_CONFIG_DIR}
339    )
340
341 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-install.cmake.in
342   ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake @ONLY)
343
344 include(CMakePackageConfigHelpers)
345 write_basic_package_version_file(
346   ${LAPACK_BINARY_DIR}/lapack-config-version.cmake
347   VERSION ${LAPACK_VERSION}
348   COMPATIBILITY SameMajorVersion
349   )
350
351 install(FILES
352   ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake
353   ${LAPACK_BINARY_DIR}/lapack-config-version.cmake
354   DESTINATION ${LIBRARY_DIR}/cmake/lapack-${LAPACK_VERSION}
355   )