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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 20.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("${PROJECT_SOURCE_DIR}/cmake/utils.cmake")
  39. include("${PROJECT_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 SANITY_CHECK)
  45. list(APPEND BLASDIRS reference)
  46. endif ()
  47. set(SUBDIRS ${BLASDIRS})
  48. if (NOT NO_LAPACK)
  49. list(APPEND SUBDIRS lapack)
  50. endif ()
  51. # set which float types we want to build for
  52. if (NOT DEFINED BUILD_SINGLE AND NOT DEFINED BUILD_DOUBLE AND NOT DEFINED BUILD_COMPLEX AND NOT DEFINED BUILD_COMPLEX16)
  53. # if none are defined, build for all
  54. set(BUILD_SINGLE true)
  55. set(BUILD_DOUBLE true)
  56. set(BUILD_COMPLEX true)
  57. set(BUILD_COMPLEX16 true)
  58. endif ()
  59. set(FLOAT_TYPES "")
  60. if (BUILD_SINGLE)
  61. message(STATUS "Building Single Precision")
  62. list(APPEND FLOAT_TYPES "SINGLE") # defines nothing
  63. endif ()
  64. if (BUILD_DOUBLE)
  65. message(STATUS "Building Double Precision")
  66. list(APPEND FLOAT_TYPES "DOUBLE") # defines DOUBLE
  67. endif ()
  68. if (BUILD_COMPLEX)
  69. message(STATUS "Building Complex Precision")
  70. list(APPEND FLOAT_TYPES "COMPLEX") # defines COMPLEX
  71. endif ()
  72. if (BUILD_COMPLEX16)
  73. message(STATUS "Building Double Complex Precision")
  74. list(APPEND FLOAT_TYPES "ZCOMPLEX") # defines COMPLEX and DOUBLE
  75. endif ()
  76. set(SUBDIRS_ALL ${SUBDIRS} test ctest utest exports benchmark ../laswp ../bench)
  77. # all :: libs netlib tests shared
  78. # libs :
  79. if (NOT DEFINED CORE OR "${CORE}" STREQUAL "UNKNOWN")
  80. message(FATAL_ERROR "Detecting CPU failed. Please set TARGET explicitly, e.g. make TARGET=your_cpu_target. Please read README for details.")
  81. endif ()
  82. if (${NO_STATIC} AND ${NO_SHARED})
  83. message(FATAL_ERROR "Neither static nor shared are enabled.")
  84. endif ()
  85. #Set default output directory
  86. set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib )
  87. set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib )
  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("${PROJECT_SOURCE_DIR}/cmake/lapack.cmake")
  100. if (NOT NO_LAPACKE)
  101. include("${PROJECT_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("${PROJECT_SOURCE_DIR}/cmake/export.cmake")
  111. # Set output for libopenblas
  112. set_target_properties( ${OpenBLAS_LIBNAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
  113. foreach (OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
  114. string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
  115. set_target_properties( ${OpenBLAS_LIBNAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR}/lib)
  116. set_target_properties( ${OpenBLAS_LIBNAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR}/lib)
  117. set_target_properties( ${OpenBLAS_LIBNAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR}/lib)
  118. endforeach()
  119. enable_testing()
  120. add_subdirectory(utest)
  121. if(NOT MSVC)
  122. #only build shared library for MSVC
  123. add_library(${OpenBLAS_LIBNAME}_static STATIC ${LA_SOURCES} ${LAPACKE_SOURCES} ${TARGET_OBJS})
  124. set_target_properties(${OpenBLAS_LIBNAME}_static PROPERTIES OUTPUT_NAME ${OpenBLAS_LIBNAME})
  125. set_target_properties(${OpenBLAS_LIBNAME}_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
  126. if(SMP)
  127. target_link_libraries(${OpenBLAS_LIBNAME} pthread)
  128. target_link_libraries(${OpenBLAS_LIBNAME}_static pthread)
  129. endif()
  130. #build test and ctest
  131. add_subdirectory(test)
  132. if(NOT NO_CBLAS)
  133. add_subdirectory(ctest)
  134. endif()
  135. endif()
  136. set_target_properties(${OpenBLAS_LIBNAME} PROPERTIES
  137. VERSION ${OpenBLAS_MAJOR_VERSION}.${OpenBLAS_MINOR_VERSION}
  138. SOVERSION ${OpenBLAS_MAJOR_VERSION}
  139. )
  140. # TODO: Why is the config saved here? Is this necessary with CMake?
  141. #Save the config files for installation
  142. # @cp Makefile.conf Makefile.conf_last
  143. # @cp config.h config_last.h
  144. #ifdef QUAD_PRECISION
  145. # @echo "#define QUAD_PRECISION">> config_last.h
  146. #endif
  147. #ifeq ($(EXPRECISION), 1)
  148. # @echo "#define EXPRECISION">> config_last.h
  149. #endif
  150. ###
  151. #ifeq ($(DYNAMIC_ARCH), 1)
  152. # @$(MAKE) -C kernel commonlibs || exit 1
  153. # @for d in $(DYNAMIC_CORE) ; \
  154. # do $(MAKE) GOTOBLAS_MAKEFILE= -C kernel TARGET_CORE=$$d kernel || exit 1 ;\
  155. # done
  156. # @echo DYNAMIC_ARCH=1 >> Makefile.conf_last
  157. #endif
  158. #ifdef USE_THREAD
  159. # @echo USE_THREAD=$(USE_THREAD) >> Makefile.conf_last
  160. #endif
  161. # @touch lib.grd