From bd5451b4ed9c86f30556ed6514bf0bc4c1948a76 Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Fri, 13 Sep 2019 16:42:50 -0700 Subject: [PATCH] Don't define USE_OPENMP if the compiler doesn't support OpenMP (#1836) --- cmake/CMakeLists.txt | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 04ac0cb65a..bb7a0096fc 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -87,14 +87,22 @@ set(NSYNC_ENABLE_TESTS OFF CACHE BOOL "Build protobuf tests" FORCE) set(ONNX_ML 1) if(onnxruntime_USE_OPENMP) - # MKLML and NGraph depend on their own OpenMP library that may be different with the compiler's. - # Disable the options to build mklml/NGraph and OpenMP together. - if(onnxruntime_USE_MKLML) - message(FATAL_ERROR "Please use only one of onnxruntime_USE_MKLML, onnxruntime_USE_OPENMP") - endif() - if(onnxruntime_USE_NGRAPH) - message(FATAL_ERROR "Please use only one of onnxruntime_USE_NGRAPH, onnxruntime_USE_OPENMP") - endif() + find_package(OpenMP) + if (OPENMP_FOUND) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") + add_definitions(-DUSE_OPENMP) + # MKLML and NGraph depend on their own OpenMP library that may be different with the compiler's. + # Disable the options to build mklml/NGraph and OpenMP together. + if(onnxruntime_USE_MKLML) + message(FATAL_ERROR "Please use only one of onnxruntime_USE_MKLML, onnxruntime_USE_OPENMP") + endif() + if(onnxruntime_USE_NGRAPH) + message(FATAL_ERROR "Please use only one of onnxruntime_USE_NGRAPH, onnxruntime_USE_OPENMP") + endif() + else() + set(onnxruntime_USE_OPENMP OFF) + endif() endif() if(onnxruntime_ENABLE_LTO) #TODO: figure out why nsync doesn't work @@ -116,15 +124,6 @@ set(REPO_ROOT ${PROJECT_SOURCE_DIR}/..) set(ONNXRUNTIME_ROOT ${PROJECT_SOURCE_DIR}/../onnxruntime) file (STRINGS "${REPO_ROOT}/VERSION_NUMBER" ORT_VERSION) -if(onnxruntime_USE_OPENMP) - find_package(OpenMP) - if (OPENMP_FOUND) - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") - add_definitions(-DUSE_OPENMP) - endif() -endif() - # Guarantee that the Eigen code that you are #including is licensed # under the MPL2 and possibly more permissive licenses (like BSD). add_definitions(-DEIGEN_MPL2_ONLY)