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