2021-02-05 11:54:29 +08:00
|
|
|
cmake_minimum_required(VERSION 3.14.0)
|
2021-01-23 20:20:31 +08:00
|
|
|
project(MindSpore)
|
2020-04-26 11:02:20 +08:00
|
|
|
|
2021-06-22 17:14:46 +08:00
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
|
|
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3.0)
|
|
|
|
message(FATAL_ERROR "GCC version ${CMAKE_CXX_COMPILER_VERSION} must not be less than 7.3.0")
|
|
|
|
elseif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.3.0)
|
|
|
|
message(WARNING "GCC version ${CMAKE_CXX_COMPILER_VERSION} is greater than 7.3.0, may cause unknown problems.")
|
|
|
|
endif()
|
2021-01-23 20:20:31 +08:00
|
|
|
endif()
|
2020-04-26 11:02:20 +08:00
|
|
|
|
2020-03-27 14:49:12 +08:00
|
|
|
include(${CMAKE_SOURCE_DIR}/cmake/options.cmake)
|
2020-09-11 15:07:17 +08:00
|
|
|
include(${CMAKE_SOURCE_DIR}/cmake/check_requirements.cmake)
|
2020-03-27 14:49:12 +08:00
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
|
2021-01-23 20:20:31 +08:00
|
|
|
if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
|
2021-03-20 19:56:45 +08:00
|
|
|
if(NOT ENABLE_GLIBCXX)
|
|
|
|
add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0)
|
|
|
|
endif()
|
2021-01-23 20:20:31 +08:00
|
|
|
endif()
|
2020-03-27 14:49:12 +08:00
|
|
|
|
2021-01-23 20:20:31 +08:00
|
|
|
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
2021-11-30 19:10:40 +08:00
|
|
|
exec_program(sw_vers ARGS -productVersion OUTPUT_VARIABLE MACOSX_SYSTEM_VERSION)
|
|
|
|
if(NOT DEFINED ENV{MACOSX_DEPLOYMENT_TARGET})
|
|
|
|
set(CMAKE_OSX_DEPLOYMENT_TARGET ${MACOSX_SYSTEM_VERSION} CACHE STRING
|
|
|
|
"minimum macosx deployment target version" FORCE)
|
|
|
|
endif()
|
|
|
|
message("macosx deployment target version: ${CMAKE_OSX_DEPLOYMENT_TARGET}")
|
2021-11-25 10:38:43 +08:00
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O2 -Winconsistent-missing-override -Wno-user-defined-warnings \
|
2021-02-05 11:54:29 +08:00
|
|
|
-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")
|
2021-08-22 16:26:45 +08:00
|
|
|
elseif(ENABLE_SYM_FILE)
|
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O2 -g -ggdb -Wl,--allow-shlib-undefined \
|
|
|
|
-DHALF_ENABLE_CPP11_USER_LITERALS=0 -D_FORTIFY_SOURCE=2")
|
2020-04-13 19:42:12 +08:00
|
|
|
else()
|
2021-02-05 11:54:29 +08:00
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O2 -Wl,--allow-shlib-undefined \
|
|
|
|
-DHALF_ENABLE_CPP11_USER_LITERALS=0 -D_FORTIFY_SOURCE=2")
|
2020-04-13 19:42:12 +08:00
|
|
|
endif()
|
|
|
|
|
2021-01-23 20:20:31 +08:00
|
|
|
if(ENABLE_PYTHON)
|
2020-07-11 04:26:00 +08:00
|
|
|
add_compile_definitions(ENABLE_PYTHON)
|
|
|
|
endif()
|
|
|
|
|
2021-02-05 11:54:29 +08:00
|
|
|
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")
|
2020-04-15 17:36:48 +08:00
|
|
|
|
2021-02-05 11:54:29 +08:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/local/include -std=c++17 \
|
|
|
|
-Werror -Wall -Wno-deprecated-declarations -fPIC")
|
2020-03-27 14:49:12 +08:00
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
|
|
|
|
set(PYBIND11_CPP_STANDARD -std=c++17)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPTION_CXX_FLAGS}")
|
|
|
|
|
2021-09-23 16:27:06 +08:00
|
|
|
if(ENABLE_AKG AND CMAKE_SYSTEM_NAME MATCHES "Linux")
|
2020-06-08 15:31:37 +08:00
|
|
|
add_subdirectory("${CMAKE_SOURCE_DIR}/akg")
|
|
|
|
endif()
|
|
|
|
|
2020-03-27 14:49:12 +08:00
|
|
|
include(${CMAKE_SOURCE_DIR}/cmake/mind_expression.cmake)
|
|
|
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
2020-08-28 15:45:28 +08:00
|
|
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/securec/include)
|
2020-03-27 14:49:12 +08:00
|
|
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/flatbuffers/include)
|
|
|
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/flatbuffers/include/flatbuffers)
|
|
|
|
|
2021-11-24 08:51:27 +08:00
|
|
|
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()
|
|
|
|
|
2020-03-27 14:49:12 +08:00
|
|
|
include(${CMAKE_SOURCE_DIR}/cmake/dependency_utils.cmake)
|
2021-03-04 10:50:37 +08:00
|
|
|
find_package(Python3 COMPONENTS Interpreter Development)
|
2020-03-27 14:49:12 +08:00
|
|
|
if(Python3_FOUND)
|
|
|
|
set(PYTHON_INCLUDE_DIRS "${Python3_INCLUDE_DIRS}")
|
|
|
|
set(PYTHON_LIBRARIES "${Python3_LIBRARIES}")
|
2021-01-23 20:20:31 +08:00
|
|
|
if(WIN32)
|
|
|
|
if(Python3_DIR)
|
2020-04-15 17:36:48 +08:00
|
|
|
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()
|
2020-03-27 14:49:12 +08:00
|
|
|
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})
|
|
|
|
|
|
|
|
set(MS_CCSRC_PATH ${CMAKE_SOURCE_DIR}/mindspore/ccsrc)
|
|
|
|
set(MS_CCSRC_BUILD_PATH ${BUILD_PATH}/mindspore/mindspore/ccsrc)
|
|
|
|
|
2021-01-23 20:20:31 +08:00
|
|
|
if(ENABLE_D OR ENABLE_ACL OR ENABLE_TESTCASES)
|
2021-01-07 09:14:54 +08:00
|
|
|
include(${CMAKE_SOURCE_DIR}/cmake/dependency_graphengine.cmake)
|
2021-01-23 20:20:31 +08:00
|
|
|
endif()
|
2020-03-27 14:49:12 +08:00
|
|
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
|
|
|
|
add_subdirectory(mindspore/ccsrc)
|
2020-08-05 16:27:05 +08:00
|
|
|
add_subdirectory(mindspore/core)
|
2021-01-23 20:20:31 +08:00
|
|
|
if(ENABLE_TESTCASES OR ENABLE_CPP_ST)
|
2020-03-27 14:49:12 +08:00
|
|
|
add_subdirectory(tests)
|
|
|
|
endif()
|
2020-04-13 15:30:25 +08:00
|
|
|
|
2021-11-06 16:56:44 +08:00
|
|
|
# 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()
|
2021-05-26 11:31:02 +08:00
|
|
|
if(MODE_ASCEND_ACL)
|
2021-06-26 09:41:46 +08:00
|
|
|
include(cmake/package_tar.cmake)
|
|
|
|
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
|
|
|
|
include(cmake/package_win.cmake)
|
2021-10-25 16:59:19 +08:00
|
|
|
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
|
|
|
|
include(cmake/package_mac.cmake)
|
2021-05-26 11:31:02 +08:00
|
|
|
else()
|
|
|
|
include(cmake/package.cmake)
|
|
|
|
endif()
|