Skip to content

Commit 18491b8

Browse files
committed
update
1 parent 7f1e880 commit 18491b8

File tree

90 files changed

+2098
-1482
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+2098
-1482
lines changed

cmake/CMakeLists.txt

Lines changed: 83 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ option(onnxruntime_USE_NUPHAR "Build with Nuphar" OFF)
7575
option(onnxruntime_USE_VITISAI "Build with Vitis-AI" OFF)
7676
option(onnxruntime_USE_TENSORRT "Build with TensorRT support" OFF)
7777
option(onnxruntime_ENABLE_LTO "Enable link time optimization" OFF)
78-
option(onnxruntime_CROSS_COMPILING "Cross compiling onnx runtime" OFF)
7978
option(onnxruntime_GCOV_COVERAGE "Compile with options necessary to run code coverage" OFF)
8079

8180
#It's preferred to turn it OFF when onnxruntime is dynamically linked to PROTOBUF. But Tensort always required the full version of protobuf.
@@ -160,6 +159,14 @@ option(onnxruntime_ENABLE_EXTENSION_CUSTOM_OPS "Enable custom operators in onnxr
160159
# pre-build python path
161160
option(onnxruntime_PREBUILT_PYTORCH_PATH "Path to pytorch installation dir")
162161

162+
if(APPLE)
163+
if(NOT CMAKE_OSX_ARCHITECTURES)
164+
message("Building ONNX Runtime for ${CMAKE_HOST_SYSTEM_PROCESSOR}")
165+
endif()
166+
elseif(NOT WIN32 AND NOT APPLE)
167+
message("Building ONNX Runtime for ${CMAKE_SYSTEM_PROCESSOR}")
168+
endif()
169+
163170
# Single output director for all binaries
164171
set (RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin CACHE PATH "Single output directory for all binaries.")
165172

@@ -461,15 +468,6 @@ if(MSVC)
461468
-DEIGEN_STRONG_INLINE=inline)
462469
endif()
463470

464-
if(onnxruntime_CROSS_COMPILING)
465-
set(CMAKE_CROSSCOMPILING ON)
466-
check_cxx_compiler_flag(-Wno-error HAS_NOERROR)
467-
if(HAS_NOERROR)
468-
string(APPEND CMAKE_CXX_FLAGS " -Wno-error=attributes")
469-
string(APPEND CMAKE_C_FLAGS " -Wno-error=attributes")
470-
endif()
471-
endif()
472-
473471
# Mark symbols to be invisible, for macOS/iOS target only
474472
# Due to many dependencies have different symbol visibility settings, set global compile flags here.
475473
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS")
@@ -495,6 +493,30 @@ endmacro()
495493
#Set global compile flags for all the source code(including third_party code like protobuf)
496494
#This section must be before any add_subdirectory, otherwise build may fail because /MD,/MT mismatch
497495
if (MSVC)
496+
enable_language(ASM_MASM)
497+
if(CMAKE_GENERATOR_PLATFORM)
498+
# Multi-platform generator
499+
set(onnxruntime_target_platform ${CMAKE_GENERATOR_PLATFORM})
500+
else()
501+
set(onnxruntime_target_platform ${CMAKE_SYSTEM_PROCESSOR})
502+
endif()
503+
if(onnxruntime_target_platform STREQUAL "ARM64")
504+
set(onnxruntime_target_platform "ARM64")
505+
elseif(onnxruntime_target_platform STREQUAL "ARM64EC")
506+
set(onnxruntime_target_platform "ARM64EC")
507+
elseif(onnxruntime_target_platform STREQUAL "ARM" OR CMAKE_GENERATOR MATCHES "ARM")
508+
set(onnxruntime_target_platform "ARM")
509+
elseif(onnxruntime_target_platform STREQUAL "x64" OR onnxruntime_target_platform STREQUAL "x86_64" OR onnxruntime_target_platform STREQUAL "AMD64" OR CMAKE_GENERATOR MATCHES "Win64")
510+
set(onnxruntime_target_platform "x64")
511+
elseif(onnxruntime_target_platform STREQUAL "Win32" OR onnxruntime_target_platform STREQUAL "x86" OR onnxruntime_target_platform STREQUAL "i386" OR onnxruntime_target_platform STREQUAL "i686")
512+
set(onnxruntime_target_platform "x86")
513+
if(NOT onnxruntime_BUILD_WEBASSEMBLY)
514+
message("Enabling SAFESEH for x86 build")
515+
set(CMAKE_ASM_MASM_FLAGS "${CMAKE_ASM_MASM_FLAGS} /safeseh")
516+
endif()
517+
endif()
518+
519+
498520
#Always enable exception handling, even for Windows ARM
499521
if(NOT onnxruntime_DISABLE_EXCEPTIONS)
500522
string(APPEND CMAKE_CXX_FLAGS " /EHsc")
@@ -543,6 +565,9 @@ if (MSVC)
543565
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /guard:cf")
544566
endif()
545567
else()
568+
if(NOT APPLE)
569+
set(onnxruntime_target_platform ${CMAKE_SYSTEM_PROCESSOR})
570+
endif()
546571
if(onnxruntime_BUILD_FOR_NATIVE_MACHINE)
547572
string(APPEND CMAKE_CXX_FLAGS " -march=native -mtune=native")
548573
string(APPEND CMAKE_C_FLAGS " -march=native -mtune=native")
@@ -595,16 +620,6 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
595620
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong")
596621
endif()
597622

