@@ -108,48 +108,53 @@ FetchContent_Declare(
108
108
)
109
109
110
110
# Download a protoc binary from Internet if needed
111
- if (CMAKE_CROSSCOMPILING AND NOT ONNX_CUSTOM_PROTOC_EXECUTABLE)
111
+ if (NOT ONNX_CUSTOM_PROTOC_EXECUTABLE)
112
112
# This part of code is only for users' convenience. The code couldn't handle all cases. Users always can manually
113
113
# download protoc from Protobuf's Github release page and pass the local path to the ONNX_CUSTOM_PROTOC_EXECUTABLE
114
114
# variable.
115
- message ("CMAKE_HOST_SYSTEM_NAME: ${CMAKE_HOST_SYSTEM_NAME} " )
116
- if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows" )
117
- if (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64" )
118
- FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_win64} URL_HASH SHA1=${DEP_SHA1_protoc_win64} )
119
- FetchContent_Populate(protoc_binary)
120
- elseif (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86" )
121
- FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_win32} URL_HASH SHA1=${DEP_SHA1_protoc_win32} )
122
- FetchContent_Populate(protoc_binary)
123
- endif ()
124
- if (protoc_binary_SOURCE_DIR)
125
- message ("Use prebuilt protoc" )
126
- set (ONNX_CUSTOM_PROTOC_EXECUTABLE ${protoc_binary_SOURCE_DIR} /bin/protoc.exe)
127
- set (PROTOC_EXECUTABLE ${ONNX_CUSTOM_PROTOC_EXECUTABLE} )
128
- endif ()
129
- elseif (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" )
130
- if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64)$" )
131
- FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_linux_x64} URL_HASH SHA1=${DEP_SHA1_protoc_linux_x64} )
132
- FetchContent_Populate(protoc_binary)
133
- elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(i.86|x86?)$" )
134
- FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_linux_x86} URL_HASH SHA1=${DEP_SHA1_protoc_linux_x86} )
135
- FetchContent_Populate(protoc_binary)
136
- elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64.*" )
137
- FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_linux_aarch64} URL_HASH SHA1=${DEP_SHA1_protoc_linux_aarch64} )
138
- FetchContent_Populate(protoc_binary)
139
- endif ()
140
- if (protoc_binary_SOURCE_DIR)
141
- message ("Use prebuilt protoc" )
142
- set (ONNX_CUSTOM_PROTOC_EXECUTABLE ${protoc_binary_SOURCE_DIR} /bin/protoc)
143
- set (PROTOC_EXECUTABLE ${ONNX_CUSTOM_PROTOC_EXECUTABLE} )
144
- endif ()
145
- elseif ((CMAKE_SYSTEM_NAME STREQUAL "Emscripten" OR CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "iOS" ) AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" )
115
+ if (CMAKE_HOST_APPLE )
116
+ # Using CMAKE_CROSSCOMPILING is not recommended for Apple target devices.
117
+ # https://cmake.org/cmake/help/v3.26/variable/CMAKE_CROSSCOMPILING.html
118
+ # To keep it simple, just download and use the universal protoc binary for all Apple host builds.
146
119
FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_mac_universal} URL_HASH SHA1=${DEP_SHA1_protoc_mac_universal} )
147
120
FetchContent_Populate(protoc_binary)
148
121
if (protoc_binary_SOURCE_DIR)
149
122
message ("Use prebuilt protoc" )
150
123
set (ONNX_CUSTOM_PROTOC_EXECUTABLE ${protoc_binary_SOURCE_DIR} /bin/protoc)
151
124
set (PROTOC_EXECUTABLE ${ONNX_CUSTOM_PROTOC_EXECUTABLE} )
152
125
endif ()
126
+ elseif (CMAKE_CROSSCOMPILING )
127
+ message ("CMAKE_HOST_SYSTEM_NAME: ${CMAKE_HOST_SYSTEM_NAME} " )
128
+ if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows" )
129
+ if (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64" )
130
+ FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_win64} URL_HASH SHA1=${DEP_SHA1_protoc_win64} )
131
+ FetchContent_Populate(protoc_binary)
132
+ elseif (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86" )
133
+ FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_win32} URL_HASH SHA1=${DEP_SHA1_protoc_win32} )
134
+ FetchContent_Populate(protoc_binary)
135
+ endif ()
136
+ if (protoc_binary_SOURCE_DIR)
137
+ message ("Use prebuilt protoc" )
138
+ set (ONNX_CUSTOM_PROTOC_EXECUTABLE ${protoc_binary_SOURCE_DIR} /bin/protoc.exe)
139
+ set (PROTOC_EXECUTABLE ${ONNX_CUSTOM_PROTOC_EXECUTABLE} )
140
+ endif ()
141
+ elseif (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" )
142
+ if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64)$" )
143
+ FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_linux_x64} URL_HASH SHA1=${DEP_SHA1_protoc_linux_x64} )
144
+ FetchContent_Populate(protoc_binary)
145
+ elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(i.86|x86?)$" )
146
+ FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_linux_x86} URL_HASH SHA1=${DEP_SHA1_protoc_linux_x86} )
147
+ FetchContent_Populate(protoc_binary)
148
+ elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64.*" )
149
+ FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_linux_aarch64} URL_HASH SHA1=${DEP_SHA1_protoc_linux_aarch64} )
150
+ FetchContent_Populate(protoc_binary)
151
+ endif ()
152
+ if (protoc_binary_SOURCE_DIR)
153
+ message ("Use prebuilt protoc" )
154
+ set (ONNX_CUSTOM_PROTOC_EXECUTABLE ${protoc_binary_SOURCE_DIR} /bin/protoc)
155
+ set (PROTOC_EXECUTABLE ${ONNX_CUSTOM_PROTOC_EXECUTABLE} )
156
+ endif ()
157
+ endif ()
153
158
endif ()
154
159
endif ()
155
160
@@ -184,9 +189,9 @@ FetchContent_Declare(
184
189
)
185
190
186
191
set (protobuf_BUILD_TESTS OFF CACHE BOOL "Build protobuf tests" FORCE)
187
- #TODO: we'd better to turn the following option off. However, it will cause
192
+ #TODO: we'd better to turn the following option off. However, it will cause
188
193
# ".\build.bat --config Debug --parallel --skip_submodule_sync --update" fail with an error message:
189
- # install(EXPORT "ONNXTargets" ...) includes target "onnx_proto" which requires target "libprotobuf-lite" that is
194
+ # install(EXPORT "ONNXTargets" ...) includes target "onnx_proto" which requires target "libprotobuf-lite" that is
190
195
# not in any export set.
191
196
#set(protobuf_INSTALL OFF CACHE BOOL "Install protobuf binaries and files" FORCE)
192
197
set (protobuf_USE_EXTERNAL_GTEST ON CACHE BOOL "" FORCE)
@@ -562,4 +567,3 @@ endif()
562
567
563
568
FILE (TO_NATIVE_PATH ${CMAKE_BINARY_DIR} ORT_BINARY_DIR )
564
569
FILE (TO_NATIVE_PATH ${PROJECT_SOURCE_DIR} ORT_SOURCE_DIR)
565
-
0 commit comments