1. Corrected the way linker flags from FindBLAS are being used
[platform/upstream/lapack.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.6)
2 project(LAPACK Fortran)
3
4 # Add the CMake directory for custon CMake modules
5 set(CMAKE_MODULE_PATH "${LAPACK_SOURCE_DIR}/CMAKE" ${CMAKE_MODULE_PATH})
6
7 if (UNIX)
8    if ( "${CMAKE_Fortran_COMPILER}" MATCHES "ifort" )
9   set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fltconsistency -fp_port" )
10    endif ()
11 endif ()
12
13 macro(lapack_install_library lib)
14   install(TARGETS ${lib} EXPORT lapack-targets
15     ARCHIVE DESTINATION lib${LIB_SUFFIX}
16     LIBRARY DESTINATION lib${LIB_SUFFIX}
17     RUNTIME DESTINATION bin
18   )
19 endmacro()
20
21 # --------------------------------------------------
22 # Testing
23
24 enable_testing()
25 include(CTest)
26 enable_testing()
27 # --------------------------------------------------
28
29 set(CMAKE_MODULE_PATH ${LAPACK_SOURCE_DIR} ${CMAKE_MODULE_PATH})
30
31 # --------------------------------------------------
32 # Check second function
33
34 include(CheckTimeFunction)
35 set(TIME_FUNC NONE ${TIME_FUNC})
36 CHECK_TIME_FUNCTION(NONE TIME_FUNC)
37 CHECK_TIME_FUNCTION(INT_CPU_TIME TIME_FUNC)
38 CHECK_TIME_FUNCTION(EXT_ETIME TIME_FUNC)
39 CHECK_TIME_FUNCTION(EXT_ETIME_ TIME_FUNC)
40 CHECK_TIME_FUNCTION(INT_ETIME TIME_FUNC)
41 message(STATUS "--> Will use second_${TIME_FUNC}.f and dsecnd_${TIME_FUNC}.f as timing function.")
42
43 set(SECOND_SRC  ${LAPACK_SOURCE_DIR}/INSTALL/second_${TIME_FUNC}.f)
44 set(DSECOND_SRC  ${LAPACK_SOURCE_DIR}/INSTALL/dsecnd_${TIME_FUNC}.f)
45 set(prefix ${CMAKE_INSTALL_PREFIX})
46 set(libdir ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX})
47 set(PKG_CONFIG_DIR ${libdir}/pkgconfig)
48
49 # --------------------------------------------------
50 # Subdirectories that need to be processed
51
52 option(USE_OPTIMIZED_BLAS "Whether or not to use an optimized BLAS library instead of included netlib BLAS" OFF)
53
54 # Check the usage of the user provided BLAS libraries
55 if(BLAS_LIBRAIRIES)
56   include(CheckFortranFunctionExists)
57   set(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRAIRIES})
58   CHECK_FORTRAN_FUNCTION_EXISTS("dgemm" BLAS_FOUND)
59   unset( CMAKE_REQUIRED_LIBRARIES )
60   if(BLAS_FOUND)
61     message(STATUS "--> BLAS supplied by user is WORKING, will use ${BLAS_LIBRAIRIES}.")
62   else(BLAS_FOUND)
63     message(ERROR "--> BLAS supplied by user is not WORKING, CANNOT USE ${BLAS_LIBRAIRIES}.")
64     message(ERROR "-->     Will use REFERENCE BLAS (by default)")
65     message(ERROR "-->     Or Correct your BLAS_LIBRAIRIES entry ")
66     message(ERROR "-->     Or Consider checking USE_OPTIMIZED_BLAS")
67   endif(BLAS_FOUND)
68
69 # User did not provide a BLAS Library but specified to search for one
70 elseif( USE_OPTIMIZED_BLAS )
71   find_package( BLAS )
72 endif (BLAS_LIBRAIRIES)
73
74 # Neither user specified or optimized BLAS libraries can be used
75 if(NOT BLAS_FOUND)
76   add_subdirectory(BLAS)
77   set( BLAS_LIBRARIES blas )
78 else()
79   set( CMAKE_EXE_LINKER_FLAGS 
80     "${CMAKE_EXE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}" 
81     CACHE STRING "Linker flags for executables" FORCE)
82   set( CMAKE_MODULE_LINKER_FLAGS 
83     "${CMAKE_MODULE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}" 
84     CACHE STRING "Linker flags for modules" FORCE)
85   set( CMAKE_SHARED_LINKER_FLAGS 
86     "${CMAKE_SHARED_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}" 
87     CACHE STRING "Linker flags for shared libs" FORCE)
88 endif( NOT BLAS_FOUND )
89    
90 add_subdirectory(SRC)
91 if(BUILD_TESTING)
92   add_subdirectory(TESTING)
93 endif(BUILD_TESTING)
94
95 # --------------------------------------------------
96 # CPACK Packaging 
97
98 SET(CPACK_PACKAGE_NAME "LAPACK")
99 SET(CPACK_PACKAGE_VENDOR "University of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd")
100 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LAPACK- Linear Algebra Package")
101 set(LAPACK_VERSION 3.2.2)
102 set(CPACK_PACKAGE_VERSION_MAJOR 3)
103 set(CPACK_PACKAGE_VERSION_MINOR 2)
104 set(CPACK_PACKAGE_VERSION_PATCH 2)
105 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
106 SET(CPACK_PACKAGE_INSTALL_DIRECTORY "LAPACK")
107 IF(WIN32 AND NOT UNIX)
108   # There is a bug in NSI that does not handle full unix paths properly. Make
109   # sure there is at least one set of four (4) backlasshes.
110   SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\http://icl.cs.utk.edu/lapack-forum")
111   SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.netlib.org/lapack")
112   SET(CPACK_NSIS_CONTACT "lapack@eecs.utk.edu")
113   SET(CPACK_NSIS_MODIFY_PATH ON)
114   SET(CPACK_NSIS_DISPLAY_NAME "LAPACK-${LAPACK_VERSION}")
115   set(CPACK_PACKAGE_RELOCATABLE "true")
116 ELSE(WIN32 AND NOT UNIX)
117   SET(CPACK_GENERATOR "TGZ")
118   SET(CPACK_SOURCE_GENERATOR TGZ)
119   SET(CPACK_SOURCE_PACKAGE_FILE_NAME "lapack-${LAPACK_VERSION}" )
120   SET(CPACK_SOURCE_IGNORE_FILES ~$ .svn ${CPACK_SOURCE_IGNORE_FILES} )
121 ENDIF(WIN32 AND NOT UNIX)
122 INCLUDE(CPack)
123
124
125 # --------------------------------------------------
126 # By default static library
127 OPTION(BUILD_SHARED_LIBS "Build shared libraries" OFF )
128 OPTION(BUILD_STATIC_LIBS "Build static libraries" ON )
129 #OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON )
130
131 if( NOT BLAS_FOUND )
132   export(TARGETS blas lapack FILE lapack-targets.cmake)
133 else( NOT BLAS_FOUND )
134   export(TARGETS lapack FILE lapack-targets.cmake)
135 endif( NOT BLAS_FOUND )
136 configure_file(${LAPACK_SOURCE_DIR}/lapack-config-version.cmake.in
137   ${LAPACK_BINARY_DIR}/lapack-config-version.cmake @ONLY)
138
139 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lapack.pc.in ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc)
140  install(FILES
141   ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc
142   DESTINATION ${PKG_CONFIG_DIR}
143    )
144
145 configure_file(${LAPACK_SOURCE_DIR}/lapack-config-install.cmake.in
146   ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake @ONLY)
147 install(FILES
148   ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake
149   ${LAPACK_BINARY_DIR}/lapack-config-version.cmake
150   DESTINATION lib/cmake/lapack-${LAPACK_VERSION}
151   )
152
153 configure_file(${LAPACK_SOURCE_DIR}/lapack-config-install.cmake.in
154   ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake @ONLY)