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

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