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