Fix linking problem C and Fortran with Sun Compilers on Linux machine
[platform/upstream/lapack.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.6)
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 # Delete libmtsk in linking sequence for Sun/Oracle Fortran Compiler.
19 # This library is not present in the Sun package SolarisStudio13.3-linux-x86-bin
20   STRING(REPLACE \;mtsk\; \; CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}")
21 endif ()
22
23
24 # --------------------------------------------------
25
26 # On Windows-GNU builds try to provide MS import libraries too.
27 if(BUILD_SHARED_LIBS)
28   include(GNUtoMS)
29 endif()
30
31 if(GNUtoMS)
32   set(LAPACK_GNUtoMS_IMPORT ${LAPACK_SOURCE_DIR}/CMAKE/lapack-GNUtoMS.cmake)
33   set(LAPACK_GNUtoMS_INSTALL "include(\${_SELF_DIR}/lapack-GNUtoMS.cmake)")
34   set(LAPACK_GNUtoMS_BUILD "include(\"${LAPACK_GNUtoMS_IMPORT}\")")
35 endif()
36
37 macro(lapack_install_library lib)
38   install(TARGETS ${lib} EXPORT lapack-targets
39     ARCHIVE DESTINATION lib${LIB_SUFFIX}
40     LIBRARY DESTINATION lib${LIB_SUFFIX}
41     RUNTIME DESTINATION bin
42   )
43   if(GNUtoMS)
44     install(FILES ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/lib${lib}.lib DESTINATION lib)
45   endif()
46 endmacro()
47
48 # --------------------------------------------------
49 # Testing
50
51 enable_testing()
52 include(CTest)
53 enable_testing()
54 # --------------------------------------------------
55
56 # Organize output files.  On Windows this also keeps .dll files next
57 # to the .exe files that need them, making tests easy to run.
58 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/bin)
59 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/lib)
60 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/lib)
61
62 # --------------------------------------------------
63 # Check for any necessary platform specific compiler flags
64 include( CheckLAPACKCompilerFlags )
65 CheckLAPACKCompilerFlags()
66
67 # --------------------------------------------------
68 # Check second function
69
70 include(CheckTimeFunction)
71 set(TIME_FUNC NONE ${TIME_FUNC})
72 CHECK_TIME_FUNCTION(NONE TIME_FUNC)
73 CHECK_TIME_FUNCTION(INT_CPU_TIME TIME_FUNC)
74 CHECK_TIME_FUNCTION(EXT_ETIME TIME_FUNC)
75 CHECK_TIME_FUNCTION(EXT_ETIME_ TIME_FUNC)
76 CHECK_TIME_FUNCTION(INT_ETIME TIME_FUNC)
77 message(STATUS "--> Will use second_${TIME_FUNC}.f and dsecnd_${TIME_FUNC}.f as timing function.")
78
79 set(SECOND_SRC  ${LAPACK_SOURCE_DIR}/INSTALL/second_${TIME_FUNC}.f)
80 set(DSECOND_SRC  ${LAPACK_SOURCE_DIR}/INSTALL/dsecnd_${TIME_FUNC}.f)
81 set(prefix ${CMAKE_INSTALL_PREFIX})
82 set(libdir ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX})
83 set(PKG_CONFIG_DIR ${libdir}/pkgconfig)
84
85 # --------------------------------------------------
86 # Precision to build
87 # By default all precisions are generated
88
89 option(BUILD_SINGLE "Build LAPACK Single Precision" ON)
90 option(BUILD_DOUBLE "Build LAPACK Double Precision" ON)
91 option(BUILD_COMPLEX "Build LAPACK Complex Precision" ON)
92 option(BUILD_COMPLEX16 "Build LAPACK Double Complex Precision" ON)
93
94 # --------------------------------------------------
95 # Subdirectories that need to be processed
96
97 option(USE_OPTIMIZED_BLAS "Whether or not to use an optimized BLAS library instead of included netlib BLAS" OFF)
98
99
100 # Check the usage of the user provided BLAS libraries
101 if(BLAS_LIBRARIES)
102   include(CheckFortranFunctionExists)
103   set(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})
104   CHECK_FORTRAN_FUNCTION_EXISTS("dgemm" BLAS_FOUND)
105   unset( CMAKE_REQUIRED_LIBRARIES )
106   if(BLAS_FOUND)
107     message(STATUS "--> BLAS supplied by user is WORKING, will use ${BLAS_LIBRARIES}.")
108   else(BLAS_FOUND)
109     message(ERROR "--> BLAS supplied by user is not WORKING, CANNOT USE ${BLAS_LIBRARIES}.")
110     message(ERROR "-->     Will use REFERENCE BLAS (by default)")
111     message(ERROR "-->     Or Correct your BLAS_LIBRARIES entry ")
112     message(ERROR "-->     Or Consider checking USE_OPTIMIZED_BLAS")
113   endif(BLAS_FOUND)
114
115 # User did not provide a BLAS Library but specified to search for one
116 elseif( USE_OPTIMIZED_BLAS )
117   find_package( BLAS )
118 endif (BLAS_LIBRARIES)
119
120 # Neither user specified or optimized BLAS libraries can be used
121 if(NOT BLAS_FOUND)
122   message(STATUS "Using supplied NETLIB BLAS implementation")
123   add_subdirectory(BLAS)
124   set( BLAS_LIBRARIES blas )
125 else()
126   set( CMAKE_EXE_LINKER_FLAGS 
127     "${CMAKE_EXE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}" 
128     CACHE STRING "Linker flags for executables" FORCE)
129   set( CMAKE_MODULE_LINKER_FLAGS 
130     "${CMAKE_MODULE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}" 
131     CACHE STRING "Linker flags for modules" FORCE)
132   set( CMAKE_SHARED_LINKER_FLAGS 
133     "${CMAKE_SHARED_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}" 
134     CACHE STRING "Linker flags for shared libs" FORCE)
135 endif( NOT BLAS_FOUND )
136
137 option(USE_XBLAS "Build extended precision (needs XBLAS)" OFF)
138 if (USE_XBLAS)
139   find_library(XBLAS_LIBRARY NAMES xblas)
140 endif(USE_XBLAS)
141    
142 add_subdirectory(SRC)
143 if(BUILD_TESTING)
144   add_subdirectory(TESTING)
145 endif(BUILD_TESTING)
146
147 # --------------------------------------------------
148 # LAPACKE
149 option(LAPACKE "Build LAPACKE" OFF)
150 if(LAPACKE)
151   add_subdirectory(lapacke)
152 endif(LAPACKE)
153
154 # --------------------------------------------------
155 # CPACK Packaging 
156
157 SET(CPACK_PACKAGE_NAME "LAPACK")
158 SET(CPACK_PACKAGE_VENDOR "University of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd")
159 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LAPACK- Linear Algebra Package")
160 set(LAPACK_VERSION 3.4.0)
161 set(CPACK_PACKAGE_VERSION_MAJOR 3)
162 set(CPACK_PACKAGE_VERSION_MINOR 4)
163 set(CPACK_PACKAGE_VERSION_PATCH 0)
164 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
165 SET(CPACK_PACKAGE_INSTALL_DIRECTORY "LAPACK")
166 IF(WIN32 AND NOT UNIX)
167   # There is a bug in NSI that does not handle full unix paths properly. Make
168   # sure there is at least one set of four (4) backlasshes.
169   SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\http://icl.cs.utk.edu/lapack-forum")
170   SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.netlib.org/lapack")
171   SET(CPACK_NSIS_CONTACT "lapack@eecs.utk.edu")
172   SET(CPACK_NSIS_MODIFY_PATH ON)
173   SET(CPACK_NSIS_DISPLAY_NAME "LAPACK-${LAPACK_VERSION}")
174   set(CPACK_PACKAGE_RELOCATABLE "true")
175 ELSE(WIN32 AND NOT UNIX)
176   SET(CPACK_GENERATOR "TGZ")
177   SET(CPACK_SOURCE_GENERATOR TGZ)
178   SET(CPACK_SOURCE_PACKAGE_FILE_NAME "lapack-${LAPACK_VERSION}" )
179   SET(CPACK_SOURCE_IGNORE_FILES ~$ .svn ${CPACK_SOURCE_IGNORE_FILES} )
180 ENDIF(WIN32 AND NOT UNIX)
181 INCLUDE(CPack)
182
183
184 # --------------------------------------------------
185 # By default static library
186 OPTION(BUILD_SHARED_LIBS "Build shared libraries" OFF )
187 OPTION(BUILD_STATIC_LIBS "Build static libraries" ON )
188 #OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON )
189
190 if( NOT BLAS_FOUND )
191   export(TARGETS blas lapack FILE lapack-targets.cmake)
192 else( NOT BLAS_FOUND )
193   export(TARGETS lapack FILE lapack-targets.cmake)
194 endif( NOT BLAS_FOUND )
195 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-version.cmake.in
196   ${LAPACK_BINARY_DIR}/lapack-config-version.cmake @ONLY)
197 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-build.cmake.in
198   ${LAPACK_BINARY_DIR}/lapack-config.cmake @ONLY)
199
200 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lapack.pc.in ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc)
201  install(FILES
202   ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc
203   DESTINATION ${PKG_CONFIG_DIR}
204    )
205
206 configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-install.cmake.in
207   ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake @ONLY)
208 install(FILES
209   ${LAPACK_GNUtoMS_IMPORT}
210   ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake
211   ${LAPACK_BINARY_DIR}/lapack-config-version.cmake
212   DESTINATION lib/cmake/lapack-${LAPACK_VERSION}
213   )
214 install(EXPORT lapack-targets
215   DESTINATION lib/cmake/lapack-${LAPACK_VERSION})