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 13 kB

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