You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

CMakeLists.txt 14 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. cmake_minimum_required(VERSION 2.8.10)
  2. project(LAPACK Fortran)
  3. set(LAPACK_MAJOR_VERSION 3)
  4. set(LAPACK_MINOR_VERSION 6)
  5. set(LAPACK_PATCH_VERSION 1)
  6. set(
  7. LAPACK_VERSION
  8. ${LAPACK_MAJOR_VERSION}.${LAPACK_MINOR_VERSION}.${LAPACK_PATCH_VERSION}
  9. )
  10. # Updated OSX RPATH settings
  11. # In response to CMake 3.0 generating warnings regarding policy CMP0042,
  12. # the OSX RPATH settings have been updated per recommendations found
  13. # in the CMake Wiki:
  14. # http://www.cmake.org/Wiki/CMake_RPATH_handling#Mac_OS_X_and_the_RPATH
  15. set(CMAKE_MACOSX_RPATH ON)
  16. set(CMAKE_SKIP_BUILD_RPATH FALSE)
  17. set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
  18. list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}" isSystemDir)
  19. if("${isSystemDir}" STREQUAL "-1")
  20. set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
  21. set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  22. endif()
  23. # Configure the warning and code coverage suppression file
  24. configure_file(
  25. "${LAPACK_SOURCE_DIR}/CTestCustom.cmake.in"
  26. "${LAPACK_BINARY_DIR}/CTestCustom.cmake"
  27. COPYONLY
  28. )
  29. # Add the CMake directory for custon CMake modules
  30. set(CMAKE_MODULE_PATH "${LAPACK_SOURCE_DIR}/CMAKE" ${CMAKE_MODULE_PATH})
  31. if (UNIX)
  32. if ( "${CMAKE_Fortran_COMPILER}" MATCHES "ifort" )
  33. set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fp-model strict" )
  34. endif ()
  35. if ( "${CMAKE_Fortran_COMPILER}" MATCHES "xlf" )
  36. set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qnosave -qstrict=none" )
  37. endif ()
  38. # Delete libmtsk in linking sequence for Sun/Oracle Fortran Compiler.
  39. # This library is not present in the Sun package SolarisStudio12.3-linux-x86-bin
  40. STRING(REPLACE \;mtsk\; \; CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}")
  41. endif ()
  42. if ( CMAKE_Fortran_COMPILER_ID STREQUAL "Compaq" )
  43. if ( WIN32 )
  44. if (CMAKE_GENERATOR STREQUAL "NMake Makefiles")
  45. get_filename_component(CMAKE_Fortran_COMPILER_CMDNAM ${CMAKE_Fortran_COMPILER} NAME_WE)
  46. message(STATUS "Using Compaq Fortran compiler with command name ${CMAKE_Fortran_COMPILER_CMDNAM}")
  47. set( cmd ${CMAKE_Fortran_COMPILER_CMDNAM} )
  48. string( TOLOWER "${cmd}" cmdlc )
  49. if ( cmdlc STREQUAL "df" )
  50. message(STATUS "Assume the Compaq Visual Fortran Compiler is being used")
  51. set(CMAKE_Fortran_USE_RESPONSE_FILE_FOR_OBJECTS 1)
  52. set(CMAKE_Fortran_USE_RESPONSE_FILE_FOR_INCLUDES 1)
  53. #This is a workaround that is needed to avoid forward-slashes in the
  54. #filenames listed in response files from incorrectly being interpreted as
  55. #introducing compiler command options
  56. if (${BUILD_SHARED_LIBS})
  57. message(FATAL_ERROR "Making of shared libraries with CVF has not been tested.")
  58. endif()
  59. set(str "NMake version 9 or later should be used. NMake version 6.0 which is\n")
  60. set(str "${str} included with the CVF distribution fails to build Lapack because\n")
  61. set(str "${str} the number of source files exceeds the limit for NMake v6.0\n")
  62. message(STATUS ${str})
  63. set(CMAKE_Fortran_LINK_EXECUTABLE "LINK /out:<TARGET> <LINK_FLAGS> <LINK_LIBRARIES> <OBJECTS>")
  64. endif()
  65. endif()
  66. endif()
  67. endif()
  68. # Get Python
  69. find_package(PythonInterp)
  70. message(STATUS "Looking for Python found - ${PYTHONINTERP_FOUND}")
  71. if (PYTHONINTERP_FOUND)
  72. message(STATUS "Using Python version ${PYTHON_VERSION_STRING}")
  73. endif()
  74. # --------------------------------------------------
  75. set(LAPACK_INSTALL_EXPORT_NAME lapack-targets)
  76. if (UNIX)
  77. include(GNUInstallDirs)
  78. set(ARCHIVE_DIR ${CMAKE_INSTALL_LIBDIR})
  79. set(LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR})
  80. set(RUNTIME_DIR ${CMAKE_INSTALL_BINDIR})
  81. else()
  82. set(ARCHIVE_DIR lib${LIB_SUFFIX})
  83. set(LIBRARY_DIR lib${LIB_SUFFIX})
  84. set(RUNTIME_DIR bin)
  85. endif()
  86. macro(lapack_install_library lib)
  87. install(TARGETS ${lib}
  88. EXPORT ${LAPACK_INSTALL_EXPORT_NAME}
  89. ARCHIVE DESTINATION ${ARCHIVE_DIR}
  90. LIBRARY DESTINATION ${LIBRARY_DIR}
  91. RUNTIME DESTINATION ${RUNTIME_DIR}
  92. )
  93. endmacro()
  94. # --------------------------------------------------
  95. # Testing
  96. enable_testing()
  97. include(CTest)
  98. enable_testing()
  99. # --------------------------------------------------
  100. # Organize output files. On Windows this also keeps .dll files next
  101. # to the .exe files that need them, making tests easy to run.
  102. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/bin)
  103. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/lib)
  104. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/lib)
  105. # --------------------------------------------------
  106. # Check for any necessary platform specific compiler flags
  107. include( CheckLAPACKCompilerFlags )
  108. CheckLAPACKCompilerFlags()
  109. # --------------------------------------------------
  110. # Check second function
  111. include(CheckTimeFunction)
  112. set(TIME_FUNC NONE ${TIME_FUNC})
  113. CHECK_TIME_FUNCTION(NONE TIME_FUNC)
  114. CHECK_TIME_FUNCTION(INT_CPU_TIME TIME_FUNC)
  115. CHECK_TIME_FUNCTION(EXT_ETIME TIME_FUNC)
  116. CHECK_TIME_FUNCTION(EXT_ETIME_ TIME_FUNC)
  117. CHECK_TIME_FUNCTION(INT_ETIME TIME_FUNC)
  118. message(STATUS "--> Will use second_${TIME_FUNC}.f and dsecnd_${TIME_FUNC}.f as timing function.")
  119. set(SECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/second_${TIME_FUNC}.f)
  120. set(DSECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/dsecnd_${TIME_FUNC}.f)
  121. set(PKG_CONFIG_DIR ${LIBRARY_DIR}/pkgconfig)
  122. # --------------------------------------------------
  123. # Precision to build
  124. # By default all precisions are generated
  125. # --------------------------------------------------
  126. # Subdirectories that need to be processed
  127. option(USE_OPTIMIZED_BLAS "Whether or not to use an optimized BLAS library instead of included netlib BLAS" OFF)
  128. # Check the usage of the user provided BLAS libraries
  129. if(BLAS_LIBRARIES)
  130. include(CheckFortranFunctionExists)
  131. set(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})
  132. CHECK_FORTRAN_FUNCTION_EXISTS("dgemm" BLAS_FOUND)
  133. unset( CMAKE_REQUIRED_LIBRARIES )
  134. if(BLAS_FOUND)
  135. message(STATUS "--> BLAS supplied by user is WORKING, will use ${BLAS_LIBRARIES}.")
  136. else(BLAS_FOUND)
  137. message(ERROR "--> BLAS supplied by user is not WORKING, CANNOT USE ${BLAS_LIBRARIES}.")
  138. message(ERROR "--> Will use REFERENCE BLAS (by default)")
  139. message(ERROR "--> Or Correct your BLAS_LIBRARIES entry ")
  140. message(ERROR "--> Or Consider checking USE_OPTIMIZED_BLAS")
  141. endif(BLAS_FOUND)
  142. # User did not provide a BLAS Library but specified to search for one
  143. elseif( USE_OPTIMIZED_BLAS )
  144. find_package( BLAS )
  145. endif (BLAS_LIBRARIES)
  146. # Neither user specified or optimized BLAS libraries can be used
  147. if(NOT BLAS_FOUND)
  148. message(STATUS "Using supplied NETLIB BLAS implementation")
  149. add_subdirectory(BLAS)
  150. set( BLAS_LIBRARIES blas )
  151. else()
  152. set( CMAKE_EXE_LINKER_FLAGS
  153. "${CMAKE_EXE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
  154. CACHE STRING "Linker flags for executables" FORCE)
  155. set( CMAKE_MODULE_LINKER_FLAGS
  156. "${CMAKE_MODULE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
  157. CACHE STRING "Linker flags for modules" FORCE)
  158. set( CMAKE_SHARED_LINKER_FLAGS
  159. "${CMAKE_SHARED_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
  160. CACHE STRING "Linker flags for shared libs" FORCE)
  161. endif( NOT BLAS_FOUND )
  162. # --------------------------------------------------
  163. # CBLAS
  164. option(CBLAS "Build CBLAS" OFF)
  165. if(CBLAS)
  166. add_subdirectory(CBLAS)
  167. endif(CBLAS)
  168. # --------------------------------------------------
  169. # XBLAS
  170. option(USE_XBLAS "Build extended precision (needs XBLAS)" OFF)
  171. if (USE_XBLAS)
  172. find_library(XBLAS_LIBRARY NAMES xblas)
  173. endif(USE_XBLAS)
  174. option(USE_OPTIMIZED_LAPACK "Whether or not to use an optimized LAPACK library instead of included netlib LAPACK" OFF)
  175. # --------------------------------------------------
  176. # LAPACK
  177. # User did not provide a LAPACK Library but specified to search for one
  178. if( USE_OPTIMIZED_LAPACK )
  179. find_package( LAPACK )
  180. endif (USE_OPTIMIZED_LAPACK)
  181. # Check the usage of the user provided or automatically found LAPACK libraries
  182. if(LAPACK_LIBRARIES)
  183. include(CheckFortranFunctionExists)
  184. set(CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARIES})
  185. # Check if new routine of 3.4.0 is in LAPACK_LIBRARIES
  186. CHECK_FORTRAN_FUNCTION_EXISTS("dgeqrt" LATESTLAPACK_FOUND)
  187. unset( CMAKE_REQUIRED_LIBRARIES )
  188. if(LATESTLAPACK_FOUND)
  189. message(STATUS "--> LAPACK supplied by user is WORKING, will use ${LAPACK_LIBRARIES}.")
  190. else(LAPACK_FOUND)
  191. message(ERROR "--> LAPACK supplied by user is not WORKING or is older than LAPACK 3.4.0, CANNOT USE ${LAPACK_LIBRARIES}.")
  192. message(ERROR "--> Will use REFERENCE LAPACK (by default)")
  193. message(ERROR "--> Or Correct your LAPACK_LIBRARIES entry ")
  194. message(ERROR "--> Or Consider checking USE_OPTIMIZED_LAPACK")
  195. endif(LATESTLAPACK_FOUND)
  196. endif (LAPACK_LIBRARIES)
  197. # Neither user specified or optimized LAPACK libraries can be used
  198. if(NOT LATESTLAPACK_FOUND)
  199. message(STATUS "Using supplied NETLIB LAPACK implementation")
  200. set( LAPACK_LIBRARIES lapack )
  201. option(BUILD_SINGLE "Build LAPACK Single Precision" ON)
  202. option(BUILD_DOUBLE "Build LAPACK Double Precision" ON)
  203. option(BUILD_COMPLEX "Build LAPACK Complex Precision" ON)
  204. option(BUILD_COMPLEX16 "Build LAPACK Double Complex Precision" ON)
  205. add_subdirectory(SRC)
  206. else()
  207. set( CMAKE_EXE_LINKER_FLAGS
  208. "${CMAKE_EXE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
  209. CACHE STRING "Linker flags for executables" FORCE)
  210. set( CMAKE_MODULE_LINKER_FLAGS
  211. "${CMAKE_MODULE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
  212. CACHE STRING "Linker flags for modules" FORCE)
  213. set( CMAKE_SHARED_LINKER_FLAGS
  214. "${CMAKE_SHARED_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
  215. CACHE STRING "Linker flags for shared libs" FORCE)
  216. endif( NOT LATESTLAPACK_FOUND )
  217. message(STATUS "BUILD TESTING : ${BUILD_TESTING}" )
  218. if(BUILD_TESTING)
  219. add_subdirectory(TESTING)
  220. endif(BUILD_TESTING)
  221. # deprecated LAPACK routines
  222. option(BUILD_DEPRECATED "Build deprecated routines" OFF)
  223. # --------------------------------------------------
  224. # LAPACKE
  225. option(LAPACKE "Build LAPACKE" OFF)
  226. # LAPACKE has also the interface to some routines from tmglib,
  227. # if LAPACKE_WITH_TMG is selected, we need to add those routines to LAPACKE
  228. option(LAPACKE_WITH_TMG "Build LAPACKE with tmglib routines" OFF)
  229. if (LAPACKE_WITH_TMG)
  230. set(LAPACKE ON)
  231. if(NOT BUILD_TESTING)
  232. add_subdirectory(TESTING/MATGEN)
  233. endif(NOT BUILD_TESTING)
  234. endif(LAPACKE_WITH_TMG)
  235. if(LAPACKE)
  236. add_subdirectory(LAPACKE)
  237. endif(LAPACKE)
  238. # --------------------------------------------------
  239. # CPACK Packaging
  240. SET(CPACK_PACKAGE_NAME "LAPACK")
  241. SET(CPACK_PACKAGE_VENDOR "University of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd")
  242. SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LAPACK- Linear Algebra Package")
  243. set(CPACK_PACKAGE_VERSION_MAJOR 3)
  244. set(CPACK_PACKAGE_VERSION_MINOR 5)
  245. set(CPACK_PACKAGE_VERSION_PATCH 0)
  246. set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
  247. SET(CPACK_PACKAGE_INSTALL_DIRECTORY "LAPACK")
  248. IF(WIN32 AND NOT UNIX)
  249. # There is a bug in NSI that does not handle full unix paths properly. Make
  250. # sure there is at least one set of four (4) backlasshes.
  251. SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\http://icl.cs.utk.edu/lapack-forum")
  252. SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.netlib.org/lapack")
  253. SET(CPACK_NSIS_CONTACT "lapack@eecs.utk.edu")
  254. SET(CPACK_NSIS_MODIFY_PATH ON)
  255. SET(CPACK_NSIS_DISPLAY_NAME "LAPACK-${LAPACK_VERSION}")
  256. set(CPACK_PACKAGE_RELOCATABLE "true")
  257. ELSE(WIN32 AND NOT UNIX)
  258. SET(CPACK_GENERATOR "TGZ")
  259. SET(CPACK_SOURCE_GENERATOR TGZ)
  260. SET(CPACK_SOURCE_PACKAGE_FILE_NAME "lapack-${LAPACK_VERSION}" )
  261. SET(CPACK_SOURCE_IGNORE_FILES ~$ .svn ${CPACK_SOURCE_IGNORE_FILES} )
  262. ENDIF(WIN32 AND NOT UNIX)
  263. INCLUDE(CPack)
  264. # --------------------------------------------------
  265. # By default static library
  266. OPTION(BUILD_SHARED_LIBS "Build shared libraries" OFF )
  267. OPTION(BUILD_STATIC_LIBS "Build static libraries" ON )
  268. #OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON )
  269. if(NOT BLAS_FOUND)
  270. set(ALL_TARGETS ${ALL_TARGETS} blas)
  271. endif(NOT BLAS_FOUND)
  272. if(NOT LATESTLAPACK_FOUND)
  273. set(ALL_TARGETS ${ALL_TARGETS} lapack)
  274. endif(NOT LATESTLAPACK_FOUND)
  275. if(BUILD_TESTING OR LAPACKE_WITH_TMG)
  276. set(ALL_TARGETS ${ALL_TARGETS} tmglib)
  277. endif(BUILD_TESTING OR LAPACKE_WITH_TMG)
  278. # Export lapack targets, not including lapacke, from the
  279. # install tree, if any.
  280. set(_lapack_config_install_guard_target "")
  281. if(ALL_TARGETS)
  282. install(EXPORT lapack-targets
  283. DESTINATION ${LIBRARY_DIR}/cmake/lapack-${LAPACK_VERSION})
  284. # Choose one of the lapack targets to use as a guard for
  285. # lapack-config.cmake to load targets from the install tree.
  286. list(GET ALL_TARGETS 0 _lapack_config_install_guard_target)
  287. endif()
  288. # Include cblas in targets exported from the build tree.
  289. if(CBLAS)
  290. set(ALL_TARGETS ${ALL_TARGETS} cblas)
  291. endif(CBLAS)
  292. # Include lapacke in targets exported from the build tree.
  293. if(LAPACKE)
  294. set(ALL_TARGETS ${ALL_TARGETS} lapacke)
  295. endif(LAPACKE)
  296. # Export lapack and lapacke targets from the build tree, if any.
  297. set(_lapack_config_build_guard_target "")
  298. if(ALL_TARGETS)
  299. export(TARGETS ${ALL_TARGETS} FILE lapack-targets.cmake)
  300. # Choose one of the lapack or lapacke targets to use as a guard
  301. # for lapack-config.cmake to load targets from the build tree.
  302. list(GET ALL_TARGETS 0 _lapack_config_build_guard_target)
  303. endif()
  304. configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-build.cmake.in
  305. ${LAPACK_BINARY_DIR}/lapack-config.cmake @ONLY)
  306. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lapack.pc.in ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc)
  307. install(FILES
  308. ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc
  309. DESTINATION ${PKG_CONFIG_DIR}
  310. )
  311. configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-install.cmake.in
  312. ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake @ONLY)
  313. include(CMakePackageConfigHelpers)
  314. write_basic_package_version_file(
  315. ${LAPACK_BINARY_DIR}/lapack-config-version.cmake
  316. VERSION ${LAPACK_VERSION}
  317. COMPATIBILITY SameMajorVersion
  318. )
  319. install(FILES
  320. ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake
  321. ${LAPACK_BINARY_DIR}/lapack-config-version.cmake
  322. DESTINATION ${LIBRARY_DIR}/cmake/lapack-${LAPACK_VERSION}
  323. )