598-
if (${CMAKE_SYSTEM_NAME} MATCHES "iOSCross")
599-
#For ios compliance
600-
message("Adding flags for ios builds")
601-
if (CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
602-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -target arm64-apple-darwin-macho")
603-
elseif (CMAKE_OSX_ARCHITECTURES STREQUAL "arm")
604-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -target armv7a-apple-darwin-macho")
605-
endif()
606-
endif()
607-
608623
#Dependencies begin
609624
if (onnxruntime_BUILD_UNIT_TESTS)
610625
if(onnxruntime_PREFER_SYSTEM_LIB)
@@ -639,10 +654,6 @@ set(ENABLE_DATE_TESTING OFF CACHE BOOL "" FORCE)
639654
set(USE_SYSTEM_TZ_DB ON CACHE BOOL "" FORCE)
640655
set(RE2_BUILD_TESTING OFF CACHE BOOL "" FORCE)
641656

642-
if(CMAKE_CROSSCOMPILING)
643-
message("Doing crosscompiling")
644-
endif()
645-
646657
#Need python to generate def file
647658
if(onnxruntime_BUILD_SHARED_LIB OR onnxruntime_ENABLE_PYTHON)
648659
if(onnxruntime_ENABLE_PYTHON)
@@ -724,6 +735,17 @@ else()
724735
endif()
725736
if(TARGET protoc)
726737
set_target_properties(protoc PROPERTIES FOLDER "External/Protobuf")
738+
get_target_property(PROTOC_OSX_ARCH protoc OSX_ARCHITECTURES)
739+
if(PROTOC_OSX_ARCH)
740+
if (${CMAKE_HOST_SYSTEM_PROCESSOR} IN_LIST PROTOC_OSX_ARCH)
741+
message("protoc can run")
742+
else()
743+
list(APPEND PROTOC_OSX_ARCH ${CMAKE_HOST_SYSTEM_PROCESSOR})
744+
set_target_properties(protoc PROPERTIES OSX_ARCHITECTURES "${CMAKE_HOST_SYSTEM_PROCESSOR}")
745+
set_target_properties(libprotoc PROPERTIES OSX_ARCHITECTURES "${PROTOC_OSX_ARCH}")
746+
set_target_properties(libprotobuf PROPERTIES OSX_ARCHITECTURES "${PROTOC_OSX_ARCH}")
747+
endif()
748+
endif()
727749
endif()
728750
if (onnxruntime_USE_FULL_PROTOBUF)
729751
set(PROTOBUF_LIB libprotobuf)
@@ -794,31 +816,35 @@ if(NOT TARGET re2::re2)
794816
set(RE2_INCLUDE_DIR ${REPO_ROOT}/cmake/external/re2)
795817
endif()
796818

819+
797820
# Adding pytorch CPU info library
798821
# TODO!! need a better way to find out the supported architectures
799-
set(TARGET_ARCH "${CMAKE_SYSTEM_PROCESSOR}")
800-
if (NOT DEFINED TARGET_ARCH OR "${TARGET_ARCH}" STREQUAL "")
801-
set(TARGET_ARCH "${CMAKE_OSX_ARCHITECTURES}")
802-
endif()
803-
804-
set(CPUINFO_SUPPORTED TRUE)
805-
if (NOT DEFINED TARGET_ARCH OR "${TARGET_ARCH}" STREQUAL "")
806-
message(WARNING
807-
"Target processor architecture is not specified. cpuinfo not included")
808-
set(CPUINFO_SUPPORTED FALSE)
809-
elseif(NOT TARGET_ARCH MATCHES "^(i[3-6]86|AMD64|x86(_64)?|armv[5-8].*|aarch64|arm64)$")
810-
message(WARNING
811-
"Target processor architecture \"${CPUINFO_TARGET_PROCESSOR}\" is not supported in cpuinfo. "
812-
"cpuinfo not included.")
813-
set(CPUINFO_SUPPORTED FALSE)
814-
elseif(MSVC AND (( CMAKE_SYSTEM_PROCESSOR MATCHES "^(ARM.*|arm.*)$" ) OR (CMAKE_GENERATOR_PLATFORM MATCHES "^(ARM.*|arm.*)$" ) ))
815-
message(WARNING
816-
"Cpuinfo not included for compilation problems with Windows ARM.")
817-
set(CPUINFO_SUPPORTED FALSE)
818-
elseif(WINDOWS_STORE)
819-
message(WARNING
820-
"Cpuinfo not included in Windows Store builds")
821-
set(CPUINFO_SUPPORTED FALSE)
822+
list(LENGTH CMAKE_OSX_ARCHITECTURES CMAKE_OSX_ARCHITECTURES_LEN)
823+
if(APPLE)
824+
if(CMAKE_OSX_ARCHITECTURES_LEN LESS_EQUAL 1)
825+
set(CPUINFO_SUPPORTED TRUE)
826+
endif()
827+
else()
828+
if(onnxruntime_BUILD_WEBASSEMBLY)
829+
set(CPUINFO_SUPPORTED FALSE)
830+
else()
831+
set(CPUINFO_SUPPORTED TRUE)
832+
endif()
833+
if(WIN32)
834+
# Exclude Windows ARM build and Windows Store
835+
if(${onnxruntime_target_platform} MATCHES "^(ARM.*|arm.*)$" )
836+
message(WARNING "Cpuinfo not included for compilation problems with Windows ARM.")
837+
set(CPUINFO_SUPPORTED FALSE)
838+
elseif(WINDOWS_STORE)
839+
message(WARNING "Cpuinfo not included in Windows Store builds")
840+
set(CPUINFO_SUPPORTED FALSE)
841+
endif()
842+
elseif(NOT ${onnxruntime_target_platform} MATCHES "^(i[3-6]86|AMD64|x86(_64)?|armv[5-8].*|aarch64|arm64)$")
843+
message(WARNING
844+
"Target processor architecture \"${onnxruntime_target_platform}\" is not supported in cpuinfo. "
845+
"cpuinfo not included.")
846+
set(CPUINFO_SUPPORTED FALSE)
847+
endif()
822848
endif()
823849

824850
# TODO do we have to add target_include_directories to each project that uses this?
@@ -828,12 +854,7 @@ if(CPUINFO_SUPPORTED)
828854
set(CPUINFO_BUILD_TOOLS OFF CACHE INTERNAL "")
829855
set(CPUINFO_BUILD_UNIT_TESTS OFF CACHE INTERNAL "")
830856
set(CPUINFO_BUILD_MOCK_TESTS OFF CACHE INTERNAL "")
831-
set(CPUINFO_BUILD_BENCHMARKS OFF CACHE INTERNAL "")
832-
833-
if (CMAKE_SYSTEM_NAME STREQUAL "iOS")
834-
set(IOS ON CACHE INTERNAL "")
835-
set(IOS_ARCH "${CMAKE_OSX_ARCHITECTURES}" CACHE INTERNAL "")
836-
endif()
857+
set(CPUINFO_BUILD_BENCHMARKS OFF CACHE INTERNAL "")
837858

838859
string(APPEND CMAKE_CXX_FLAGS " -DCPUINFO_SUPPORTED")
839860
add_subdirectory(external/pytorch_cpuinfo EXCLUDE_FROM_ALL)
@@ -1084,10 +1105,7 @@ function(onnxruntime_set_compile_flags target_name)
10841105
target_compile_options(${target_name} PRIVATE "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:--compiler-options -Werror>" "$<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:-Werror>")
10851106
endif()
10861107

1087-
target_compile_definitions(${target_name} PUBLIC -DNSYNC_ATOMIC_CPP11)
1088-
if(APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "iOSCross" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "iOS")
1089-
target_compile_definitions(${target_name} PUBLIC -Doptional_CONFIG_SELECT_OPTIONAL=optional_OPTIONAL_NONSTD)
1090-
endif()
1108+
target_compile_definitions(${target_name} PUBLIC -DNSYNC_ATOMIC_CPP11)
10911109
target_include_directories(${target_name} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/external/nsync/public")
10921110
endif()
10931111
foreach(ORT_FLAG ${ORT_PROVIDER_FLAGS})
@@ -1140,22 +1158,25 @@ endfunction()
11401158

11411159
#For plugins that are not linked into other targets but may be loaded dynamically at runtime using dlopen-like functionality.
11421160
function(onnxruntime_add_shared_library_module target_name)
1143-
if ((${CMAKE_SYSTEM_NAME} MATCHES "Darwin") OR (${CMAKE_SYSTEM_NAME} MATCHES "iOSCross") OR (${CMAKE_SYSTEM_NAME} MATCHES "iOS"))
1161+
if ((${CMAKE_SYSTEM_NAME} MATCHES "Darwin") OR (${CMAKE_SYSTEM_NAME} MATCHES "iOS"))
11441162
add_library(${target_name} SHARED ${ARGN})
11451163
else()
11461164
#On Windows, this target shouldn't generate an import lib, but I don't know how to disable it.
11471165
add_library(${target_name} MODULE ${ARGN})
11481166
endif()
11491167

11501168
onnxruntime_configure_target(${target_name})
1169+
if (onnxruntime_target_platform STREQUAL "x86" AND NOT onnxruntime_BUILD_WEBASSEMBLY)
1170+
target_link_options(${target_name} PRIVATE /SAFESEH)
1171+
endif()
11511172
endfunction()
11521173

11531174
function(onnxruntime_add_executable target_name)
1154-
if(${CMAKE_SYSTEM_NAME} MATCHES "iOSCross")
1155-
message(FATAL_ERROR "iOS doesn't support commmand line tool")
1156-
endif()
11571175
add_executable(${target_name} ${ARGN})
11581176
onnxruntime_configure_target(${target_name})
1177+
if (onnxruntime_target_platform STREQUAL "x86" AND NOT onnxruntime_BUILD_WEBASSEMBLY)
1178+
target_link_options(${target_name} PRIVATE /SAFESEH)
1179+
endif()
11591180
endfunction()
11601181

11611182
function(onnxruntime_add_include_to_target dst_target)
@@ -1814,7 +1835,7 @@ if (WINDOWS_STORE)
18141835
target_link_options(onnxruntime PRIVATE /DYNAMICBASE /NXCOMPAT /APPCONTAINER)
18151836
target_link_options(winml_dll PRIVATE /DYNAMICBASE /NXCOMPAT /APPCONTAINER)
18161837

1817-
if (onnxruntime_target_platform STREQUAL "x86")
1838+
if (onnxruntime_target_platform STREQUAL "x86" AND NOT onnxruntime_BUILD_WEBASSEMBLY)
18181839
target_link_options(onnxruntime PRIVATE /SAFESEH)
18191840
target_link_options(winml_dll PRIVATE /SAFESEH)
18201841
endif()

cmake/onnxruntime.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ set(onnxruntime_INTERNAL_LIBRARIES
174174
${onnxruntime_tvm_libs}
175175
onnxruntime_framework
176176
onnxruntime_graph
177+
${ONNXRUNTIME_MLAS_LIBS}
177178
onnxruntime_common
178-
onnxruntime_mlas
179179
onnxruntime_flatbuffers
180180
)
181181

cmake/onnxruntime_common.cmake

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,6 @@ else()
6565
endif()
6666
endif()
6767

68-
if(CMAKE_GENERATOR_PLATFORM)
69-
# Multi-platform generator
70-
set(onnxruntime_target_platform ${CMAKE_GENERATOR_PLATFORM})
71-
else()
72-
set(onnxruntime_target_platform ${CMAKE_SYSTEM_PROCESSOR})
73-
endif()
74-
if(onnxruntime_target_platform STREQUAL "ARM64")
75-
set(onnxruntime_target_platform "ARM64")
76-
elseif(onnxruntime_target_platform STREQUAL "ARM64EC")
77-
set(onnxruntime_target_platform "ARM64EC")
78-
elseif(onnxruntime_target_platform STREQUAL "ARM" OR CMAKE_GENERATOR MATCHES "ARM")
79-
set(onnxruntime_target_platform "ARM")
80-
elseif(onnxruntime_target_platform STREQUAL "x64" OR onnxruntime_target_platform STREQUAL "x86_64" OR onnxruntime_target_platform STREQUAL "AMD64" OR CMAKE_GENERATOR MATCHES "Win64")
81-
set(onnxruntime_target_platform "x64")
82-
elseif(onnxruntime_target_platform STREQUAL "Win32" OR onnxruntime_target_platform STREQUAL "x86" OR onnxruntime_target_platform STREQUAL "i386" OR onnxruntime_target_platform STREQUAL "i686")
83-
set(onnxruntime_target_platform "x86")
84-
endif()
85-
8668
if(onnxruntime_target_platform STREQUAL "ARM64EC")
8769
if (MSVC)
8870
link_directories("$ENV{VCINSTALLDIR}/Tools/MSVC/$ENV{VCToolsVersion}/lib/ARM64EC")
@@ -185,18 +167,11 @@ if(MSVC)
185167
elseif(onnxruntime_target_platform STREQUAL "x86")
186168
set(X86 TRUE)
187169
endif()
188-
elseif(NOT onnxruntime_BUILD_WEBASSEMBLY)
189-
if (CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
190-
set(ARM64 TRUE)
191-
elseif (CMAKE_OSX_ARCHITECTURES STREQUAL "arm64e")
192-
set(ARM64 TRUE)
193-
elseif (CMAKE_OSX_ARCHITECTURES STREQUAL "arm")
194-
set(ARM TRUE)
195-
elseif (CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64")
196-
set(X86_64 TRUE)
197-
elseif (CMAKE_OSX_ARCHITECTURES STREQUAL "i386")
198-
set(X86 TRUE)
170+
elseif(APPLE)
171+
if(CMAKE_OSX_ARCHITECTURES_LEN LESS_EQUAL 1)
172+
set(X64 TRUE)
199173
endif()
174+
elseif(NOT onnxruntime_BUILD_WEBASSEMBLY)
200175
if (CMAKE_SYSTEM_NAME STREQUAL "Android")
201176
if (CMAKE_ANDROID_ARCH_ABI STREQUAL "armeabi-v7a")
202177
set(ARM TRUE)

cmake/onnxruntime_java.cmake

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,24 @@ endif()
7979

8080
# Set platform and arch for packaging
8181
# Checks the names set by MLAS on non-Windows platforms first
82-
if (CMAKE_SYSTEM_NAME STREQUAL "Android")
82+
if(APPLE)
83+
get_target_property(ONNXRUNTIME4J_OSX_ARCH onnxruntime4j_jni OSX_ARCHITECTURES)
84+
list(LENGTH ONNXRUNTIME4J_OSX_ARCH ONNXRUNTIME4J_OSX_ARCH_LEN)
85+
if(ONNXRUNTIME4J_OSX_ARCH)
86+
if(ONNXRUNTIME4J_OSX_ARCH_LEN LESS_EQUAL 1)
87+
list(GET ONNXRUNTIME4J_OSX_ARCH 0 JNI_ARCH)
88+
message("Set Java ARCH TO macOS/iOS ${JNI_ARCH}")
89+
else()
90+
message(FATAL_ERROR "Java is currently not supported for macOS universal")
91+
endif()
92+
else()
93+
set(JNI_ARCH ${CMAKE_HOST_SYSTEM_PROCESSOR})
94+
message("Set Java ARCH TO macOS/iOS ${JNI_ARCH}")
95+
endif()
96+
if(JNI_ARCH STREQUAL "x86_64")
97+
set(JNI_ARCH x64)
98+
endif()
99+
elseif (CMAKE_SYSTEM_NAME STREQUAL "Android")
83100
set(JNI_ARCH ${ANDROID_ABI})
84101
elseif (ARM64)
85102
set(JNI_ARCH aarch64)

0 commit comments

Comments
 (0)