@@ -108,53 +108,48 @@ FetchContent_Declare(
108
108
)
109
109
110
110
# Download a protoc binary from Internet if needed
111
- if (NOT ONNX_CUSTOM_PROTOC_EXECUTABLE )
111
+ if (CMAKE_CROSSCOMPILING AND 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
- if (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 Apple builds.
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" )
119
146
FetchContent_Declare (protoc_binary URL ${DEP_URL_protoc_mac_universal} URL_HASH SHA1=${DEP_SHA1_protoc_mac_universal} )
120
147
FetchContent_Populate (protoc_binary )
121
148
if (protoc_binary_SOURCE_DIR )
122
149
message ("Use prebuilt protoc" )
123
150
set (ONNX_CUSTOM_PROTOC_EXECUTABLE ${protoc_binary_SOURCE_DIR} /bin/protoc )
124
151
set (PROTOC_EXECUTABLE ${ONNX_CUSTOM_PROTOC_EXECUTABLE} )
125
152
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 ()
158
153
endif ()
159
154
endif ()
160
155
@@ -189,9 +184,9 @@ FetchContent_Declare(
189
184
)
190
185
191
186
set (protobuf_BUILD_TESTS OFF CACHE BOOL "Build protobuf tests" FORCE )
192
- #TODO: we'd better to turn the following option off. However, it will cause
187
+ #TODO: we'd better to turn the following option off. However, it will cause
193
188
# ".\build.bat --config Debug --parallel --skip_submodule_sync --update" fail with an error message:
194
- # install(EXPORT "ONNXTargets" ...) includes target "onnx_proto" which requires target "libprotobuf-lite" that is
189
+ # install(EXPORT "ONNXTargets" ...) includes target "onnx_proto" which requires target "libprotobuf-lite" that is
195
190
# not in any export set.
196
191
#set(protobuf_INSTALL OFF CACHE BOOL "Install protobuf binaries and files" FORCE)
197
192
set (protobuf_USE_EXTERNAL_GTEST ON CACHE BOOL "" FORCE )
@@ -567,3 +562,4 @@ endif()
567
562
568
563
FILE (TO_NATIVE_PATH ${CMAKE_BINARY_DIR} ORT_BINARY_DIR )
569
564
FILE (TO_NATIVE_PATH ${PROJECT_SOURCE_DIR} ORT_SOURCE_DIR )
565
+
0 commit comments