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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. cmake_minimum_required(VERSION 3.14.1)
  2. project (MindSpore)
  3. if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3.0)
  4. message(FATAL_ERROR "GCC vesion ${CMAKE_CXX_COMPILER_VERSION} must not be less than 7.3.0")
  5. endif ()
  6. include(${CMAKE_SOURCE_DIR}/cmake/options.cmake)
  7. include(${CMAKE_SOURCE_DIR}/cmake/check_requirements.cmake)
  8. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
  9. if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
  10. add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0)
  11. endif ()
  12. if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  13. set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O2 -Werror -Wno-return-std-move -Wno-unused-private-field -Wno-unused-lambda-capture -Wno-sign-compare -Wno-overloaded-virtual -Wno-unneeded-internal-declaration -Wno-unused-variable -Wno-pessimizing-move -Wno-inconsistent-missing-override -DHALF_ENABLE_CPP11_USER_LITERALS=0 -D_FORTIFY_SOURCE=2")
  14. else()
  15. set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O2 -Wl,--allow-shlib-undefined -DHALF_ENABLE_CPP11_USER_LITERALS=0 -D_FORTIFY_SOURCE=2")
  16. endif()
  17. if (ENABLE_PYTHON)
  18. add_compile_definitions(ENABLE_PYTHON)
  19. endif()
  20. set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -g2 -ggdb -fno-inline-functions -fno-omit-frame-pointer -Wl,--allow-shlib-undefined -D_LIBCPP_INLINE_VISIBILITY='' -D_LIBCPP_DISABLE_EXTERN_TEMPLATE=1 -DHALF_ENABLE_CPP11_USER_LITERALS=0 -D_FORTIFY_SOURCE=2 -Wno-cpp")
  21. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/local/include -std=c++17 -Werror -Wall -fPIC")
  22. set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
  23. set(PYBIND11_CPP_STANDARD -std=c++17)
  24. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPTION_CXX_FLAGS}")
  25. if (ENABLE_AKG AND (ENABLE_D OR ENABLE_GPU))
  26. add_subdirectory("${CMAKE_SOURCE_DIR}/akg")
  27. endif()
  28. include(${CMAKE_SOURCE_DIR}/cmake/mind_expression.cmake)
  29. include_directories(${CMAKE_CURRENT_SOURCE_DIR})
  30. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/securec/include)
  31. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/flatbuffers/include)
  32. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/flatbuffers/include/flatbuffers)
  33. include(${CMAKE_SOURCE_DIR}/cmake/dependency_utils.cmake)
  34. find_package(Python3 3.7 COMPONENTS Interpreter Development)
  35. if(Python3_FOUND)
  36. set(PYTHON_INCLUDE_DIRS "${Python3_INCLUDE_DIRS}")
  37. set(PYTHON_LIBRARIES "${Python3_LIBRARIES}")
  38. if (WIN32)
  39. if (Python3_DIR)
  40. message("Python3_DIR set already: " ${Python3_DIR})
  41. else()
  42. string(LENGTH ${PYTHON_LIBRARIES} PYTHON_LIBRARIES_LEN)
  43. string(LENGTH "libpythonxx.a" Python3_NAME_LEN)
  44. math(EXPR Python3_DIR_LEN ${PYTHON_LIBRARIES_LEN}-${Python3_NAME_LEN})
  45. string(SUBSTRING ${Python3_LIBRARIES} 0 ${Python3_DIR_LEN} Python3_DIR)
  46. message("Python3_DIR: " ${Python3_DIR})
  47. endif()
  48. link_directories(${Python3_DIR})
  49. endif()
  50. else()
  51. find_python_package(py_inc py_lib)
  52. set(PYTHON_INCLUDE_DIRS "${py_inc}")
  53. set(PYTHON_LIBRARIES "${py_lib}")
  54. endif()
  55. message("PYTHON_INCLUDE_DIRS = ${PYTHON_INCLUDE_DIRS}")
  56. message("PYTHON_LIBRARIES = ${PYTHON_LIBRARIES}")
  57. include_directories(${PYTHON_INCLUDE_DIRS})
  58. set(MS_CCSRC_PATH ${CMAKE_SOURCE_DIR}/mindspore/ccsrc)
  59. set(MS_CCSRC_BUILD_PATH ${BUILD_PATH}/mindspore/mindspore/ccsrc)
  60. if (ENABLE_GE)
  61. link_directories(${CMAKE_SOURCE_DIR}/third_party/ge/lib)
  62. elseif(ENABLE_D OR ENABLE_TESTCASES)
  63. include(${CMAKE_SOURCE_DIR}/cmake/dependency_graphengine.cmake)
  64. endif()
  65. if (ENABLE_GE OR ENABLE_D OR ENABLE_TESTCASES)
  66. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/graphengine/inc)
  67. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/graphengine/inc/external)
  68. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/graphengine/inc/framework)
  69. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/graphengine/third_party/fwkacllib/inc)
  70. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/graphengine/third_party/fwkacllib/inc/toolchain)
  71. endif()
  72. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
  73. add_subdirectory(mindspore/ccsrc)
  74. add_subdirectory(mindspore/core)
  75. if (ENABLE_TESTCASES)
  76. add_subdirectory(tests)
  77. endif()
  78. if (ENABLE_SERVING)
  79. add_subdirectory(serving)
  80. add_subdirectory(serving/example/cpp_client)
  81. endif()
  82. include(cmake/package.cmake)