-
Notifications
You must be signed in to change notification settings - Fork 709
/
CMakeLists.txt
173 lines (151 loc) · 6.39 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
cmake_minimum_required(VERSION 3.14.0)
project(MindSpore)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3.0)
message(FATAL_ERROR "GCC version must be 7.3.0 and above, but found ${CMAKE_CXX_COMPILER_VERSION}")
elseif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11.3.0)
message(WARNING "GCC version ${CMAKE_CXX_COMPILER_VERSION} is greater than 11.3.0, may cause unknown problems.")
endif()
endif()
include(${CMAKE_SOURCE_DIR}/cmake/options.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/check_requirements.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/ascend_variables.cmake)
#generate code
if(DEFINED ENV{ENABLE_GEN_CODE})
set(ENABLE_GEN_CODE $ENV{ENABLE_GEN_CODE})
endif()
set(ENABLE_GEN_CODE on)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_GEN_CODE")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
if(NOT ENABLE_GLIBCXX)
add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0)
endif()
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(MACOSX_CXX_WARNING_FLAGS "-Wno-inconsistent-missing-override \
-Wno-unused-lambda-capture -Wno-unneeded-internal-declaration -Wno-unused-variable \
-Wno-return-std-move")
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 13.1)
set(MACOSX_CXX_WARNING_FLAGS "${MACOSX_CXX_WARNING_FLAGS} -Wno-unused-but-set-variable")
endif()
set(CMAKE_CXX_FLAGS_RELEASE
"$ENV{CXXFLAGS} -O2 ${MACOSX_CXX_WARNING_FLAGS} -DHALF_ENABLE_CPP11_USER_LITERALS=0 -D_FORTIFY_SOURCE=2")
elseif(ENABLE_SYM_FILE)
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O2 -g -ggdb -Wl,--build-id=uuid -Wl,--allow-shlib-undefined \
-DHALF_ENABLE_CPP11_USER_LITERALS=0 -D_FORTIFY_SOURCE=2")
else()
if(NOT MSVC)
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O2 -Wl,--allow-shlib-undefined -s \
-DHALF_ENABLE_CPP11_USER_LITERALS=0 -D_FORTIFY_SOURCE=2")
endif()
endif()
if(ENABLE_PYTHON)
add_compile_definitions(ENABLE_PYTHON)
add_compile_definitions(ENABLE_MINDDATA_PYTHON)
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -g2 -ggdb -fno-inline-functions -fno-omit-frame-pointer \
-D_LIBCPP_INLINE_VISIBILITY='' -D_LIBCPP_DISABLE_EXTERN_TEMPLATE=1 -DHALF_ENABLE_CPP11_USER_LITERALS=0 \
-D_FORTIFY_SOURCE=2 -Wno-cpp ${MACOSX_CXX_WARNING_FLAGS}")
else()
if(NOT MSVC)
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")
endif()
endif()
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/local/include -std=c++17 \
-Werror -Wall -Wno-deprecated-declarations -fPIC")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(PYBIND11_CPP_STANDARD -std=c++17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPTION_CXX_FLAGS}")
if(ENABLE_AKG AND CMAKE_SYSTEM_NAME MATCHES "Linux")
add_subdirectory("${CMAKE_SOURCE_DIR}/akg")
endif()
include(${CMAKE_SOURCE_DIR}/cmake/mind_expression.cmake)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/securec/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/flatbuffers/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/flatbuffers/include/flatbuffers)
if(MSVC AND NOT ENABLE_GPU)
find_program(CCACHE_EXE ccache)
if(CCACHE_EXE)
message(STATUS "using ccache to speed windows compilation.")
file(COPY ${CCACHE_EXE} DESTINATION ${CMAKE_BINARY_DIR}/cl.exe)
set(CMAKE_VS_GLOBALS
"CLToolExe=cl.exe"
"CLToolPath=${CMAKE_BINARY_DIR}"
"TrackFileAccess=false"
"UseMultiToolTask=true"
"DebugInformationFormat=OldStyle"
)
endif()
endif()
if(ENABLE_FAST_HASH_TABLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_FAST_HASH_TABLE=1")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/robin_hood/include)
endif()
include(${CMAKE_SOURCE_DIR}/cmake/dependency_utils.cmake)
find_package(Python3 COMPONENTS Interpreter Development)
if(Python3_FOUND)
set(PYTHON_INCLUDE_DIRS "${Python3_INCLUDE_DIRS}")
set(PYTHON_LIBRARIES "${Python3_LIBRARIES}")
if(WIN32)
if(Python3_DIR)
message("Python3_DIR set already: " ${Python3_DIR})
else()
string(LENGTH ${PYTHON_LIBRARIES} PYTHON_LIBRARIES_LEN)
string(LENGTH "libpythonxx.a" Python3_NAME_LEN)
math(EXPR Python3_DIR_LEN ${PYTHON_LIBRARIES_LEN}-${Python3_NAME_LEN})
string(SUBSTRING ${Python3_LIBRARIES} 0 ${Python3_DIR_LEN} Python3_DIR)
message("Python3_DIR: " ${Python3_DIR})
endif()
link_directories(${Python3_DIR})
endif()
else()
find_python_package(py_inc py_lib)
set(PYTHON_INCLUDE_DIRS "${py_inc}")
set(PYTHON_LIBRARIES "${py_lib}")
endif()
message("PYTHON_INCLUDE_DIRS = ${PYTHON_INCLUDE_DIRS}")
message("PYTHON_LIBRARIES = ${PYTHON_LIBRARIES}")
include_directories(${PYTHON_INCLUDE_DIRS})
include(${CMAKE_SOURCE_DIR}/cmake/utils.cmake)
find_and_use_mold()
set(MS_CCSRC_PATH ${CMAKE_SOURCE_DIR}/mindspore/ccsrc)
set(MS_CCSRC_BUILD_PATH ${BUILD_PATH}/mindspore/mindspore/ccsrc)
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
endif()
include(${CMAKE_SOURCE_DIR}/cmake/init.cmake)
add_subdirectory(mindspore/core)
if(ENABLE_D OR ENABLE_ACL OR ENABLE_TESTCASES)
include(${CMAKE_SOURCE_DIR}/cmake/dependency_graphengine.cmake)
endif()
add_subdirectory_with_faster_option(mindspore/ccsrc)
if(ENABLE_TESTCASES OR ENABLE_CPP_ST)
add_subdirectory(tests)
endif()
# packaging
file(READ ${CMAKE_SOURCE_DIR}/version.txt VERSION_NUMBER)
string(REPLACE "\n" "" VERSION_NUMBER ${VERSION_NUMBER})
if(${VERSION_NUMBER} MATCHES ".*dev.*")
message("building dev mode")
set(BUILD_DEV_MODE ON)
endif()
if(ONLY_BUILD_DEVICE_PLUGINS)
include(cmake/package_plugin.cmake)
elseif(MODE_ASCEND_ACL)
include(cmake/package_tar.cmake)
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
include(cmake/package_win.cmake)
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
include(cmake/package_mac.cmake)
else()
include(cmake/package.cmake)
endif()