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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. cmake_minimum_required(VERSION 3.2)
  2. project(LAPACK Fortran C)
  3. set(LAPACK_MAJOR_VERSION 3)
  4. set(LAPACK_MINOR_VERSION 11)
  5. set(LAPACK_PATCH_VERSION 0)
  6. set(
  7. LAPACK_VERSION
  8. ${LAPACK_MAJOR_VERSION}.${LAPACK_MINOR_VERSION}.${LAPACK_PATCH_VERSION}
  9. )
  10. # Allow setting a prefix for the library names
  11. set(CMAKE_STATIC_LIBRARY_PREFIX "lib${LIBRARY_PREFIX}")
  12. set(CMAKE_SHARED_LIBRARY_PREFIX "lib${LIBRARY_PREFIX}")
  13. # Add the CMake directory for custom CMake modules
  14. set(CMAKE_MODULE_PATH "${LAPACK_SOURCE_DIR}/CMAKE" ${CMAKE_MODULE_PATH})
  15. # Export all symbols on Windows when building shared libraries
  16. SET(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
  17. # Set a default build type if none was specified
  18. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  19. message(STATUS "Setting build type to 'Release' as none was specified.")
  20. set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
  21. # Set the possible values of build type for cmake-gui
  22. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo" "Coverage")
  23. endif()
  24. # Coverage
  25. set(_is_coverage_build 0)
  26. set(_msg "Checking if build type is 'Coverage'")
  27. message(STATUS "${_msg}")
  28. if(NOT CMAKE_CONFIGURATION_TYPES)
  29. string(TOLOWER ${CMAKE_BUILD_TYPE} _build_type_lc)
  30. if(${_build_type_lc} STREQUAL "coverage")
  31. set(_is_coverage_build 1)
  32. endif()
  33. endif()
  34. message(STATUS "${_msg}: ${_is_coverage_build}")
  35. if(_is_coverage_build)
  36. message(STATUS "Adding coverage")
  37. find_package(codecov)
  38. endif()
  39. # By default test Fortran compiler complex abs and complex division
  40. option(TEST_FORTRAN_COMPILER "Test Fortran compiler complex abs and complex division" OFF)
  41. if( TEST_FORTRAN_COMPILER )
  42. add_executable( test_zcomplexabs ${LAPACK_SOURCE_DIR}/INSTALL/test_zcomplexabs.f )
  43. add_custom_target( run_test_zcomplexabs
  44. COMMAND test_zcomplexabs 2> test_zcomplexabs.err
  45. WORKING_DIRECTORY ${LAPACK_BINARY_DIR}/INSTALL
  46. COMMENT "Running test_zcomplexabs in ${LAPACK_BINARY_DIR}/INSTALL with stderr: test_zcomplexabs.err"
  47. SOURCES ${LAPACK_SOURCE_DIR}/INSTALL/test_zcomplexabs.f )
  48. add_executable( test_zcomplexdiv ${LAPACK_SOURCE_DIR}/INSTALL/test_zcomplexdiv.f )
  49. add_custom_target( run_test_zcomplexdiv
  50. COMMAND test_zcomplexdiv 2> test_zcomplexdiv.err
  51. WORKING_DIRECTORY ${LAPACK_BINARY_DIR}/INSTALL
  52. COMMENT "Running test_zcomplexdiv in ${LAPACK_BINARY_DIR}/INSTALL with stderr: test_zcomplexdiv.err"
  53. SOURCES ${LAPACK_SOURCE_DIR}/INSTALL/test_zcomplexdiv.f )
  54. add_executable( test_zcomplexmult ${LAPACK_SOURCE_DIR}/INSTALL/test_zcomplexmult.f )
  55. add_custom_target( run_test_zcomplexmult
  56. COMMAND test_zcomplexmult 2> test_zcomplexmult.err
  57. WORKING_DIRECTORY ${LAPACK_BINARY_DIR}/INSTALL
  58. COMMENT "Running test_zcomplexmult in ${LAPACK_BINARY_DIR}/INSTALL with stderr: test_zcomplexmult.err"
  59. SOURCES ${LAPACK_SOURCE_DIR}/INSTALL/test_zcomplexmult.f )
  60. add_executable( test_zminMax ${LAPACK_SOURCE_DIR}/INSTALL/test_zminMax.f )
  61. add_custom_target( run_test_zminMax
  62. COMMAND test_zminMax 2> test_zminMax.err
  63. WORKING_DIRECTORY ${LAPACK_BINARY_DIR}/INSTALL
  64. COMMENT "Running test_zminMax in ${LAPACK_BINARY_DIR}/INSTALL with stderr: test_zminMax.err"
  65. SOURCES ${LAPACK_SOURCE_DIR}/INSTALL/test_zminMax.f )
  66. endif()
  67. # By default static library
  68. option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
  69. # By default build index32 library
  70. option(BUILD_INDEX64 "Build Index-64 API libraries" OFF)
  71. if(BUILD_INDEX64)
  72. set(BLASLIB "blas64")
  73. set(CBLASLIB "cblas64")
  74. set(LAPACKLIB "lapack64")
  75. set(LAPACKELIB "lapacke64")
  76. set(TMGLIB "tmglib64")
  77. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWeirdNEC -DLAPACK_ILP64 -DHAVE_LAPACK_CONFIG_H")
  78. set(FORTRAN_ILP TRUE)
  79. else()
  80. set(BLASLIB "blas")
  81. set(CBLASLIB "cblas")
  82. set(LAPACKLIB "lapack")
  83. set(LAPACKELIB "lapacke")
  84. set(TMGLIB "tmglib")
  85. endif()
  86. include(GNUInstallDirs)
  87. # Updated OSX RPATH settings
  88. # In response to CMake 3.0 generating warnings regarding policy CMP0042,
  89. # the OSX RPATH settings have been updated per recommendations found
  90. # in the CMake Wiki:
  91. # http://www.cmake.org/Wiki/CMake_RPATH_handling#Mac_OS_X_and_the_RPATH
  92. set(CMAKE_MACOSX_RPATH ON)
  93. set(CMAKE_SKIP_BUILD_RPATH FALSE)
  94. set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
  95. list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES ${CMAKE_INSTALL_FULL_LIBDIR} isSystemDir)
  96. if("${isSystemDir}" STREQUAL "-1")
  97. set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})
  98. set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  99. endif()
  100. # Configure the warning and code coverage suppression file
  101. configure_file(
  102. "${LAPACK_SOURCE_DIR}/CTestCustom.cmake.in"
  103. "${LAPACK_BINARY_DIR}/CTestCustom.cmake"
  104. @ONLY
  105. )
  106. include(PreventInSourceBuilds)
  107. include(PreventInBuildInstalls)
  108. # Check if recursive flag exists
  109. include(CheckFortranCompilerFlag)
  110. if(CMAKE_Fortran_COMPILER_ID STREQUAL Flang)
  111. check_fortran_compiler_flag("-Mrecursive" _MrecursiveFlag)
  112. elseif(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
  113. check_fortran_compiler_flag("-frecursive" _frecursiveFlag)
  114. elseif(CMAKE_Fortran_COMPILER_ID STREQUAL Intel)
  115. check_fortran_compiler_flag("-recursive" _recursiveFlag)
  116. elseif(CMAKE_Fortran_COMPILER_ID STREQUAL XL)
  117. check_fortran_compiler_flag("-qrecur" _qrecurFlag)
  118. elseif(CMAKE_Fortran_COMPILER_ID STREQUAL NAG)
  119. check_fortran_compiler_flag("-recursive" _recursiveFlag)
  120. else()
  121. message(WARNING "Fortran local arrays should be allocated on the stack."
  122. " Please use a compiler which guarantees that feature."
  123. " See https://github.com/Reference-LAPACK/lapack/pull/188 and references therein.")
  124. endif()
  125. # Add recursive flag
  126. if(_MrecursiveFlag)
  127. string(REGEX MATCH "-Mrecursive" output_test <string> "${CMAKE_Fortran_FLAGS}")
  128. if(NOT output_test)
  129. set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Mrecursive"
  130. CACHE STRING "Recursive flag must be set" FORCE)
  131. endif()
  132. elseif(_frecursiveFlag)
  133. string(REGEX MATCH "-frecursive" output_test <string> "${CMAKE_Fortran_FLAGS}")
  134. if(NOT output_test)
  135. set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -frecursive"
  136. CACHE STRING "Recursive flag must be set" FORCE)
  137. endif()
  138. elseif(_recursiveFlag)
  139. string(REGEX MATCH "-recursive" output_test <string> "${CMAKE_Fortran_FLAGS}")
  140. if(NOT output_test)
  141. set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -recursive"
  142. CACHE STRING "Recursive flag must be set" FORCE)
  143. endif()
  144. elseif(_qrecurFlag)
  145. string(REGEX MATCH "-qrecur" output_test <string> "${CMAKE_Fortran_FLAGS}")
  146. if(NOT output_test)
  147. set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qrecur"
  148. CACHE STRING "Recursive flag must be set" FORCE)
  149. endif()
  150. endif()
  151. if(UNIX)
  152. if(CMAKE_Fortran_COMPILER_ID STREQUAL Intel)
  153. set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fp-model strict")
  154. endif()
  155. if(CMAKE_Fortran_COMPILER_ID STREQUAL XL)
  156. set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qnosave -qstrict")
  157. endif()
  158. # Delete libmtsk in linking sequence for Sun/Oracle Fortran Compiler.
  159. # This library is not present in the Sun package SolarisStudio12.3-linux-x86-bin
  160. string(REPLACE \;mtsk\; \; CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}")
  161. endif()
  162. if(CMAKE_Fortran_COMPILER_ID STREQUAL Compaq)
  163. if(WIN32)
  164. if(CMAKE_GENERATOR STREQUAL "NMake Makefiles")
  165. get_filename_component(CMAKE_Fortran_COMPILER_CMDNAM ${CMAKE_Fortran_COMPILER} NAME_WE)
  166. message(STATUS "Using Compaq Fortran compiler with command name ${CMAKE_Fortran_COMPILER_CMDNAM}")
  167. set(cmd ${CMAKE_Fortran_COMPILER_CMDNAM})
  168. string(TOLOWER "${cmd}" cmdlc)
  169. if(cmdlc STREQUAL "df")
  170. message(STATUS "Assume the Compaq Visual Fortran Compiler is being used")
  171. set(CMAKE_Fortran_USE_RESPONSE_FILE_FOR_OBJECTS 1)
  172. set(CMAKE_Fortran_USE_RESPONSE_FILE_FOR_INCLUDES 1)
  173. #This is a workaround that is needed to avoid forward-slashes in the
  174. #filenames listed in response files from incorrectly being interpreted as
  175. #introducing compiler command options
  176. if(${BUILD_SHARED_LIBS})
  177. message(FATAL_ERROR "Making of shared libraries with CVF has not been tested.")
  178. endif()
  179. set(str "NMake version 9 or later should be used. NMake version 6.0 which is\n")
  180. set(str "${str} included with the CVF distribution fails to build Lapack because\n")
  181. set(str "${str} the number of source files exceeds the limit for NMake v6.0\n")
  182. message(STATUS ${str})
  183. set(CMAKE_Fortran_LINK_EXECUTABLE "LINK /out:<TARGET> <LINK_FLAGS> <LINK_LIBRARIES> <OBJECTS>")
  184. endif()
  185. endif()
  186. endif()
  187. endif()
  188. # Add option to enable flat namespace for symbol resolution on macOS
  189. if(APPLE)
  190. option(USE_FLAT_NAMESPACE "Use flat namespaces for symbol resolution during build and runtime." OFF)
  191. if(USE_FLAT_NAMESPACE)
  192. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-flat_namespace")
  193. set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-flat_namespace")
  194. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-flat_namespace")
  195. else()
  196. if(BUILD_SHARED_LIBS AND BUILD_TESTING)
  197. message(WARNING
  198. "LAPACK test suite might fail with shared libraries and the default two-level namespace. "
  199. "Disable shared libraries or enable flat namespace for symbol resolution via -DUSE_FLAT_NAMESPACE=ON.")
  200. endif()
  201. endif()
  202. endif()
  203. # --------------------------------------------------
  204. set(LAPACK_INSTALL_EXPORT_NAME ${LAPACKLIB}-targets)
  205. macro(lapack_install_library lib)
  206. install(TARGETS ${lib}
  207. EXPORT ${LAPACK_INSTALL_EXPORT_NAME}
  208. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development
  209. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT RuntimeLibraries
  210. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT RuntimeLibraries
  211. )
  212. endmacro()
  213. set(PKG_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
  214. # --------------------------------------------------
  215. # Testing
  216. option(BUILD_TESTING "Build tests" ${_is_coverage_build})
  217. include(CTest)
  218. message(STATUS "Build tests: ${BUILD_TESTING}")
  219. if(BUILD_TESTING)
  220. set(_msg "Looking for Python3 needed for summary tests")
  221. message(STATUS "${_msg}")
  222. # find_package(PythonInterp 3) cannot be used because /usr/bin/python may be
  223. # a Python2 interpreter.
  224. find_program(PYTHON_EXECUTABLE python3)
  225. if(PYTHON_EXECUTABLE)
  226. message(STATUS "${_msg} - found")
  227. else()
  228. message(STATUS "${_msg} - not found (skipping summary tests)")
  229. endif()
  230. endif()
  231. # --------------------------------------------------
  232. # Organize output files. On Windows this also keeps .dll files next
  233. # to the .exe files that need them, making tests easy to run.
  234. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/bin)
  235. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/lib)
  236. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/lib)
  237. # --------------------------------------------------
  238. # Check for any necessary platform specific compiler flags
  239. include(CheckLAPACKCompilerFlags)
  240. CheckLAPACKCompilerFlags()
  241. # --------------------------------------------------
  242. # Check second function
  243. include(CheckTimeFunction)
  244. set(TIME_FUNC NONE)
  245. CHECK_TIME_FUNCTION(NONE TIME_FUNC)
  246. CHECK_TIME_FUNCTION(INT_CPU_TIME TIME_FUNC)
  247. CHECK_TIME_FUNCTION(EXT_ETIME TIME_FUNC)
  248. CHECK_TIME_FUNCTION(EXT_ETIME_ TIME_FUNC)
  249. CHECK_TIME_FUNCTION(INT_ETIME TIME_FUNC)
  250. message(STATUS "--> Will use second_${TIME_FUNC}.f and dsecnd_${TIME_FUNC}.f as timing function.")
  251. set(SECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/second_${TIME_FUNC}.f)
  252. set(DSECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/dsecnd_${TIME_FUNC}.f)
  253. # deprecated LAPACK and LAPACKE routines
  254. option(BUILD_DEPRECATED "Build deprecated routines" OFF)
  255. message(STATUS "Build deprecated routines: ${BUILD_DEPRECATED}")
  256. # --------------------------------------------------
  257. # Precision to build
  258. # By default all precisions are generated
  259. option(BUILD_SINGLE "Build single precision real" ON)
  260. option(BUILD_DOUBLE "Build double precision real" ON)
  261. option(BUILD_COMPLEX "Build single precision complex" ON)
  262. option(BUILD_COMPLEX16 "Build double precision complex" ON)
  263. message(STATUS "Build single precision real: ${BUILD_SINGLE}")
  264. message(STATUS "Build double precision real: ${BUILD_DOUBLE}")
  265. message(STATUS "Build single precision complex: ${BUILD_COMPLEX}")
  266. message(STATUS "Build double precision complex: ${BUILD_COMPLEX16}")
  267. if(NOT (BUILD_SINGLE OR BUILD_DOUBLE OR BUILD_COMPLEX OR BUILD_COMPLEX16))
  268. message(FATAL_ERROR "Nothing to build, no precision selected.
  269. Please enable at least one of these:
  270. BUILD_SINGLE, BUILD_DOUBLE, BUILD_COMPLEX, BUILD_COMPLEX16.")
  271. endif()
  272. # --------------------------------------------------
  273. # Subdirectories that need to be processed
  274. option(USE_OPTIMIZED_BLAS "Whether or not to use an optimized BLAS library instead of included netlib BLAS" OFF)
  275. # Check the usage of the user provided BLAS libraries
  276. if(BLAS_LIBRARIES)
  277. include(CheckFortranFunctionExists)
  278. set(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})
  279. CHECK_FORTRAN_FUNCTION_EXISTS("dgemm" BLAS_FOUND)
  280. unset(CMAKE_REQUIRED_LIBRARIES)
  281. if(BLAS_FOUND)
  282. message(STATUS "--> BLAS supplied by user is WORKING, will use ${BLAS_LIBRARIES}.")
  283. else()
  284. message(ERROR "--> BLAS supplied by user is not WORKING, CANNOT USE ${BLAS_LIBRARIES}.")
  285. message(ERROR "--> Will use REFERENCE BLAS (by default)")
  286. message(ERROR "--> Or Correct your BLAS_LIBRARIES entry ")
  287. message(ERROR "--> Or Consider checking USE_OPTIMIZED_BLAS")
  288. endif()
  289. # User did not provide a BLAS Library but specified to search for one
  290. elseif(USE_OPTIMIZED_BLAS)
  291. find_package(BLAS)
  292. endif()
  293. # Neither user specified or optimized BLAS libraries can be used
  294. if(NOT BLAS_FOUND)
  295. message(STATUS "Using supplied NETLIB BLAS implementation")
  296. add_subdirectory(BLAS)
  297. set(BLAS_LIBRARIES ${BLASLIB})
  298. else()
  299. set(CMAKE_EXE_LINKER_FLAGS
  300. "${CMAKE_EXE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
  301. CACHE STRING "Linker flags for executables" FORCE)
  302. set(CMAKE_MODULE_LINKER_FLAGS
  303. "${CMAKE_MODULE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
  304. CACHE STRING "Linker flags for modules" FORCE)
  305. set(CMAKE_SHARED_LINKER_FLAGS
  306. "${CMAKE_SHARED_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
  307. CACHE STRING "Linker flags for shared libs" FORCE)
  308. endif()
  309. # --------------------------------------------------
  310. # CBLAS
  311. option(CBLAS "Build CBLAS" OFF)
  312. if(CBLAS)
  313. add_subdirectory(CBLAS)
  314. endif()
  315. # --------------------------------------------------
  316. # XBLAS
  317. option(USE_XBLAS "Build extended precision (needs XBLAS)" OFF)
  318. if(USE_XBLAS)
  319. find_library(XBLAS_LIBRARY NAMES xblas)
  320. endif()
  321. option(USE_OPTIMIZED_LAPACK "Whether or not to use an optimized LAPACK library instead of included netlib LAPACK" OFF)
  322. # --------------------------------------------------
  323. # LAPACK
  324. # User did not provide a LAPACK Library but specified to search for one
  325. if(USE_OPTIMIZED_LAPACK)
  326. find_package(LAPACK)
  327. endif()
  328. # Check the usage of the user provided or automatically found LAPACK libraries
  329. if(LAPACK_LIBRARIES)
  330. include(CheckFortranFunctionExists)
  331. set(CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARIES})
  332. # Check if new routine of 3.4.0 is in LAPACK_LIBRARIES
  333. CHECK_FORTRAN_FUNCTION_EXISTS("dgeqrt" LATESTLAPACK_FOUND)
  334. unset(CMAKE_REQUIRED_LIBRARIES)
  335. if(LATESTLAPACK_FOUND)
  336. message(STATUS "--> LAPACK supplied by user is WORKING, will use ${LAPACK_LIBRARIES}.")
  337. else()
  338. message(ERROR "--> LAPACK supplied by user is not WORKING or is older than LAPACK 3.4.0, CANNOT USE ${LAPACK_LIBRARIES}.")
  339. message(ERROR "--> Will use REFERENCE LAPACK (by default)")
  340. message(ERROR "--> Or Correct your LAPACK_LIBRARIES entry ")
  341. message(ERROR "--> Or Consider checking USE_OPTIMIZED_LAPACK")
  342. endif()
  343. endif()
  344. # Neither user specified or optimized LAPACK libraries can be used
  345. if(NOT LATESTLAPACK_FOUND)
  346. message(STATUS "Using supplied NETLIB LAPACK implementation")
  347. set(LAPACK_LIBRARIES ${LAPACKLIB})
  348. add_subdirectory(SRC)
  349. else()
  350. set(CMAKE_EXE_LINKER_FLAGS
  351. "${CMAKE_EXE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
  352. CACHE STRING "Linker flags for executables" FORCE)
  353. set(CMAKE_MODULE_LINKER_FLAGS
  354. "${CMAKE_MODULE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
  355. CACHE STRING "Linker flags for modules" FORCE)
  356. set(CMAKE_SHARED_LINKER_FLAGS
  357. "${CMAKE_SHARED_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
  358. CACHE STRING "Linker flags for shared libs" FORCE)
  359. endif()
  360. if(BUILD_TESTING)
  361. add_subdirectory(TESTING)
  362. endif()
  363. # --------------------------------------------------
  364. # LAPACKE
  365. option(LAPACKE "Build LAPACKE" OFF)
  366. # LAPACKE has also the interface to some routines from tmglib,
  367. # if LAPACKE_WITH_TMG is selected, we need to add those routines to LAPACKE
  368. option(LAPACKE_WITH_TMG "Build LAPACKE with tmglib routines" OFF)
  369. if(LAPACKE_WITH_TMG)
  370. set(LAPACKE ON)
  371. endif()
  372. # TMGLIB
  373. # Cache export target
  374. set(LAPACK_INSTALL_EXPORT_NAME_CACHE ${LAPACK_INSTALL_EXPORT_NAME})
  375. if(BUILD_TESTING OR LAPACKE_WITH_TMG)
  376. if(LATESTLAPACK_FOUND AND LAPACKE_WITH_TMG)
  377. set(CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARIES})
  378. # Check if dlatms (part of tmg) is found
  379. CHECK_FORTRAN_FUNCTION_EXISTS("dlatms" LAPACK_WITH_TMGLIB_FOUND)
  380. unset(CMAKE_REQUIRED_LIBRARIES)
  381. if(NOT LAPACK_WITH_TMGLIB_FOUND)
  382. # Build and install TMG as part of LAPACKE targets (as opposed to LAPACK
  383. # targets)
  384. set(LAPACK_INSTALL_EXPORT_NAME ${LAPACKELIB}-targets)
  385. endif()
  386. endif()
  387. add_subdirectory(TESTING/MATGEN)
  388. endif()
  389. # Reset export target
  390. set(LAPACK_INSTALL_EXPORT_NAME ${LAPACK_INSTALL_EXPORT_NAME_CACHE})
  391. unset(LAPACK_INSTALL_EXPORT_NAME_CACHE)
  392. if(LAPACKE)
  393. add_subdirectory(LAPACKE)
  394. endif()
  395. #-------------------------------------
  396. # BLAS++ / LAPACK++
  397. option(BLAS++ "Build BLAS++" OFF)
  398. option(LAPACK++ "Build LAPACK++" OFF)
  399. function(_display_cpp_implementation_msg name)
  400. string(TOLOWER ${name} name_lc)
  401. message(STATUS "${name}++ enable")
  402. message(STATUS "----------------")
  403. message(STATUS "Thank you for your interest in ${name}++, a newly developed C++ API for ${name} library")
  404. message(STATUS "The objective of ${name}++ is to provide a convenient, performance oriented API for development in the C++ language, that, for the most part, preserves established conventions, while, at the same time, takes advantages of modern C++ features, such as: namespaces, templates, exceptions, etc.")
  405. message(STATUS "For support ${name}++ related question, please email: slate-user@icl.utk.edu")
  406. message(STATUS "----------------")
  407. endfunction()
  408. if (BLAS++)
  409. _display_cpp_implementation_msg("BLAS")
  410. include(ExternalProject)
  411. ExternalProject_Add(blaspp
  412. URL https://bitbucket.org/icl/blaspp/downloads/blaspp-2020.10.02.tar.gz
  413. CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env LIBRARY_PATH=$ENV{LIBRARY_PATH}:${CMAKE_BINARY_DIR}/lib LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:${PROJECT_BINARY_DIR}/lib ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR} -DCMAKE_INSTALL_LIBDIR=lib -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} ${PROJECT_BINARY_DIR}/blaspp-prefix/src/blaspp
  414. BUILD_COMMAND ${CMAKE_COMMAND} -E env LIBRARY_PATH=$ENV{LIBRARY_PATH}:${PROJECT_BINARY_DIR}/lib LIB_SUFFIX="" make
  415. INSTALL_COMMAND make PREFIX=${PROJECT_BINARY_DIR} LIB_SUFFIX="" install
  416. )
  417. ExternalProject_Add_StepDependencies(blaspp build ${BLAS_LIBRARIES})
  418. endif()
  419. if (LAPACK++)
  420. message (STATUS "linking lapack++ against ${LAPACK_LIBRARIES}")
  421. _display_cpp_implementation_msg("LAPACK")
  422. include(ExternalProject)
  423. if (BUILD_SHARED_LIBS)
  424. ExternalProject_Add(lapackpp
  425. URL https://bitbucket.org/icl/lapackpp/downloads/lapackpp-2020.10.02.tar.gz
  426. CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env LIBRARY_PATH=$ENV{LIBRARY_PATH}:${CMAKE_BINARY_DIR}/lib LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:${PROJECT_BINARY_DIR}/lib ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR} -DCMAKE_INSTALL_LIBDIR=lib -DLAPACK_LIBRARIES=${LAPACK_LIBRARIES} -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} ${PROJECT_BINARY_DIR}/lapackpp-prefix/src/lapackpp
  427. BUILD_COMMAND ${CMAKE_COMMAND} -E env LIBRARY_PATH=$ENV{LIBRARY_PATH}:${PROJECT_BINARY_DIR}/lib LIB_SUFFIX="" make
  428. INSTALL_COMMAND make PREFIX=${PROJECT_BINARY_DIR} LIB_SUFFIX="" install
  429. )
  430. else ()
  431. # FIXME this does not really work as the libraries list gets converted to a semicolon-separated list somewhere in the lapack++ build files
  432. ExternalProject_Add(lapackpp
  433. URL https://bitbucket.org/icl/lapackpp/downloads/lapackpp-2020.10.02.tar.gz
  434. CONFIGURE_COMMAND env LIBRARY_PATH=$ENV{LIBRARY_PATH}:${CMAKE_BINARY_DIR}/lib LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:${PROJECT_BINARY_DIR}/lib ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR} -DCMAKE_INSTALL_LIBDIR=lib -DLAPACK_LIBRARIES="${PROJECT_BINARY_DIR}/lib/liblapack.a -lgfortran" -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} ${PROJECT_BINARY_DIR}/lapackpp-prefix/src/lapackpp
  435. BUILD_COMMAND env LIBRARY_PATH=$ENV{LIBRARY_PATH}:${PROJECT_BINARY_DIR}/lib LIB_SUFFIX="" make
  436. INSTALL_COMMAND make PREFIX=${PROJECT_BINARY_DIR} LIB_SUFFIX="" install
  437. )
  438. endif()
  439. ExternalProject_Add_StepDependencies(lapackpp build blaspp ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES})
  440. endif()
  441. # --------------------------------------------------
  442. # CPACK Packaging
  443. set(CPACK_PACKAGE_NAME "LAPACK")
  444. set(CPACK_PACKAGE_VENDOR "University of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd")
  445. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LAPACK- Linear Algebra Package")
  446. set(CPACK_PACKAGE_VERSION_MAJOR ${LAPACK_MAJOR_VERSION})
  447. set(CPACK_PACKAGE_VERSION_MINOR ${LAPACK_MINOR_VERSION})
  448. set(CPACK_PACKAGE_VERSION_PATCH ${LAPACK_PATCH_VERSION})
  449. set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
  450. set(CPACK_MONOLITHIC_INSTALL ON)
  451. set(CPACK_PACKAGE_INSTALL_DIRECTORY "LAPACK")
  452. if(WIN32 AND NOT UNIX)
  453. # There is a bug in NSI that does not handle full unix paths properly. Make
  454. # sure there is at least one set of four (4) backslashes.
  455. set(CPACK_NSIS_HELP_LINK "http:\\\\\\\\http://icl.cs.utk.edu/lapack-forum")
  456. set(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.netlib.org/lapack")
  457. set(CPACK_NSIS_CONTACT "lapack@eecs.utk.edu")
  458. set(CPACK_NSIS_MODIFY_PATH ON)
  459. set(CPACK_NSIS_DISPLAY_NAME "LAPACK-${LAPACK_VERSION}")
  460. set(CPACK_PACKAGE_RELOCATABLE "true")
  461. else()
  462. set(CPACK_GENERATOR "TGZ")
  463. set(CPACK_SOURCE_GENERATOR TGZ)
  464. set(CPACK_SOURCE_PACKAGE_FILE_NAME "lapack-${LAPACK_VERSION}")
  465. set(CPACK_SOURCE_IGNORE_FILES ~$ .svn ${CPACK_SOURCE_IGNORE_FILES})
  466. endif()
  467. include(CPack)
  468. # --------------------------------------------------
  469. if(NOT BLAS_FOUND)
  470. set(ALL_TARGETS ${ALL_TARGETS} ${BLASLIB})
  471. endif()
  472. if(NOT LATESTLAPACK_FOUND)
  473. set(ALL_TARGETS ${ALL_TARGETS} ${LAPACKLIB})
  474. endif()
  475. # Export lapack targets, not including lapacke, from the
  476. # install tree, if any.
  477. set(_lapack_config_install_guard_target "")
  478. if(ALL_TARGETS)
  479. install(EXPORT ${LAPACKLIB}-targets
  480. DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${LAPACKLIB}-${LAPACK_VERSION}
  481. COMPONENT Development
  482. )
  483. # Choose one of the lapack targets to use as a guard for
  484. # lapack-config.cmake to load targets from the install tree.
  485. list(GET ALL_TARGETS 0 _lapack_config_install_guard_target)
  486. endif()
  487. # Include cblas in targets exported from the build tree.
  488. if(CBLAS)
  489. set(ALL_TARGETS ${ALL_TARGETS} ${CBLASLIB})
  490. endif()
  491. # Include lapacke in targets exported from the build tree.
  492. if(LAPACKE)
  493. set(ALL_TARGETS ${ALL_TARGETS} ${LAPACKELIB})
  494. endif()
  495. if(NOT LAPACK_WITH_TMGLIB_FOUND AND LAPACKE_WITH_TMG)
  496. set(ALL_TARGETS ${ALL_TARGETS} ${TMGLIB})
  497. endif()
  498. # Export lapack and lapacke targets from the build tree, if any.
  499. set(_lapack_config_build_guard_target "")
  500. if(ALL_TARGETS)
  501. export(TARGETS ${ALL_TARGETS} FILE ${LAPACKLIB}-targets.cmake)
  502. # Choose one of the lapack or lapacke targets to use as a guard
  503. # for lapack-config.cmake to load targets from the build tree.
  504. list(GET ALL_TARGETS 0 _lapack_config_build_guard_target)
  505. endif()
  506. configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-build.cmake.in
  507. ${LAPACK_BINARY_DIR}/${LAPACKLIB}-config.cmake @ONLY)
  508. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lapack.pc.in ${CMAKE_CURRENT_BINARY_DIR}/${LAPACKLIB}.pc @ONLY)
  509. install(FILES
  510. ${CMAKE_CURRENT_BINARY_DIR}/${LAPACKLIB}.pc
  511. DESTINATION ${PKG_CONFIG_DIR}
  512. COMPONENT Development
  513. )
  514. configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-install.cmake.in
  515. ${LAPACK_BINARY_DIR}/CMakeFiles/${LAPACKLIB}-config.cmake @ONLY)
  516. include(CMakePackageConfigHelpers)
  517. write_basic_package_version_file(
  518. ${LAPACK_BINARY_DIR}/${LAPACKLIB}-config-version.cmake
  519. VERSION ${LAPACK_VERSION}
  520. COMPATIBILITY SameMajorVersion
  521. )
  522. install(FILES
  523. ${LAPACK_BINARY_DIR}/CMakeFiles/${LAPACKLIB}-config.cmake
  524. ${LAPACK_BINARY_DIR}/${LAPACKLIB}-config-version.cmake
  525. DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${LAPACKLIB}-${LAPACK_VERSION}
  526. COMPONENT Development
  527. )
  528. if (LAPACK++)
  529. install(
  530. DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
  531. DESTINATION ${CMAKE_INSTALL_LIBDIR}
  532. FILES_MATCHING REGEX "liblapackpp.(a|so)$"
  533. )
  534. install(
  535. DIRECTORY "${PROJECT_BINARY_DIR}/lapackpp-prefix/src/lapackpp/include/"
  536. DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
  537. FILES_MATCHING REGEX "\\.(h|hh)$"
  538. )
  539. write_basic_package_version_file(
  540. "lapackppConfigVersion.cmake"
  541. VERSION 2020.10.02
  542. COMPATIBILITY AnyNewerVersion
  543. )
  544. install(
  545. FILES "${CMAKE_CURRENT_BINARY_DIR}/lib/lapackpp/lapackppConfig.cmake"
  546. "${CMAKE_CURRENT_BINARY_DIR}/lib/lapackpp/lapackppConfigVersion.cmake"
  547. DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/"
  548. )
  549. endif()
  550. if (BLAS++)
  551. write_basic_package_version_file(
  552. "blasppConfigVersion.cmake"
  553. VERSION 2020.10.02
  554. COMPATIBILITY AnyNewerVersion
  555. )
  556. install(
  557. FILES "${CMAKE_CURRENT_BINARY_DIR}/lib/blaspp/blasppConfig.cmake"
  558. "${CMAKE_CURRENT_BINARY_DIR}/lib/blaspp/blasppConfigVersion.cmake"
  559. DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/"
  560. )
  561. install(
  562. DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
  563. DESTINATION ${CMAKE_INSTALL_LIBDIR}
  564. FILES_MATCHING REGEX "libblaspp.(a|so)$"
  565. )
  566. install(
  567. DIRECTORY "${PROJECT_BINARY_DIR}/blaspp-prefix/src/blaspp/include/"
  568. DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
  569. FILES_MATCHING REGEX "\\.(h|hh)$"
  570. )
  571. endif()
  572. # --------------------------------------------------
  573. # Generate MAN and/or HTML Documentation
  574. option(BUILD_HTML_DOCUMENTATION "Create and install the HTML based API
  575. documentation (requires Doxygen) - command: make html" OFF)
  576. option(BUILD_MAN_DOCUMENTATION "Create and install the MAN based documentation (requires Doxygen) - command: make man" OFF)
  577. message(STATUS "Build html documentation: ${BUILD_HTML_DOCUMENTATION}")
  578. message(STATUS "Build man documentation: ${BUILD_MAN_DOCUMENTATION}")
  579. if(BUILD_HTML_DOCUMENTATION OR BUILD_MAN_DOCUMENTATION)
  580. find_package(Doxygen)
  581. if(NOT DOXYGEN_FOUND)
  582. message(WARNING "Doxygen is needed to build the documentation.")
  583. else()
  584. set(DOXYGEN_PROJECT_BRIEF "LAPACK: Linear Algebra PACKage")
  585. set(DOXYGEN_PROJECT_NUMBER ${LAPACK_VERSION})
  586. set(DOXYGEN_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/DOCS)
  587. set(PROJECT_LOGO ${CMAKE_CURRENT_SOURCE_DIR}/DOCS/lapack.png)
  588. set(DOXYGEN_OPTIMIZE_FOR_FORTRAN YES)
  589. set(DOXYGEN_SOURCE_BROWSER YES)
  590. set(DISTRIBUTE_GROUP_DOC YES)
  591. set(DOXYGEN_CREATE_SUBDIRS YES)
  592. set(DOXYGEN_SEPARATE_MEMBER_PAGES YES)
  593. set(DOXYGEN_EXTRACT_ALL YES)
  594. set(DOXYGEN_FILE_PATTERNS "*.f;*.c;*.h")
  595. set(DOXYGEN_RECURSIVE YES)
  596. set(DOXYGEN_GENERATE_TREEVIEW YES)
  597. set(DOXYGEN_INTERACTIVE_SVG YES)
  598. set(DOXYGEN_QUIET YES)
  599. set(DOXYGEN_WARNINGS NO)
  600. set(DOXYGEN_GENERATE_HTML NO)
  601. set(DOXYGEN_GENERATE_MAN NO)
  602. if (BUILD_HTML_DOCUMENTATION)
  603. set(DOXYGEN_GENERATE_HTML YES)
  604. set(DOXYGEN_HTML_OUTPUT explore-html)
  605. set(DOXYGEN_INLINE_SOURCES YES)
  606. set(DOXYGEN_CALL_GRAPH YES)
  607. set(DOXYGEN_CALLER_GRAPH YES)
  608. doxygen_add_docs(
  609. html
  610. ${PROJECT_SOURCE_DIR}
  611. COMMENT "Generating html LAPACK documentation (it will take some time... time to grab a coffee)"
  612. )
  613. endif()
  614. if (BUILD_MAN_DOCUMENTATION)
  615. set(DOXYGEN_GENERATE_MAN YES)
  616. set(DOXYGEN_EXCLUDE SRC/VARIANTS)
  617. set(DOXYGEN_MAN_LINKS YES)
  618. set(DOXYGEN_INLINE_SOURCES NO)
  619. set(DOXYGEN_CALL_GRAPH NO)
  620. set(DOXYGEN_CALLER_GRAPH NO)
  621. doxygen_add_docs(
  622. man
  623. ${PROJECT_SOURCE_DIR}
  624. COMMENT "Generating man LAPACK documentation"
  625. )
  626. endif()
  627. endif()
  628. endif()