From 0bd4c218d456fba1212174b6c2d90e2e93101061 Mon Sep 17 00:00:00 2001 From: yanghaoran Date: Fri, 11 Sep 2020 15:07:17 +0800 Subject: [PATCH] cmake check if required packages exist --- CMakeLists.txt | 14 +------ cmake/check_requirements.cmake | 68 ++++++++++++++++++++++++++++++++++ cmake/mind_expression.cmake | 9 +---- cmake/options.cmake | 7 ++++ 4 files changed, 77 insertions(+), 21 deletions(-) create mode 100644 cmake/check_requirements.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e0c9d413f1..aad9c5dd54e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_ endif () include(${CMAKE_SOURCE_DIR}/cmake/options.cmake) +include(${CMAKE_SOURCE_DIR}/cmake/check_requirements.cmake) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/") if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows") add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0) @@ -29,19 +30,6 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(PYBIND11_CPP_STANDARD -std=c++17) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPTION_CXX_FLAGS}") -find_package(Threads) -if (DEFINED ENV{MS_PATCH_PATH}) - find_program(Patch_EXECUTABLE patch PATHS $ENV{MS_PATCH_PATH}) - set(Patch_FOUND ${Patch_EXECUTABLE}) -else () - find_package(Patch) -endif () -if (NOT Patch_FOUND) - message(FATAL_ERROR "Patch not found, please set env variable MS_PATCH_PATH, " - "usually locate in GIT_PATH/usr/bin in windows") -endif () -message(PATCH_EXECUTABLE = ${Patch_EXECUTABLE}) - if (ENABLE_AKG AND (ENABLE_D OR ENABLE_GPU)) add_subdirectory("${CMAKE_SOURCE_DIR}/akg") endif() diff --git a/cmake/check_requirements.cmake b/cmake/check_requirements.cmake new file mode 100644 index 00000000000..2aadd6fb3ba --- /dev/null +++ b/cmake/check_requirements.cmake @@ -0,0 +1,68 @@ +## define customized find fucntions, print customized error messages +function(find_required_package pkg_name) + find_package(${pkg_name}) + if (NOT ${pkg_name}_FOUND) + message(FATAL_ERROR "Required package ${pkg_name} not found, please install the package and try building MindSpore again.") + endif() +endfunction() + +function(find_required_program prog_name) + find_program(${prog_name}_EXE ${prog_name}) + if (NOT ${prog_name}_EXE) + message(FATAL_ERROR "Required program ${prog_name} not found, please install the package and try building MindSpore again.") + endif () +endfunction() + + +## find python, quit if the found python is static +set(Python3_USE_STATIC_LIBS FALSE) +find_package(Python3 COMPONENTS Interpreter Development) +if (Python3_FOUND) + message("Python3 found, version: ${Python3_VERSION}") + message("Python3 library path: ${Python3_LIBRARY_DIRS}") + message("Python3 interpreter: ${Python3_EXECUTABLE}") + else() + message(FATAL_ERROR "Python3 not found, please install Python>=3.7.5, and set --enable-shared " + "if you are building Python locally") +endif () + +## packages used both on windows and linux +if (DEFINED ENV{MS_PATCH_PATH}) + find_program(Patch_EXECUTABLE patch PATHS $ENV{MS_PATCH_PATH}) + set(Patch_FOUND ${Patch_EXECUTABLE}) +else () + find_package(Patch) +endif () +if (NOT Patch_FOUND) + message(FATAL_ERROR "Patch not found, please set environment variable MS_PATCH_PATH to path where Patch is located, " + "usually found in GIT_PATH/usr/bin on Windows") +endif () +message(PATCH_EXECUTABLE = ${Patch_EXECUTABLE}) + +find_required_package(Threads) + + +## packages used on Linux +if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows") + if (ENABLE_MINDDATA) + find_required_program(tclsh) + endif () + + if (MS_BUILD_GRPC) + find_required_package(OpenSSL) + endif () + + ## packages used in GPU mode only + if (ENABLE_GPU) + find_library(gmp_LIB gmp) + find_library(gmpxx_LIB gmpxx) + find_file(gmp_HEADER gmp.h) + if (NOT gmp_LIB OR NOT gmpxx_LIB OR NOT gmp_HEADER) + message(FATAL_ERROR "Required package gmp not found, please install gmp and try building MindSpore again.") + endif () + find_required_program(automake) + find_required_program(autoconf) + find_required_program(libtoolize) + find_required_package(FLEX) + endif() +endif() diff --git a/cmake/mind_expression.cmake b/cmake/mind_expression.cmake index 80efb02b964..87d082c81fd 100644 --- a/cmake/mind_expression.cmake +++ b/cmake/mind_expression.cmake @@ -15,14 +15,7 @@ include(${CMAKE_SOURCE_DIR}/cmake/external_libs/json.cmake) include(${CMAKE_SOURCE_DIR}/cmake/dependency_securec.cmake) include(${CMAKE_SOURCE_DIR}/cmake/external_libs/protobuf.cmake) -SET(MS_BUILD_GRPC 0) -if (ENABLE_DEBUGGER OR ENABLE_SERVING OR ENABLE_TESTCASES) - SET(MS_BUILD_GRPC 1) -endif() -if (ENABLE_MINDDATA AND NOT CMAKE_SYSTEM_NAME MATCHES "Windows") - SET(MS_BUILD_GRPC 1) -endif() -if ("${MS_BUILD_GRPC}") +if (MS_BUILD_GRPC) # build dependencies of gRPC include(${CMAKE_SOURCE_DIR}/cmake/external_libs/absl.cmake) include(${CMAKE_SOURCE_DIR}/cmake/external_libs/c-ares.cmake) diff --git a/cmake/options.cmake b/cmake/options.cmake index a9ccc80feb5..7f746860242 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -123,3 +123,10 @@ endif() if(ENABLE_DEBUGGER) add_compile_definitions(ENABLE_DEBUGGER) endif() + +if (ENABLE_DEBUGGER OR ENABLE_SERVING OR ENABLE_TESTCASES) + set(MS_BUILD_GRPC ON) +endif() +if (ENABLE_MINDDATA AND NOT CMAKE_SYSTEM_NAME MATCHES "Windows") + set(MS_BUILD_GRPC ON) +endif()