@@ -168,6 +168,14 @@ set(ONNX_CUSTOM_PROTOC_EXECUTABLE "" CACHE STRING "Specify custom protoc executa
168
168
# pre-build python path
169
169
option (onnxruntime_PREBUILT_PYTORCH_PATH "Path to pytorch installation dir" )
170
170
171
+ if (APPLE )
172
+ if (NOT CMAKE_OSX_ARCHITECTURES)
173
+ message ("Building ONNX Runtime for ${CMAKE_HOST_SYSTEM_PROCESSOR} " )
174
+ endif ()
175
+ elseif (NOT WIN32 AND NOT APPLE )
176
+ message ("Building ONNX Runtime for ${CMAKE_SYSTEM_PROCESSOR} " )
177
+ endif ()
178
+
171
179
# Single output director for all binaries
172
180
set (RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /bin CACHE PATH "Single output directory for all binaries." )
173
181
@@ -507,6 +515,30 @@ endmacro()
507
515
#Set global compile flags for all the source code(including third_party code like protobuf)
508
516
#This section must be before any add_subdirectory, otherwise build may fail because /MD,/MT mismatch
509
517
if (MSVC )
518
+ enable_language (ASM_MASM)
519
+ if (CMAKE_GENERATOR_PLATFORM)
520
+ # Multi-platform generator
521
+ set (onnxruntime_target_platform ${CMAKE_GENERATOR_PLATFORM} )
522
+ else ()
523
+ set (onnxruntime_target_platform ${CMAKE_SYSTEM_PROCESSOR} )
524
+ endif ()
525
+ if (onnxruntime_target_platform STREQUAL "ARM64" )
526
+ set (onnxruntime_target_platform "ARM64" )
527
+ elseif (onnxruntime_target_platform STREQUAL "ARM64EC" )
528
+ set (onnxruntime_target_platform "ARM64EC" )
529
+ elseif (onnxruntime_target_platform STREQUAL "ARM" OR CMAKE_GENERATOR MATCHES "ARM" )
530
+ set (onnxruntime_target_platform "ARM" )
531
+ elseif (onnxruntime_target_platform STREQUAL "x64" OR onnxruntime_target_platform STREQUAL "x86_64" OR onnxruntime_target_platform STREQUAL "AMD64" OR CMAKE_GENERATOR MATCHES "Win64" )
532
+ set (onnxruntime_target_platform "x64" )
533
+ elseif (onnxruntime_target_platform STREQUAL "Win32" OR onnxruntime_target_platform STREQUAL "x86" OR onnxruntime_target_platform STREQUAL "i386" OR onnxruntime_target_platform STREQUAL "i686" )
534
+ set (onnxruntime_target_platform "x86" )
535
+ if (NOT onnxruntime_BUILD_WEBASSEMBLY)
536
+ message ("Enabling SAFESEH for x86 build" )
537
+ set (CMAKE_ASM_MASM_FLAGS "${CMAKE_ASM_MASM_FLAGS} /safeseh" )
538
+ endif ()
539
+ endif ()
540
+
541
+
510
542
#Always enable exception handling, even for Windows ARM
511
543
if (NOT onnxruntime_DISABLE_EXCEPTIONS)
512
544
string (APPEND CMAKE_CXX_FLAGS " /EHsc" )
@@ -555,6 +587,9 @@ if (MSVC)
555
587
SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /guard:cf" )
556
588
endif ()
557
589
else ()
590
+ if (NOT APPLE )
591
+ set (onnxruntime_target_platform ${CMAKE_SYSTEM_PROCESSOR} )
592
+ endif ()
558
593
if (onnxruntime_BUILD_FOR_NATIVE_MACHINE)
559
594
string (APPEND CMAKE_CXX_FLAGS " -march=native -mtune=native" )
560
595
string (APPEND CMAKE_C_FLAGS " -march=native -mtune=native" )
@@ -736,6 +771,17 @@ else()
736
771
endif ()
737
772
if (TARGET protoc)
738
773
set_target_properties (protoc PROPERTIES FOLDER "External/Protobuf" )
774
+ get_target_property (PROTOC_OSX_ARCH protoc OSX_ARCHITECTURES )
775
+ if (PROTOC_OSX_ARCH)
776
+ if (${CMAKE_HOST_SYSTEM_PROCESSOR} IN_LIST PROTOC_OSX_ARCH)
777
+ message ("protoc can run" )
778
+ else ()
779
+ list (APPEND PROTOC_OSX_ARCH ${CMAKE_HOST_SYSTEM_PROCESSOR} )
780
+ set_target_properties (protoc PROPERTIES OSX_ARCHITECTURES "${CMAKE_HOST_SYSTEM_PROCESSOR} " )
781
+ set_target_properties (libprotoc PROPERTIES OSX_ARCHITECTURES "${PROTOC_OSX_ARCH} " )
782
+ set_target_properties (libprotobuf PROPERTIES OSX_ARCHITECTURES "${PROTOC_OSX_ARCH} " )
783
+ endif ()
784
+ endif ()
739
785
endif ()
740
786
if (onnxruntime_USE_FULL_PROTOBUF)
741
787
set (PROTOBUF_LIB libprotobuf)
@@ -810,31 +856,39 @@ if(NOT TARGET re2::re2)
810
856
set (RE2_INCLUDE_DIR ${REPO_ROOT} /cmake/external/re2)
811
857
endif ()
812
858
859
+
813
860
# Adding pytorch CPU info library
814
861
# TODO!! need a better way to find out the supported architectures
815
- set (TARGET_ARCH "${CMAKE_SYSTEM_PROCESSOR} " )
816
- if (NOT DEFINED TARGET_ARCH OR "${TARGET_ARCH} " STREQUAL "" )
817
- set (TARGET_ARCH "${CMAKE_OSX_ARCHITECTURES} " )
818
- endif ()
819
-
820
- set (CPUINFO_SUPPORTED TRUE )
821
- if (NOT DEFINED TARGET_ARCH OR "${TARGET_ARCH} " STREQUAL "" )
822
- message (WARNING
823
- "Target processor architecture is not specified. cpuinfo not included" )
824
- set (CPUINFO_SUPPORTED FALSE )
825
- elseif (NOT TARGET_ARCH MATCHES "^(i[3-6]86|AMD64|x86(_64)?|armv[5-8].*|aarch64|arm64)$" )
826
- message (WARNING
827
- "Target processor architecture \" ${CPUINFO_TARGET_PROCESSOR} \" is not supported in cpuinfo. "
828
- "cpuinfo not included." )
829
- set (CPUINFO_SUPPORTED FALSE )
830
- elseif (MSVC AND (( CMAKE_SYSTEM_PROCESSOR MATCHES "^(ARM.*|arm.*)$" ) OR (CMAKE_GENERATOR_PLATFORM MATCHES "^(ARM.*|arm.*)$" ) ))
831
- message (WARNING
832
- "Cpuinfo not included for compilation problems with Windows ARM." )
833
- set (CPUINFO_SUPPORTED FALSE )
834
- elseif (WINDOWS_STORE)
835
- message (WARNING
836
- "Cpuinfo not included in Windows Store builds" )
837
- set (CPUINFO_SUPPORTED FALSE )
862
+ list (LENGTH CMAKE_OSX_ARCHITECTURES CMAKE_OSX_ARCHITECTURES_LEN)
863
+ if (APPLE )
864
+ if (CMAKE_OSX_ARCHITECTURES_LEN LESS_EQUAL 1)
865
+ set (CPUINFO_SUPPORTED TRUE )
866
+ elseif (onnxruntime_BUILD_APPLE_FRAMEWORK)
867
+ # We stitch multiple static libraries together when onnxruntime_BUILD_APPLE_FRAMEWORK is true,
868
+ # but that would not work for universal static libraries
869
+ message (FATAL_ERROR "universal binary is not supported for apple framework" )
870
+ endif ()
871
+ else ()
872
+ if (onnxruntime_BUILD_WEBASSEMBLY)
873
+ set (CPUINFO_SUPPORTED FALSE )
874
+ else ()
875
+ set (CPUINFO_SUPPORTED TRUE )
876
+ endif ()
877
+ if (WIN32 )
878
+ # Exclude Windows ARM build and Windows Store
879
+ if (${onnxruntime_target_platform} MATCHES "^(ARM.*|arm.*)$" )
880
+ message (WARNING "Cpuinfo not included for compilation problems with Windows ARM." )
881
+ set (CPUINFO_SUPPORTED FALSE )
882
+ elseif (WINDOWS_STORE)
883
+ message (WARNING "Cpuinfo not included in Windows Store builds" )
884
+ set (CPUINFO_SUPPORTED FALSE )
885
+ endif ()
886
+ elseif (NOT ${onnxruntime_target_platform} MATCHES "^(i[3-6]86|AMD64|x86(_64)?|armv[5-8].*|aarch64|arm64)$" )
887
+ message (WARNING
888
+ "Target processor architecture \" ${onnxruntime_target_platform} \" is not supported in cpuinfo. "
889
+ "cpuinfo not included." )
890
+ set (CPUINFO_SUPPORTED FALSE )
891
+ endif ()
838
892
endif ()
839
893
840
894
# TODO do we have to add target_include_directories to each project that uses this?
@@ -1162,6 +1216,9 @@ function(onnxruntime_add_shared_library_module target_name)
1162
1216
endif ()
1163
1217
1164
1218
onnxruntime_configure_target(${target_name} )
1219
+ if (onnxruntime_target_platform STREQUAL "x86" AND NOT onnxruntime_BUILD_WEBASSEMBLY)
1220
+ target_link_options (${target_name} PRIVATE /SAFESEH)
1221
+ endif ()
1165
1222
endfunction ()
1166
1223
1167
1224
function (onnxruntime_add_executable target_name)
@@ -1170,6 +1227,9 @@ function(onnxruntime_add_executable target_name)
1170
1227
endif ()
1171
1228
add_executable (${target_name} ${ARGN} )
1172
1229
onnxruntime_configure_target(${target_name} )
1230
+ if (onnxruntime_target_platform STREQUAL "x86" AND NOT onnxruntime_BUILD_WEBASSEMBLY)
1231
+ target_link_options (${target_name} PRIVATE /SAFESEH)
1232
+ endif ()
1173
1233
endfunction ()
1174
1234
1175
1235
function (onnxruntime_add_include_to_target dst_target)
@@ -1813,7 +1873,7 @@ if (WINDOWS_STORE)
1813
1873
target_link_options (onnxruntime PRIVATE /DYNAMICBASE /NXCOMPAT /APPCONTAINER)
1814
1874
target_link_options (winml_dll PRIVATE /DYNAMICBASE /NXCOMPAT /APPCONTAINER)
1815
1875
1816
- if (onnxruntime_target_platform STREQUAL "x86" )
1876
+ if (onnxruntime_target_platform STREQUAL "x86" AND NOT onnxruntime_BUILD_WEBASSEMBLY )
1817
1877
target_link_options (onnxruntime PRIVATE /SAFESEH)
1818
1878
target_link_options (winml_dll PRIVATE /SAFESEH)
1819
1879
endif ()
0 commit comments