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