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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. cmake_minimum_required(VERSION 2.8.10)
  2. # Set a default build type if none was specified
  3. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  4. message(STATUS "Setting build type to 'Release' as none was specified.")
  5. set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
  6. # Set the possible values of build type for cmake-gui
  7. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
  8. endif()
  9. project(LAPACK Fortran)
  10. set(LAPACK_MAJOR_VERSION 3)
  11. set(LAPACK_MINOR_VERSION 7)
  12. set(LAPACK_PATCH_VERSION 0)
  13. set(
  14. LAPACK_VERSION
  15. ${LAPACK_MAJOR_VERSION}.${LAPACK_MINOR_VERSION}.${LAPACK_PATCH_VERSION}
  16. )
  17. # Updated OSX RPATH settings
  18. # In response to CMake 3.0 generating warnings regarding policy CMP0042,
  19. # the OSX RPATH settings have been updated per recommendations found
  20. # in the CMake Wiki:
  21. # http://www.cmake.org/Wiki/CMake_RPATH_handling#Mac_OS_X_and_the_RPATH
  22. set(CMAKE_MACOSX_RPATH ON)
  23. set(CMAKE_SKIP_BUILD_RPATH FALSE)
  24. set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
  25. list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}" isSystemDir)
  26. if("${isSystemDir}" STREQUAL "-1")
  27. set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
  28. set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  29. endif()
  30. # Configure the warning and code coverage suppression file
  31. configure_file(
  32. "${LAPACK_SOURCE_DIR}/CTestCustom.cmake.in"
  33. "${LAPACK_BINARY_DIR}/CTestCustom.cmake"
  34. @ONLY
  35. )
  36. # Add the CMake directory for custon CMake modules
  37. set(CMAKE_MODULE_PATH "${LAPACK_SOURCE_DIR}/CMAKE" ${CMAKE_MODULE_PATH})
  38. include(PreventInSourceBuilds)
  39. include(PreventInBuildInstalls)
  40. if(UNIX)
  41. if("${CMAKE_Fortran_COMPILER}" MATCHES "ifort")
  42. set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fp-model strict")
  43. endif()
  44. if("${CMAKE_Fortran_COMPILER}" MATCHES "xlf")
  45. set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qnosave -qstrict=none")
  46. endif()
  47. # Delete libmtsk in linking sequence for Sun/Oracle Fortran Compiler.
  48. # This library is not present in the Sun package SolarisStudio12.3-linux-x86-bin
  49. string(REPLACE \;mtsk\; \; CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}")
  50. endif()
  51. if(CMAKE_Fortran_COMPILER_ID STREQUAL "Compaq")
  52. if(WIN32)
  53. if(CMAKE_GENERATOR STREQUAL "NMake Makefiles")
  54. get_filename_component(CMAKE_Fortran_COMPILER_CMDNAM ${CMAKE_Fortran_COMPILER} NAME_WE)
  55. message(STATUS "Using Compaq Fortran compiler with command name ${CMAKE_Fortran_COMPILER_CMDNAM}")
  56. set(cmd ${CMAKE_Fortran_COMPILER_CMDNAM})
  57. string(TOLOWER "${cmd}" cmdlc)
  58. if(cmdlc STREQUAL "df")
  59. message(STATUS "Assume the Compaq Visual Fortran Compiler is being used")
  60. set(CMAKE_Fortran_USE_RESPONSE_FILE_FOR_OBJECTS 1)
  61. set(CMAKE_Fortran_USE_RESPONSE_FILE_FOR_INCLUDES 1)
  62. #This is a workaround that is needed to avoid forward-slashes in the
  63. #filenames listed in response files from incorrectly being interpreted as
  64. #introducing compiler command options
  65. if(${BUILD_SHARED_LIBS})
  66. message(FATAL_ERROR "Making of shared libraries with CVF has not been tested.")
  67. endif()
  68. set(str "NMake version 9 or later should be used. NMake version 6.0 which is\n")
  69. set(str "${str} included with the CVF distribution fails to build Lapack because\n")
  70. set(str "${str} the number of source files exceeds the limit for NMake v6.0\n")
  71. message(STATUS ${str})
  72. set(CMAKE_Fortran_LINK_EXECUTABLE "LINK /out:<TARGET> <LINK_FLAGS> <LINK_LIBRARIES> <OBJECTS>")
  73. endif()
  74. endif()
  75. endif()
  76. endif()
  77. # Get Python
  78. message(STATUS "Looking for Python greater than 2.6 - ${PYTHONINTERP_FOUND}")
  79. find_package(PythonInterp 2.7) # lapack_testing.py uses features from python 2.7 and greater
  80. if(PYTHONINTERP_FOUND)
  81. message(STATUS "Using Python version ${PYTHON_VERSION_STRING}")
  82. else()
  83. message(STATUS "No suitable Python version found, so skipping summary tests.")
  84. endif()
  85. # --------------------------------------------------
  86. set(LAPACK_INSTALL_EXPORT_NAME lapack-targets)
  87. if(UNIX)
  88. include(GNUInstallDirs)
  89. set(ARCHIVE_DIR ${CMAKE_INSTALL_LIBDIR})
  90. set(LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR})
  91. set(RUNTIME_DIR ${CMAKE_INSTALL_BINDIR})
  92. else()
  93. set(ARCHIVE_DIR lib${LIB_SUFFIX})
  94. set(LIBRARY_DIR lib${LIB_SUFFIX})
  95. set(RUNTIME_DIR bin)
  96. endif()
  97. macro(lapack_install_library lib)
  98. install(TARGETS ${lib}
  99. EXPORT ${LAPACK_INSTALL_EXPORT_NAME}
  100. ARCHIVE DESTINATION ${ARCHIVE_DIR}
  101. LIBRARY DESTINATION ${LIBRARY_DIR}
  102. RUNTIME DESTINATION ${RUNTIME_DIR}
  103. )
  104. endmacro()
  105. set(PKG_CONFIG_DIR ${LIBRARY_DIR}/pkgconfig)
  106. set(prefix ${CMAKE_INSTALL_PREFIX})
  107. if(NOT IS_ABSOLUTE ${LIBRARY_DIR})
  108. set(libdir "\${prefix}/${LIBRARY_DIR}")
  109. else()
  110. set(libdir "${LIBRARY_DIR}")
  111. endif()
  112. # --------------------------------------------------
  113. # Testing
  114. enable_testing()
  115. include(CTest)
  116. enable_testing()
  117. # --------------------------------------------------
  118. # Organize output files. On Windows this also keeps .dll files next
  119. # to the .exe files that need them, making tests easy to run.
  120. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/bin)
  121. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/lib)
  122. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/lib)
  123. # --------------------------------------------------
  124. # Check for any necessary platform specific compiler flags
  125. include(CheckLAPACKCompilerFlags)
  126. CheckLAPACKCompilerFlags()
  127. # --------------------------------------------------
  128. # Check second function
  129. include(CheckTimeFunction)
  130. set(TIME_FUNC NONE ${TIME_FUNC})
  131. CHECK_TIME_FUNCTION(NONE TIME_FUNC)
  132. CHECK_TIME_FUNCTION(INT_CPU_TIME TIME_FUNC)
  133. CHECK_TIME_FUNCTION(EXT_ETIME TIME_FUNC)
  134. CHECK_TIME_FUNCTION(EXT_ETIME_ TIME_FUNC)
  135. CHECK_TIME_FUNCTION(INT_ETIME TIME_FUNC)
  136. message(STATUS "--> Will use second_${TIME_FUNC}.f and dsecnd_${TIME_FUNC}.f as timing function.")
  137. set(SECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/second_${TIME_FUNC}.f)
  138. set(DSECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/dsecnd_${TIME_FUNC}.f)
  139. # By default static library
  140. option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
  141. option(BUILD_TESTING "Build tests" OFF)
  142. # deprecated LAPACK routines
  143. option(BUILD_DEPRECATED "Build deprecated routines" OFF)
  144. # --------------------------------------------------
  145. # Precision to build
  146. # By default all precisions are generated
  147. option(BUILD_SINGLE "Build LAPACK Single Precision" ON)
  148. option(BUILD_DOUBLE "Build LAPACK Double Precision" ON)
  149. option(BUILD_COMPLEX "Build LAPACK Complex Precision" ON)
  150. option(BUILD_COMPLEX16 "Build LAPACK Double Complex Precision" ON)
  151. # --------------------------------------------------
  152. # Subdirectories that need to be processed
  153. option(USE_OPTIMIZED_BLAS "Whether or not to use an optimized BLAS library instead of included netlib BLAS" OFF)
  154. # Check the usage of the user provided BLAS libraries
  155. if(BLAS_LIBRARIES)
  156. include(CheckFortranFunctionExists)
  157. set(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})
  158. CHECK_FORTRAN_FUNCTION_EXISTS("dgemm" BLAS_FOUND)
  159. unset(CMAKE_REQUIRED_LIBRARIES)
  160. if(BLAS_FOUND)
  161. message(STATUS "--> BLAS supplied by user is WORKING, will use ${BLAS_LIBRARIES}.")
  162. else()
  163. message(ERROR "--> BLAS supplied by user is not WORKING, CANNOT USE ${BLAS_LIBRARIES}.")
  164. message(ERROR "--> Will use REFERENCE BLAS (by default)")
  165. message(ERROR "--> Or Correct your BLAS_LIBRARIES entry ")
  166. message(ERROR "--> Or Consider checking USE_OPTIMIZED_BLAS")
  167. endif()
  168. # User did not provide a BLAS Library but specified to search for one
  169. elseif(USE_OPTIMIZED_BLAS)
  170. find_package(BLAS)
  171. endif()
  172. # Neither user specified or optimized BLAS libraries can be used
  173. if(NOT BLAS_FOUND)
  174. message(STATUS "Using supplied NETLIB BLAS implementation")
  175. add_subdirectory(BLAS)
  176. set(BLAS_LIBRARIES blas)
  177. else()
  178. set(CMAKE_EXE_LINKER_FLAGS
  179. "${CMAKE_EXE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
  180. CACHE STRING "Linker flags for executables" FORCE)
  181. set(CMAKE_MODULE_LINKER_FLAGS
  182. "${CMAKE_MODULE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
  183. CACHE STRING "Linker flags for modules" FORCE)
  184. set(CMAKE_SHARED_LINKER_FLAGS
  185. "${CMAKE_SHARED_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
  186. CACHE STRING "Linker flags for shared libs" FORCE)
  187. endif()
  188. # --------------------------------------------------
  189. # CBLAS
  190. option(CBLAS "Build CBLAS" OFF)
  191. if(CBLAS)
  192. add_subdirectory(CBLAS)
  193. endif()
  194. # --------------------------------------------------
  195. # XBLAS
  196. option(USE_XBLAS "Build extended precision (needs XBLAS)" OFF)
  197. if(USE_XBLAS)
  198. find_library(XBLAS_LIBRARY NAMES xblas)
  199. endif()
  200. option(USE_OPTIMIZED_LAPACK "Whether or not to use an optimized LAPACK library instead of included netlib LAPACK" OFF)
  201. # --------------------------------------------------
  202. # LAPACK
  203. # User did not provide a LAPACK Library but specified to search for one
  204. if(USE_OPTIMIZED_LAPACK)
  205. find_package(LAPACK)
  206. endif()
  207. # Check the usage of the user provided or automatically found LAPACK libraries
  208. if(LAPACK_LIBRARIES)
  209. include(CheckFortranFunctionExists)
  210. set(CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARIES})
  211. # Check if new routine of 3.4.0 is in LAPACK_LIBRARIES
  212. CHECK_FORTRAN_FUNCTION_EXISTS("dgeqrt" LATESTLAPACK_FOUND)
  213. unset(CMAKE_REQUIRED_LIBRARIES)
  214. if(LATESTLAPACK_FOUND)
  215. message(STATUS "--> LAPACK supplied by user is WORKING, will use ${LAPACK_LIBRARIES}.")
  216. else()
  217. message(ERROR "--> LAPACK supplied by user is not WORKING or is older than LAPACK 3.4.0, CANNOT USE ${LAPACK_LIBRARIES}.")
  218. message(ERROR "--> Will use REFERENCE LAPACK (by default)")
  219. message(ERROR "--> Or Correct your LAPACK_LIBRARIES entry ")
  220. message(ERROR "--> Or Consider checking USE_OPTIMIZED_LAPACK")
  221. endif()
  222. endif()
  223. # Neither user specified or optimized LAPACK libraries can be used
  224. if(NOT LATESTLAPACK_FOUND)
  225. message(STATUS "Using supplied NETLIB LAPACK implementation")
  226. set(LAPACK_LIBRARIES lapack)
  227. add_subdirectory(SRC)
  228. else()
  229. set(CMAKE_EXE_LINKER_FLAGS
  230. "${CMAKE_EXE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
  231. CACHE STRING "Linker flags for executables" FORCE)
  232. set(CMAKE_MODULE_LINKER_FLAGS
  233. "${CMAKE_MODULE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
  234. CACHE STRING "Linker flags for modules" FORCE)
  235. set(CMAKE_SHARED_LINKER_FLAGS
  236. "${CMAKE_SHARED_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
  237. CACHE STRING "Linker flags for shared libs" FORCE)
  238. endif()
  239. message(STATUS "BUILD TESTING : ${BUILD_TESTING}")
  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 ${LIBRARY_DIR}/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 ${LIBRARY_DIR}/cmake/lapack-${LAPACK_VERSION}
  339. )