Merge some of Sebastien Fabbro's patch for CMAKE
[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(LOOK_FOR_OPTIMZED_BLAS "Whether or not to use an optimized BLAS library or the included netlib BLAS" OFF)
53 if (BLAS_LIBRAIRIES)
54      # User provided a BLAS Library
55      include(CheckFortranFunctionExists)
56      set(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRAIRIES})
57      CHECK_FORTRAN_FUNCTION_EXISTS("dgemm" BLAS_FOUND)
58      unset( CMAKE_REQUIRED_LIBRARIES )
59      if (BLAS_FOUND)
60         message(STATUS "--> BLAS supplied by user is WORKING, will use ${BLAS_LIBRAIRIES}.")
61      else(BLAS_FOUND)
62         message(ERROR "--> BLAS supplied by user is not WORKING, CANNOT USE ${BLAS_LIBRAIRIES}.")
63         message(ERROR "-->     Will use REFERENCE BLAS (by default)")
64         message(ERROR "-->     Or Correct your BLAS_LIBRAIRIES entry ")
65         message(ERROR "-->     Or Consider checking LOOK_FOR_OPTIMZED_BLAS")
66      endif(BLAS_FOUND)
67 else (BLAS_LIBRAIRIES)
68      # User did not provide a BLAS Library
69    if( LOOK_FOR_OPTIMZED_BLAS )
70        find_package( BLAS )
71    endif(LOOK_FOR_OPTIMZED_BLAS)
72 endif (BLAS_LIBRAIRIES)
73
74 if(NOT BLAS_FOUND)
75       add_subdirectory(BLAS)
76       set( BLAS_LIBRARIES blas )
77 else()
78   set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${BLAS_LINKER_FLAGS}" 
79     CACHE STRING "Flags for Fortran compiler" FORCE
80   )
81 endif( NOT BLAS_FOUND )
82    
83 add_subdirectory(SRC)
84 if(BUILD_TESTING)
85   add_subdirectory(TESTING)
86 endif(BUILD_TESTING)
87
88 # --------------------------------------------------
89 # CPACK Packaging 
90
91 SET(CPACK_PACKAGE_NAME "LAPACK")
92 SET(CPACK_PACKAGE_VENDOR "University of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd")
93 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LAPACK- Linear Algebra Package")
94 set(LAPACK_VERSION 3.2.2)
95 set(CPACK_PACKAGE_VERSION_MAJOR 3)
96 set(CPACK_PACKAGE_VERSION_MINOR 2)
97 set(CPACK_PACKAGE_VERSION_PATCH 2)
98 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
99 SET(CPACK_PACKAGE_INSTALL_DIRECTORY "LAPACK")
100 IF(WIN32 AND NOT UNIX)
101   # There is a bug in NSI that does not handle full unix paths properly. Make
102   # sure there is at least one set of four (4) backlasshes.
103   SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\http://icl.cs.utk.edu/lapack-forum")
104   SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.netlib.org/lapack")
105   SET(CPACK_NSIS_CONTACT "lapack@eecs.utk.edu")
106   SET(CPACK_NSIS_MODIFY_PATH ON)
107   SET(CPACK_NSIS_DISPLAY_NAME "LAPACK-${LAPACK_VERSION}")
108   set(CPACK_PACKAGE_RELOCATABLE "true")
109 ELSE(WIN32 AND NOT UNIX)
110   SET(CPACK_GENERATOR "TGZ")
111   SET(CPACK_SOURCE_GENERATOR TGZ)
112   SET(CPACK_SOURCE_PACKAGE_FILE_NAME "lapack-${LAPACK_VERSION}" )
113   SET(CPACK_SOURCE_IGNORE_FILES ~$ .svn ${CPACK_SOURCE_IGNORE_FILES} )
114 ENDIF(WIN32 AND NOT UNIX)
115 INCLUDE(CPack)
116
117
118 # --------------------------------------------------
119 # By default static library
120 OPTION(BUILD_SHARED_LIBS "Build shared libraries" OFF )
121 OPTION(BUILD_STATIC_LIBS "Build static libraries" ON )
122 #OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON )
123
124 if( NOT BLAS_FOUND )
125   export(TARGETS blas lapack FILE lapack-targets.cmake)
126 else( NOT BLAS_FOUND )
127   export(TARGETS lapack FILE lapack-targets.cmake)
128 endif( NOT BLAS_FOUND )
129 configure_file(${LAPACK_SOURCE_DIR}/lapack-config-version.cmake.in
130   ${LAPACK_BINARY_DIR}/lapack-config-version.cmake @ONLY)
131
132 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lapack.pc.in ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc)
133  install(FILES
134   ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc
135   DESTINATION ${PKG_CONFIG_DIR}
136    )
137
138 configure_file(${LAPACK_SOURCE_DIR}/lapack-config-install.cmake.in
139   ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake @ONLY)
140 install(FILES
141   ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake
142   ${LAPACK_BINARY_DIR}/lapack-config-version.cmake
143   DESTINATION lib/cmake/lapack-${LAPACK_VERSION}
144   )
145
146 configure_file(${LAPACK_SOURCE_DIR}/lapack-config-install.cmake.in
147   ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake @ONLY)