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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. ##
  2. ## Author: Hank Anderson <hank@statease.com>
  3. ##
  4. cmake_minimum_required(VERSION 2.8.4)
  5. project(OpenBLAS)
  6. set(OpenBLAS_MAJOR_VERSION 0)
  7. set(OpenBLAS_MINOR_VERSION 2)
  8. set(OpenBLAS_PATCH_VERSION 16.dev)
  9. set(OpenBLAS_VERSION "${OpenBLAS_MAJOR_VERSION}.${OpenBLAS_MINOR_VERSION}.${OpenBLAS_PATCH_VERSION}")
  10. enable_language(ASM)
  11. enable_language(C)
  12. if(MSVC)
  13. set(OpenBLAS_LIBNAME libopenblas)
  14. else()
  15. set(OpenBLAS_LIBNAME openblas)
  16. endif()
  17. #######
  18. if(MSVC)
  19. option(BUILD_WITHOUT_LAPACK "Without LAPACK and LAPACKE (Only BLAS or CBLAS)" ON)
  20. endif()
  21. option(BUILD_WITHOUT_CBLAS "Without CBLAS" OFF)
  22. option(BUILD_DEBUG "Build Debug Version" OFF)
  23. #######
  24. if(BUILD_WITHOUT_LAPACK)
  25. set(NO_LAPACK 1)
  26. set(NO_LAPACKE 1)
  27. endif()
  28. if(BUILD_DEBUG)
  29. set(CMAKE_BUILD_TYPE Debug)
  30. else()
  31. set(CMAKE_BUILD_TYPE Release)
  32. endif()
  33. if(BUILD_WITHOUT_CBLAS)
  34. set(NO_CBLAS 1)
  35. endif()
  36. #######
  37. message(WARNING "CMake support is experimental. This will not produce the same Makefiles that OpenBLAS ships with. Only x86 support is currently available.")
  38. include("${CMAKE_SOURCE_DIR}/cmake/utils.cmake")
  39. include("${CMAKE_SOURCE_DIR}/cmake/system.cmake")
  40. set(BLASDIRS interface driver/level2 driver/level3 driver/others)
  41. if (NOT DYNAMIC_ARCH)
  42. list(APPEND BLASDIRS kernel)
  43. endif ()
  44. if (DEFINED UTEST_CHECK)
  45. set(SANITY_CHECK 1)
  46. endif ()
  47. if (DEFINED SANITY_CHECK)
  48. list(APPEND BLASDIRS reference)
  49. endif ()
  50. set(SUBDIRS ${BLASDIRS})
  51. if (NOT NO_LAPACK)
  52. list(APPEND SUBDIRS lapack)
  53. endif ()
  54. # set which float types we want to build for
  55. if (NOT DEFINED BUILD_SINGLE AND NOT DEFINED BUILD_DOUBLE AND NOT DEFINED BUILD_COMPLEX AND NOT DEFINED BUILD_COMPLEX16)
  56. # if none are defined, build for all
  57. set(BUILD_SINGLE true)
  58. set(BUILD_DOUBLE true)
  59. set(BUILD_COMPLEX true)
  60. set(BUILD_COMPLEX16 true)
  61. endif ()
  62. set(FLOAT_TYPES "")
  63. if (BUILD_SINGLE)
  64. message(STATUS "Building Single Precision")
  65. list(APPEND FLOAT_TYPES "SINGLE") # defines nothing
  66. endif ()
  67. if (BUILD_DOUBLE)
  68. message(STATUS "Building Double Precision")
  69. list(APPEND FLOAT_TYPES "DOUBLE") # defines DOUBLE
  70. endif ()
  71. if (BUILD_COMPLEX)
  72. message(STATUS "Building Complex Precision")
  73. list(APPEND FLOAT_TYPES "COMPLEX") # defines COMPLEX
  74. endif ()
  75. if (BUILD_COMPLEX16)
  76. message(STATUS "Building Double Complex Precision")
  77. list(APPEND FLOAT_TYPES "ZCOMPLEX") # defines COMPLEX and DOUBLE
  78. endif ()
  79. set(SUBDIRS_ALL ${SUBDIRS} test ctest utest exports benchmark ../laswp ../bench)
  80. # all :: libs netlib tests shared
  81. # libs :
  82. if (NOT DEFINED CORE OR "${CORE}" STREQUAL "UNKNOWN")
  83. message(FATAL_ERROR "Detecting CPU failed. Please set TARGET explicitly, e.g. make TARGET=your_cpu_target. Please read README for details.")
  84. endif ()
  85. if (${NO_STATIC} AND ${NO_SHARED})
  86. message(FATAL_ERROR "Neither static nor shared are enabled.")
  87. endif ()
  88. # get obj vars into format that add_library likes: $<TARGET_OBJS:objlib> (see http://www.cmake.org/cmake/help/v3.0/command/add_library.html)
  89. set(TARGET_OBJS "")
  90. foreach (SUBDIR ${SUBDIRS})
  91. add_subdirectory(${SUBDIR})
  92. string(REPLACE "/" "_" subdir_obj ${SUBDIR})
  93. list(APPEND TARGET_OBJS "$<TARGET_OBJECTS:${subdir_obj}>")
  94. endforeach ()
  95. # netlib:
  96. # Can't just use lapack-netlib's CMake files, since they are set up to search for BLAS, build and install a binary. We just want to build a couple of lib files out of lapack and lapacke.
  97. # Not using add_subdirectory here because lapack-netlib already has its own CMakeLists.txt. Instead include a cmake script with the sources we want.
  98. if (NOT NOFORTRAN AND NOT NO_LAPACK)
  99. include("${CMAKE_SOURCE_DIR}/cmake/lapack.cmake")
  100. if (NOT NO_LAPACKE)
  101. include("${CMAKE_SOURCE_DIR}/cmake/lapacke.cmake")
  102. endif ()
  103. endif ()
  104. #Only generate .def for dll on MSVC
  105. if(MSVC)
  106. set(OpenBLAS_DEF_FILE "${PROJECT_BINARY_DIR}/openblas.def")
  107. endif()
  108. # add objects to the openblas lib
  109. add_library(${OpenBLAS_LIBNAME} SHARED ${LA_SOURCES} ${LAPACKE_SOURCES} ${TARGET_OBJS} ${OpenBLAS_DEF_FILE})
  110. include("${CMAKE_SOURCE_DIR}/cmake/export.cmake")
  111. if(NOT MSVC)
  112. #only build shared library for MSVC
  113. add_library(${OpenBLAS_LIBNAME}_static STATIC ${LA_SOURCES} ${LAPACKE_SOURCES} ${TARGET_OBJS})
  114. set_target_properties(${OpenBLAS_LIBNAME}_static PROPERTIES OUTPUT_NAME ${OpenBLAS_LIBNAME})
  115. set_target_properties(${OpenBLAS_LIBNAME}_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
  116. if(SMP)
  117. target_link_libraries(${OpenBLAS_LIBNAME} pthread)
  118. target_link_libraries(${OpenBLAS_LIBNAME}_static pthread)
  119. endif()
  120. #build test and ctest
  121. enable_testing()
  122. add_subdirectory(test)
  123. if(NOT NO_CBLAS)
  124. add_subdirectory(ctest)
  125. endif()
  126. endif()
  127. set_target_properties(${OpenBLAS_LIBNAME} PROPERTIES
  128. VERSION ${OpenBLAS_MAJOR_VERSION}.${OpenBLAS_MINOR_VERSION}
  129. SOVERSION ${OpenBLAS_MAJOR_VERSION}
  130. )
  131. # TODO: Why is the config saved here? Is this necessary with CMake?
  132. #Save the config files for installation
  133. # @cp Makefile.conf Makefile.conf_last
  134. # @cp config.h config_last.h
  135. #ifdef QUAD_PRECISION
  136. # @echo "#define QUAD_PRECISION">> config_last.h
  137. #endif
  138. #ifeq ($(EXPRECISION), 1)
  139. # @echo "#define EXPRECISION">> config_last.h
  140. #endif
  141. ###
  142. #ifeq ($(DYNAMIC_ARCH), 1)
  143. # @$(MAKE) -C kernel commonlibs || exit 1
  144. # @for d in $(DYNAMIC_CORE) ; \
  145. # do $(MAKE) GOTOBLAS_MAKEFILE= -C kernel TARGET_CORE=$$d kernel || exit 1 ;\
  146. # done
  147. # @echo DYNAMIC_ARCH=1 >> Makefile.conf_last
  148. #endif
  149. #ifdef USE_THREAD
  150. # @echo USE_THREAD=$(USE_THREAD) >> Makefile.conf_last
  151. #endif
  152. # @touch lib.grd