diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 82bfedb93d..179689b774 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -538,7 +538,7 @@ if (MSVC) set(CMAKE_ASM_MASM_FLAGS "${CMAKE_ASM_MASM_FLAGS} /safeseh") endif() endif() - + #Always enable exception handling, even for Windows ARM if(NOT onnxruntime_DISABLE_EXCEPTIONS) @@ -831,7 +831,13 @@ get_filename_component(ORTTRAINING_ROOT "${ORTTRAINING_ROOT}" ABSOLUTE) get_filename_component(REPO_ROOT "${REPO_ROOT}" ABSOLUTE) set(ONNXRUNTIME_INCLUDE_DIR ${REPO_ROOT}/include/onnxruntime) -add_subdirectory(external/date EXCLUDE_FROM_ALL) +if(onnxruntime_PREFER_SYSTEM_LIB) + find_package(date) + add_library(date_interface ALIAS date::date) +endif() +if(NOT TARGET date::date) + add_subdirectory(external/date EXCLUDE_FROM_ALL) +endif() set(SAFEINT_INCLUDE_DIR ${REPO_ROOT}/cmake/external/SafeInt) add_library(safeint_interface INTERFACE) @@ -842,7 +848,12 @@ if(onnxruntime_DISABLE_EXCEPTIONS) add_compile_definitions(optional_CONFIG_NO_EXCEPTIONS=1) endif() -add_subdirectory(external/mp11 EXCLUDE_FROM_ALL) +if(onnxruntime_PREFER_SYSTEM_LIB) + find_package(boost_mp11) +endif() +if(NOT TARGET Boost::mp11) + add_subdirectory(external/mp11 EXCLUDE_FROM_ALL) +endif() set(JSON_BuildTests OFF CACHE INTERNAL "") set(JSON_Install OFF CACHE INTERNAL "") @@ -883,12 +894,12 @@ else() elseif(WINDOWS_STORE OR (WIN32 AND NOT CMAKE_CXX_STANDARD_LIBRARIES MATCHES kernel32.lib)) message(WARNING "Cpuinfo not included in Windows Store or WCOS builds") set(CPUINFO_SUPPORTED FALSE) - endif() + endif() elseif(NOT ${onnxruntime_target_platform} MATCHES "^(i[3-6]86|AMD64|x86(_64)?|armv[5-8].*|aarch64|arm64)$") message(WARNING "Target processor architecture \"${onnxruntime_target_platform}\" is not supported in cpuinfo. " "cpuinfo not included.") - set(CPUINFO_SUPPORTED FALSE) + set(CPUINFO_SUPPORTED FALSE) endif() endif() @@ -905,7 +916,7 @@ if(CPUINFO_SUPPORTED) set(IOS ON CACHE INTERNAL "") set(IOS_ARCH "${CMAKE_OSX_ARCHITECTURES}" CACHE INTERNAL "") endif() - + string(APPEND CMAKE_CXX_FLAGS " -DCPUINFO_SUPPORTED") add_subdirectory(external/pytorch_cpuinfo EXCLUDE_FROM_ALL) if(MSVC) @@ -1412,7 +1423,13 @@ set(FLATBUFFERS_INSTALL OFF CACHE BOOL "FLATBUFFERS_INSTALL" FORCE) set(FLATBUFFERS_BUILD_FLATHASH OFF CACHE BOOL "FLATBUFFERS_BUILD_FLATHASH" FORCE) set(FLATBUFFERS_BUILD_FLATLIB ON CACHE BOOL "FLATBUFFERS_BUILD_FLATLIB" FORCE) set_msvc_c_cpp_compiler_warning_level(4) -add_subdirectory(external/flatbuffers EXCLUDE_FROM_ALL) +if(onnxruntime_PREFER_SYSTEM_LIB) + find_package(Flatbuffers) + add_library(flatbuffers ALIAS flatbuffers::flatbuffers) +endif() +if(NOT TARGET flatbuffers::flatbuffers) + add_subdirectory(external/flatbuffers EXCLUDE_FROM_ALL) +endif() set_msvc_c_cpp_compiler_warning_level(3) list(APPEND onnxruntime_EXTERNAL_DEPENDENCIES flatbuffers) list(APPEND onnxruntime_EXTERNAL_LIBRARIES flatbuffers)