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.

OpenBLAS.cmake 1.7 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. if(MGE_USE_SYSTEM_LIB)
  2. find_package(OpenBLAS)
  3. set(MGE_USE_SYSTEM_OPENBLAS ON)
  4. message(STATUS "Using system provided OpenBLAS ${OpenBLAS_VERSION}")
  5. add_library(libopenblas IMPORTED GLOBAL)
  6. set_target_properties(
  7. libopenblas PROPERTIES IMPORTED_LOCATION ${OpenBLAS_LIBRARIES}
  8. INTERFACE_INCLUDE_DIRECTORIES ${OpenBLAS_INCLUDE_DIRS})
  9. return()
  10. endif()
  11. include(ExternalProject)
  12. include(GNUInstallDirs)
  13. set(OPENBLAS_DIR
  14. "${PROJECT_SOURCE_DIR}/third_party/OpenBLAS"
  15. CACHE STRING "OpenBLAS directory")
  16. set(OPENBLAS_BUILD_DIR ${PROJECT_BINARY_DIR}/third_party/OpenBLAS)
  17. set(OPENBLAS_INC ${OPENBLAS_BUILD_DIR}/include)
  18. set(OPENBLAS_LIB ${OPENBLAS_BUILD_DIR}/${CMAKE_INSTALL_LIBDIR}/libopenblas.a)
  19. if(${CMAKE_GENERATOR} STREQUAL "Ninja")
  20. set(MAKE_COMMAND make)
  21. else()
  22. set(MAKE_COMMAND "$(MAKE)")
  23. endif()
  24. ExternalProject_Add(
  25. openblas
  26. SOURCE_DIR ${OPENBLAS_DIR}
  27. PREFIX ${OPENBLAS_BUILD_DIR}
  28. CMAKE_GENERATOR "Unix Makefiles"
  29. CMAKE_ARGS -DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}
  30. -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
  31. -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
  32. -DCMAKE_INSTALL_PREFIX=${OPENBLAS_BUILD_DIR}
  33. -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
  34. -DCMAKE_POSITION_INDEPENDENT_CODE=ON
  35. BUILD_COMMAND ${MAKE_COMMAND}
  36. BUILD_BYPRODUCTS ${OPENBLAS_LIB} ${OPENBLAS_PROTOC_EXECUTABLE})
  37. file(MAKE_DIRECTORY ${OPENBLAS_INC})
  38. add_library(libopenblas STATIC IMPORTED GLOBAL)
  39. add_dependencies(libopenblas openblas)
  40. set_target_properties(
  41. libopenblas PROPERTIES IMPORTED_LOCATION ${OPENBLAS_LIB}
  42. INTERFACE_INCLUDE_DIRECTORIES ${OPENBLAS_BUILD_DIR}/include)