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