@@ -75,7 +75,6 @@ option(onnxruntime_USE_NUPHAR "Build with Nuphar" OFF)
75
75
option (onnxruntime_USE_VITISAI "Build with Vitis-AI" OFF )
76
76
option (onnxruntime_USE_TENSORRT "Build with TensorRT support" OFF )
77
77
option (onnxruntime_ENABLE_LTO "Enable link time optimization" OFF )
78
- option (onnxruntime_CROSS_COMPILING "Cross compiling onnx runtime" OFF )
79
78
option (onnxruntime_GCOV_COVERAGE "Compile with options necessary to run code coverage" OFF )
80
79
81
80
#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
160
159
# pre-build python path
161
160
option (onnxruntime_PREBUILT_PYTORCH_PATH "Path to pytorch installation dir" )
162
161
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
+
163
170
# Single output director for all binaries
164
171
set (RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /bin CACHE PATH "Single output directory for all binaries." )
165
172
@@ -461,15 +468,6 @@ if(MSVC)
461
468
-DEIGEN_STRONG_INLINE=inline)
462
469
endif ()
463
470
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
-
473
471
# Mark symbols to be invisible, for macOS/iOS target only
474
472
# Due to many dependencies have different symbol visibility settings, set global compile flags here.
475
473
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS" )
@@ -495,6 +493,30 @@ endmacro()
495
493
#Set global compile flags for all the source code(including third_party code like protobuf)
496
494
#This section must be before any add_subdirectory, otherwise build may fail because /MD,/MT mismatch
497
495
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
+
498
520
#Always enable exception handling, even for Windows ARM
499
521
if (NOT onnxruntime_DISABLE_EXCEPTIONS)
500
522
string (APPEND CMAKE_CXX_FLAGS " /EHsc" )
@@ -543,6 +565,9 @@ if (MSVC)
543
565
SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /guard:cf" )
544
566
endif ()
545
567
else ()
568
+ if (NOT APPLE )
569
+ set (onnxruntime_target_platform ${CMAKE_SYSTEM_PROCESSOR} )
570
+ endif ()
546
571
if (onnxruntime_BUILD_FOR_NATIVE_MACHINE)
547
572
string (APPEND CMAKE_CXX_FLAGS " -march=native -mtune=native" )
548
573
string (APPEND CMAKE_C_FLAGS " -march=native -mtune=native" )
@@ -595,16 +620,6 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
595
620
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong" )
596
621
endif ()
597
622
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
-
608
623
#Dependencies begin
609
624
if (onnxruntime_BUILD_UNIT_TESTS)
610
625
if (onnxruntime_PREFER_SYSTEM_LIB)
@@ -639,10 +654,6 @@ set(ENABLE_DATE_TESTING OFF CACHE BOOL "" FORCE)
639
654
set (USE_SYSTEM_TZ_DB ON CACHE BOOL "" FORCE)
640
655
set (RE2_BUILD_TESTING OFF CACHE BOOL "" FORCE)
641
656
642
- if (CMAKE_CROSSCOMPILING )
643
- message ("Doing crosscompiling" )
644
- endif ()
645
-
646
657
#Need python to generate def file
647
658
if (onnxruntime_BUILD_SHARED_LIB OR onnxruntime_ENABLE_PYTHON)
648
659
if (onnxruntime_ENABLE_PYTHON)
@@ -724,6 +735,17 @@ else()
724
735
endif ()
725
736
if (TARGET protoc)
726
737
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 ()
727
749
endif ()
728
750
if (onnxruntime_USE_FULL_PROTOBUF)
729
751
set (PROTOBUF_LIB libprotobuf)
@@ -794,31 +816,35 @@ if(NOT TARGET re2::re2)
794
816
set (RE2_INCLUDE_DIR ${REPO_ROOT} /cmake/external/re2)
795
817
endif ()
796
818
819
+
797
820
# Adding pytorch CPU info library
798
821
# 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 ()
822
848
endif ()
823
849
824
850
# TODO do we have to add target_include_directories to each project that uses this?
@@ -828,12 +854,7 @@ if(CPUINFO_SUPPORTED)
828
854
set (CPUINFO_BUILD_TOOLS OFF CACHE INTERNAL "" )
829
855
set (CPUINFO_BUILD_UNIT_TESTS OFF CACHE INTERNAL "" )
830
856
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 "" )
837
858
838
859
string (APPEND CMAKE_CXX_FLAGS " -DCPUINFO_SUPPORTED" )
839
860
add_subdirectory (external/pytorch_cpuinfo EXCLUDE_FROM_ALL )
@@ -1084,10 +1105,7 @@ function(onnxruntime_set_compile_flags target_name)
1084
1105
target_compile_options (${target_name} PRIVATE "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:--compiler-options -Werror>" "$<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:-Werror>" )
1085
1106
endif ()
1086
1107
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)
1091
1109
target_include_directories (${target_name} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR} /external/nsync/public" )
1092
1110
endif ()
1093
1111
foreach (ORT_FLAG ${ORT_PROVIDER_FLAGS} )
@@ -1140,22 +1158,25 @@ endfunction()
1140
1158
1141
1159
#For plugins that are not linked into other targets but may be loaded dynamically at runtime using dlopen-like functionality.
1142
1160
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" ))
1144
1162
add_library (${target_name} SHARED ${ARGN} )
1145
1163
else ()
1146
1164
#On Windows, this target shouldn't generate an import lib, but I don't know how to disable it.
1147
1165
add_library (${target_name} MODULE ${ARGN} )
1148
1166
endif ()
1149
1167
1150
1168
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 ()
1151
1172
endfunction ()
1152
1173
1153
1174
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 ()
1157
1175
add_executable (${target_name} ${ARGN} )
1158
1176
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 ()
1159
1180
endfunction ()
1160
1181
1161
1182
function (onnxruntime_add_include_to_target dst_target)
@@ -1814,7 +1835,7 @@ if (WINDOWS_STORE)
1814
1835
target_link_options (onnxruntime PRIVATE /DYNAMICBASE /NXCOMPAT /APPCONTAINER)
1815
1836
target_link_options (winml_dll PRIVATE /DYNAMICBASE /NXCOMPAT /APPCONTAINER)
1816
1837
1817
- if (onnxruntime_target_platform STREQUAL "x86" )
1838
+ if (onnxruntime_target_platform STREQUAL "x86" AND NOT onnxruntime_BUILD_WEBASSEMBLY )
1818
1839
target_link_options (onnxruntime PRIVATE /SAFESEH)
1819
1840
target_link_options (winml_dll PRIVATE /SAFESEH)
1820
1841
endif ()
0 commit comments