• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1cmake_minimum_required(VERSION 3.14.0)
2project(MindSpore)
3
4if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
5    if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3.0)
6        message(FATAL_ERROR "GCC version ${CMAKE_CXX_COMPILER_VERSION} must not be less than 7.3.0")
7    elseif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.3.0)
8        message(WARNING "GCC version ${CMAKE_CXX_COMPILER_VERSION} is greater than 7.3.0, may cause unknown problems.")
9    endif()
10endif()
11
12include(${CMAKE_SOURCE_DIR}/cmake/options.cmake)
13include(${CMAKE_SOURCE_DIR}/cmake/check_requirements.cmake)
14set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
15if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
16    if(NOT ENABLE_GLIBCXX)
17        add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0)
18    endif()
19endif()
20
21if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
22    set(CMAKE_OSX_SYSROOT "")
23    set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O2 -Winconsistent-missing-override -Wuser-defined-warnings \
24        -Wno-return-std-move -Wno-unused-private-field -Wno-unused-lambda-capture -Wno-sign-compare \
25        -Wno-overloaded-virtual -Wno-unneeded-internal-declaration -Wno-unused-variable -Wno-pessimizing-move \
26        -Wno-inconsistent-missing-override -DHALF_ENABLE_CPP11_USER_LITERALS=0 -D_FORTIFY_SOURCE=2")
27elseif(ENABLE_SYM_FILE)
28    set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O2 -g -ggdb -Wl,--allow-shlib-undefined \
29        -DHALF_ENABLE_CPP11_USER_LITERALS=0 -D_FORTIFY_SOURCE=2")
30else()
31    set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O2 -Wl,--allow-shlib-undefined \
32        -DHALF_ENABLE_CPP11_USER_LITERALS=0 -D_FORTIFY_SOURCE=2")
33endif()
34
35if(ENABLE_PYTHON)
36    add_compile_definitions(ENABLE_PYTHON)
37endif()
38
39set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -g2 -ggdb -fno-inline-functions -fno-omit-frame-pointer \
40    -Wl,--allow-shlib-undefined -D_LIBCPP_INLINE_VISIBILITY='' -D_LIBCPP_DISABLE_EXTERN_TEMPLATE=1 \
41    -DHALF_ENABLE_CPP11_USER_LITERALS=0 -D_FORTIFY_SOURCE=2 -Wno-cpp")
42
43set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/local/include -std=c++17 \
44    -Werror -Wall -Wno-deprecated-declarations -fPIC")
45set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
46
47set(PYBIND11_CPP_STANDARD -std=c++17)
48set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPTION_CXX_FLAGS}")
49
50if(ENABLE_AKG AND (ENABLE_D OR ENABLE_GPU))
51    add_subdirectory("${CMAKE_SOURCE_DIR}/akg")
52endif()
53
54include(${CMAKE_SOURCE_DIR}/cmake/mind_expression.cmake)
55include_directories(${CMAKE_CURRENT_SOURCE_DIR})
56include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/securec/include)
57include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/flatbuffers/include)
58include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/flatbuffers/include/flatbuffers)
59
60include(${CMAKE_SOURCE_DIR}/cmake/dependency_utils.cmake)
61find_package(Python3 COMPONENTS Interpreter Development)
62if(Python3_FOUND)
63    set(PYTHON_INCLUDE_DIRS "${Python3_INCLUDE_DIRS}")
64    set(PYTHON_LIBRARIES "${Python3_LIBRARIES}")
65    if(WIN32)
66        if(Python3_DIR)
67            message("Python3_DIR set already: " ${Python3_DIR})
68        else()
69            string(LENGTH ${PYTHON_LIBRARIES} PYTHON_LIBRARIES_LEN)
70            string(LENGTH "libpythonxx.a" Python3_NAME_LEN)
71            math(EXPR Python3_DIR_LEN  ${PYTHON_LIBRARIES_LEN}-${Python3_NAME_LEN})
72            string(SUBSTRING ${Python3_LIBRARIES} 0 ${Python3_DIR_LEN} Python3_DIR)
73            message("Python3_DIR: " ${Python3_DIR})
74        endif()
75        link_directories(${Python3_DIR})
76    endif()
77else()
78    find_python_package(py_inc py_lib)
79    set(PYTHON_INCLUDE_DIRS "${py_inc}")
80    set(PYTHON_LIBRARIES "${py_lib}")
81endif()
82message("PYTHON_INCLUDE_DIRS = ${PYTHON_INCLUDE_DIRS}")
83message("PYTHON_LIBRARIES = ${PYTHON_LIBRARIES}")
84include_directories(${PYTHON_INCLUDE_DIRS})
85
86set(MS_CCSRC_PATH ${CMAKE_SOURCE_DIR}/mindspore/ccsrc)
87set(MS_CCSRC_BUILD_PATH ${BUILD_PATH}/mindspore/mindspore/ccsrc)
88
89if(ENABLE_D OR ENABLE_ACL OR ENABLE_TESTCASES)
90    include(${CMAKE_SOURCE_DIR}/cmake/dependency_graphengine.cmake)
91endif()
92
93set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
94add_subdirectory(mindspore/ccsrc)
95add_subdirectory(mindspore/core)
96if(ENABLE_TESTCASES OR ENABLE_CPP_ST)
97    add_subdirectory(tests)
98endif()
99
100if(MODE_ASCEND_ACL)
101    include(cmake/package_tar.cmake)
102elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
103    include(cmake/package_win.cmake)
104else()
105    include(cmake/package.cmake)
106endif()
107