microsoft/onnxruntime-extensions

Public

mirrored from https://github.com/microsoft/onnxruntime-extensionsAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.5.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

CMakeLists.txt

452lines · modecode

1cmake_minimum_required(VERSION 3.16.0)
2project(onnxruntime_extensions LANGUAGES C CXX)
3# set(CMAKE_VERBOSE_MAKEFILE ON)
4
5if(NOT CMAKE_BUILD_TYPE)
6 message(STATUS "Build type not set - using RelWithDebInfo")
7 set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose build type: Debug Release RelWithDebInfo." FORCE)
8endif()
9
10
11set(CPACK_PACKAGE_NAME "onnxruntime_extensions")
12set(CPACK_PACKAGE_VERSION_MAJOR "0")
13set(CPACK_PACKAGE_VERSION_MINOR "5")
14set(CPACK_PACKAGE_VERSION_PATCH "0")
15set(VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH})
16
17
18set(CMAKE_CXX_STANDARD 17)
19set(CMAKE_CXX_STANDARD_REQUIRED ON)
20set(CMAKE_CXX_EXTENSIONS OFF)
21include(CheckCXXCompilerFlag)
22include(CheckLanguage)
23
24option(CC_OPTIMIZE "Allow compiler optimizations, Set to OFF to disable" ON)
25option(OCOS_ENABLE_PYTHON "Enable Python component building" OFF)
26option(OCOS_ENABLE_CTEST "Enable C++ test" OFF)
27option(OCOS_ENABLE_CPP_EXCEPTIONS "Enable C++ Exception" ON)
28option(OCOS_ENABLE_TF_STRING "Enable String Operator Set" ON)
29option(OCOS_ENABLE_RE2_REGEX "Enable StringRegexReplace and StringRegexSplit" ON)
30option(OCOS_ENABLE_GPT2_TOKENIZER "Enable the GPT2 tokenizer building" ON)
31option(OCOS_ENABLE_SPM_TOKENIZER "Enable the SentencePiece tokenizer building" ON)
32option(OCOS_ENABLE_WORDPIECE_TOKENIZER "Enable the WordpieceTokenizer building" ON)
33option(OCOS_ENABLE_BERT_TOKENIZER "Enable the BertTokenizer building" ON)
34option(OCOS_ENABLE_BLINGFIRE "Enable operators depending on the Blingfire library" ON)
35option(OCOS_ENABLE_MATH "Enable math tensor operators building" ON)
36option(OCOS_ENABLE_DLIB "Enable operators like Inverse depending on DLIB" ON)
37option(OCOS_ENABLE_OPENCV "Enable operators depending on opencv" ON)
38option(OCOS_ENABLE_OPENCV_CODECS "Enable operators depending on opencv imgcodecs" OFF)
39option(OCOS_ENABLE_STATIC_LIB "Enable generating static library" OFF)
40option(OCOS_ENABLE_SELECTED_OPLIST "Enable including the selected_ops tool file" OFF)
41
42
43function(disable_all_operators)
44 set(OCOS_ENABLE_RE2_REGEX OFF CACHE INTERNAL "")
45 set(OCOS_ENABLE_TF_STRING OFF CACHE INTERNAL "")
46 set(OCOS_ENABLE_WORDPIECE_TOKENIZER OFF CACHE INTERNAL "")
47 set(OCOS_ENABLE_GPT2_TOKENIZER OFF CACHE INTERNAL "")
48 set(OCOS_ENABLE_SPM_TOKENIZER OFF CACHE INTERNAL "")
49 set(OCOS_ENABLE_BERT_TOKENIZER OFF CACHE INTERNAL "")
50 set(OCOS_ENABLE_BLINGFIRE OFF CACHE INTERNAL "")
51 set(OCOS_ENABLE_MATH OFF CACHE INTERNAL "")
52 set(OCOS_ENABLE_DLIB OFF CACHE INTERNAL "")
53 set(OCOS_ENABLE_OPENCV OFF CACHE INTERNAL "")
54endfunction()
55
56if(NOT CC_OPTIMIZE)
57 message("!!!THE COMPILER OPTIMIZATION HAS BEEN DISABLED, DEBUG-ONLY!!!")
58 string(REGEX REPLACE "([\-\/]O[123])" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
59 string(REGEX REPLACE "([\-\/]O[123])" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
60 string(REGEX REPLACE "([\-\/]O[123])" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
61 string(REGEX REPLACE "([\-\/]O[123])" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
62
63 if (NOT WIN32)
64 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
65 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
66 else()
67 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Od")
68 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Od")
69 endif()
70endif()
71
72# Build the libraries with -fPIC
73set(CMAKE_POSITION_INDEPENDENT_CODE ON)
74
75set_property(GLOBAL PROPERTY USE_FOLDERS ON)
76
77set(CMAKE_FIND_FRAMEWORK NEVER CACHE STRING "...")
78if(NOT "${CMAKE_FIND_FRAMEWORK}" STREQUAL "NEVER")
79 message(FATAL_ERROR "CMAKE_FIND_FRAMEWORK is not NEVER")
80endif()
81
82# External dependencies
83list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/externals ${PROJECT_SOURCE_DIR}/cmake)
84
85if (OCOS_ENABLE_SELECTED_OPLIST)
86 # Need to ensure _selectedoplist.cmake file is already generated in folder: ${PROJECT_SOURCE_DIR}/cmake/
87 # You could run gen_selectedops.py in folder: tools/ to generate _selectedoplist.cmake
88 message(STATUS "Looking for the _selectedoplist.cmake")
89 disable_all_operators()
90 include(_selectedoplist)
91endif()
92
93if(NOT OCOS_ENABLE_CPP_EXCEPTIONS)
94 include(noexcep_ops)
95 add_compile_definitions(OCOS_NO_EXCEPTIONS ORT_NO_EXCEPTIONS)
96 if(MSVC)
97 string(REGEX REPLACE "/EHsc" "/EHs-c-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
98 add_compile_definitions("_HAS_EXCEPTIONS=0")
99 else()
100 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables")
101 endif()
102endif()
103
104include(FetchContent)
105
106if (OCOS_ENABLE_RE2_REGEX)
107 if (NOT TARGET re2::re2)
108 set(RE2_BUILD_TESTING OFF CACHE INTERNAL "")
109 message(STATUS "Fetch googlere2")
110 include(googlere2)
111 endif()
112
113 if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
114 set_property(TARGET re2 PROPERTY COMPILE_OPTIONS)
115 endif()
116endif()
117
118macro(standardize_output_folder bin_target)
119set_target_properties(${bin_target} PROPERTIES
120 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
121 LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
122 ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
123 PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
124endmacro()
125
126
127#### scan all source files
128
129file(GLOB TARGET_SRC "operators/*.cc" "operators/*.h")
130if (OCOS_ENABLE_TF_STRING)
131 set(farmhash_SOURCE_DIR ${PROJECT_SOURCE_DIR}/cmake/externals/farmhash)
132 file(GLOB TARGET_SRC_KERNELS "operators/text/*.cc" "operators/text/*.h*")
133 file(GLOB TARGET_SRC_HASH "${farmhash_SOURCE_DIR}/src/farmhash.*")
134 list(APPEND TARGET_SRC ${TARGET_SRC_KERNELS} ${TARGET_SRC_HASH})
135endif()
136
137if (OCOS_ENABLE_RE2_REGEX)
138 file(GLOB TARGET_SRC_RE2_KERNELS "operators/text/re2_strings/*.cc" "operators/text/re2_strings/*.h*")
139 list(APPEND TARGET_SRC ${TARGET_SRC_RE2_KERNELS})
140endif()
141
142if (OCOS_ENABLE_MATH)
143 if(OCOS_ENABLE_DLIB)
144 set(DLIB_ISO_CPP_ONLY ON CACHE INTERNAL "")
145 set(DLIB_NO_GUI_SUPPORT ON CACHE INTERNAL "")
146 set(DLIB_USE_CUDA OFF CACHE INTERNAL "")
147 set(DLIB_USE_LAPACK OFF CACHE INTERNAL "")
148 set(DLIB_USE_BLAS OFF CACHE INTERNAL "")
149 include(dlib)
150 # Ideally, dlib should be included as
151 # file(GLOB TARGET_SRC_DLIB "${dlib_SOURCE_DIR}/dlib/all/source.cpp")
152 # To avoid the unintentional using some unwanted component, only include
153 file(GLOB TARGET_SRC_DLIB "${dlib_SOURCE_DIR}/dlib/test_for_odr_violations.cpp")
154 file(GLOB TARGET_SRC_INVERSE "operators/math/dlib/*.cc" "operators/math/dlib/*.h*")
155 endif()
156 file(GLOB TARGET_SRC_MATH "operators/math/*.cc" "operators/math/*.h*")
157 list(APPEND TARGET_SRC ${TARGET_SRC_MATH} ${TARGET_SRC_DLIB} ${TARGET_SRC_INVERSE})
158endif()
159
160if (OCOS_ENABLE_OPENCV)
161 message(STATUS "Fetch opencv")
162 include(opencv)
163 file(GLOB TARGET_SRC_CV "operators/cv2/*.cc" "operators/cv2/*.h*")
164 list(APPEND TARGET_SRC ${TARGET_SRC_CV})
165endif()
166
167set(_HAS_TOKENIZER OFF)
168if (OCOS_ENABLE_GPT2_TOKENIZER)
169 # GPT2
170 set(_HAS_TOKENIZER ON)
171 file(GLOB tok_TARGET_SRC "operators/tokenizer/gpt*.cc" "operators/tokenizer/unicode*.*")
172 list(APPEND TARGET_SRC ${tok_TARGET_SRC})
173endif()
174
175if (OCOS_ENABLE_SPM_TOKENIZER)
176 # SentencePiece
177 set(_HAS_TOKENIZER ON)
178 set(SPM_ENABLE_TCMALLOC OFF CACHE INTERNAL "")
179 set(SPM_ENABLE_SHARED OFF CACHE INTERNAL "")
180 message(STATUS "Fetch sentencepiece")
181 include(sentencepieceproject)
182 file(GLOB stpiece_TARGET_SRC "operators/tokenizer/sentencepiece/*.cc" "operators/tokenizer/sentencepiece*")
183 list(REMOVE_ITEM stpiece_TARGET_SRC INCLUDE REGEX ".*((spm)|(train)).*")
184 list(APPEND TARGET_SRC ${stpiece_TARGET_SRC})
185endif()
186
187if (OCOS_ENABLE_WORDPIECE_TOKENIZER)
188 set(_HAS_TOKENIZER ON)
189 file(GLOB wordpiece_TARGET_SRC "operators/tokenizer/wordpiece*.*")
190 list(APPEND TARGET_SRC ${wordpiece_TARGET_SRC})
191endif()
192
193if (OCOS_ENABLE_BERT_TOKENIZER)
194 # Bert
195 set(_HAS_TOKENIZER ON)
196 file(GLOB bert_TARGET_SRC "operators/tokenizer/basic_tokenizer.*" "operators/tokenizer/bert_tokenizer.*" "operators/tokenizer/bert_tokenizer_decoder.*")
197 list(APPEND TARGET_SRC ${bert_TARGET_SRC})
198endif()
199
200if (OCOS_ENABLE_BLINGFIRE)
201 # blingfire
202 set(_HAS_TOKENIZER ON)
203 file(GLOB blingfire_TARGET_SRC "operators/tokenizer/blingfire*.*")
204 list(APPEND TARGET_SRC ${blingfire_TARGET_SRC})
205endif()
206
207if (OCOS_ENABLE_GPT2_TOKENIZER OR OCOS_ENABLE_WORDPIECE_TOKENIZER)
208 if (NOT TARGET nlohmann_json)
209 set(JSON_BuildTests OFF CACHE INTERNAL "")
210 message(STATUS "Fetch json")
211 include(json)
212 endif()
213endif()
214
215if (_HAS_TOKENIZER)
216 message(STATUS "Tokenizer needed.")
217 file(GLOB tokenizer_TARGET_SRC "operators/tokenizer/tokenizers.*")
218 list(APPEND TARGET_SRC ${tokenizer_TARGET_SRC})
219endif()
220
221#### make all compile options.
222
223add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
224add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
225add_library(ocos_operators STATIC ${TARGET_SRC})
226standardize_output_folder(ocos_operators)
227
228target_include_directories(ocos_operators PUBLIC
229 ${PROJECT_SOURCE_DIR}/includes
230 ${PROJECT_SOURCE_DIR}/includes/onnxruntime
231 ${PROJECT_SOURCE_DIR}/operators
232 ${PROJECT_SOURCE_DIR}/operators/tokenizer)
233set(ocos_libraries "")
234set(OCOS_COMPILE_DEFINITIONS "")
235
236if (OCOS_ENABLE_DLIB)
237 list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_DLIB)
238endif()
239
240if (_HAS_TOKENIZER)
241 list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_TOKENIZER)
242endif()
243
244if (OCOS_ENABLE_TF_STRING)
245 target_include_directories(ocos_operators PUBLIC
246 ${googlere2_SOURCE_DIR}
247 ${farmhash_SOURCE_DIR}/src)
248 list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_TF_STRING NOMINMAX FARMHASH_NO_BUILTIN_EXPECT FARMHASH_DEBUG=0)
249 list(APPEND ocos_libraries re2)
250endif()
251
252if (OCOS_ENABLE_RE2_REGEX)
253 list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_RE2_REGEX)
254endif()
255
256if (OCOS_ENABLE_MATH)
257 target_include_directories(ocos_operators PUBLIC ${dlib_SOURCE_DIR})
258 list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_MATH)
259 # The dlib matrix implementation is all in the headers, no library compiling needed.
260endif()
261
262if (OCOS_ENABLE_OPENCV)
263 list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_OPENCV)
264 if (OCOS_ENABLE_OPENCV_CODECS)
265 list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_OPENCV ENABLE_OPENCV_CODEC)
266 endif()
267 list(APPEND ocos_libraries ${opencv_LIBS})
268 target_include_directories(ocos_operators PRIVATE ${opencv_INCLUDE_DIRS})
269endif()
270
271if (OCOS_ENABLE_GPT2_TOKENIZER)
272 # GPT2
273 target_include_directories(ocos_operators PRIVATE ${json_SOURCE_DIR}/single_include)
274 list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_GPT2_TOKENIZER)
275 list(APPEND ocos_libraries nlohmann_json::nlohmann_json)
276endif()
277
278if (OCOS_ENABLE_WORDPIECE_TOKENIZER)
279 list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_WORDPIECE_TOKENIZER)
280endif()
281
282if (OCOS_ENABLE_BERT_TOKENIZER)
283 list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_BERT_TOKENIZER)
284endif()
285
286if (OCOS_ENABLE_SPM_TOKENIZER)
287 # SentencePiece
288 target_include_directories(ocos_operators PUBLIC ${spm_INCLUDE_DIRS})
289 list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_SPM_TOKENIZER)
290 list(APPEND ocos_libraries sentencepiece-static)
291endif()
292
293if (OCOS_ENABLE_BLINGFIRE)
294 include(blingfire)
295 list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_BLINGFIRE)
296 list(APPEND ocos_libraries bingfirtinydll_static)
297endif()
298
299if (OCOS_ENABLE_GPT2_TOKENIZER OR OCOS_ENABLE_WORDPIECE_TOKENIZER)
300 target_include_directories(ocos_operators PRIVATE ${json_SOURCE_DIR}/single_include)
301 list(APPEND ocos_libraries nlohmann_json::nlohmann_json)
302endif()
303
304list(REMOVE_DUPLICATES OCOS_COMPILE_DEFINITIONS)
305target_compile_definitions(ocos_operators PRIVATE ${OCOS_COMPILE_DEFINITIONS})
306target_link_libraries(ocos_operators PRIVATE ${ocos_libraries})
307
308file(GLOB shared_TARGET_SRC "shared/*.cc" "shared/*.h")
309if(OCOS_ENABLE_PYTHON)
310 set(Python3_FIND_REGISTRY NEVER CACHE STRING "...")
311 if(NOT "${Python3_FIND_REGISTRY}" STREQUAL "NEVER")
312 message(FATAL_ERROR "Python3_FIND_REGISTRY is not NEVER")
313 endif()
314 find_package(Python3 COMPONENTS Interpreter Development.Module NumPy)
315 if (NOT Python3_FOUND)
316 message(FATAL_ERROR "Python3 or NumPy not found!")
317 endif()
318 if (WIN32)
319 list(APPEND shared_TARGET_SRC "${PROJECT_SOURCE_DIR}/onnxruntime_extensions/ortcustomops.def")
320 endif()
321
322 file(GLOB TARGET_SRC_PYOPS "pyop/*.cc" "pyop/*.h")
323 add_library(ortcustomops SHARED ${TARGET_SRC_PYOPS} ${shared_TARGET_SRC})
324 standardize_output_folder(ortcustomops)
325 list(APPEND OCOS_COMPILE_DEFINITIONS PYTHON_OP_SUPPORT)
326 # building static lib has higher priority
327elseif(OCOS_ENABLE_STATIC_LIB)
328 add_library(ortcustomops STATIC ${shared_TARGET_SRC})
329 add_library(onnxruntime_extensions ALIAS ortcustomops)
330elseif(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
331 add_executable(ortcustomops ${shared_TARGET_SRC})
332 set_target_properties(ortcustomops PROPERTIES LINK_FLAGS " \
333 -s WASM=1 \
334 -s NO_EXIT_RUNTIME=0 \
335 -s ALLOW_MEMORY_GROWTH=1 \
336 -s SAFE_HEAP=0 \
337 -s MODULARIZE=1 \
338 -s SAFE_HEAP_LOG=0 \
339 -s STACK_OVERFLOW_CHECK=0 \
340 -s EXPORT_ALL=0 \
341 -s VERBOSE=0 \
342 --no-entry")
343 if (CMAKE_BUILD_TYPE STREQUAL "Debug")
344 set_property(TARGET ortcustomops APPEND_STRING PROPERTY LINK_FLAGS " -s ASSERTIONS=1 -s DEMANGLE_SUPPORT=1")
345 else()
346 set_property(TARGET ortcustomops APPEND_STRING PROPERTY LINK_FLAGS " -s ASSERTIONS=0 -s DEMANGLE_SUPPORT=0")
347 endif()
348else()
349 list(APPEND shared_TARGET_SRC "${PROJECT_SOURCE_DIR}/shared/ortcustomops.def")
350 add_library(ortcustomops SHARED ${shared_TARGET_SRC})
351 if (CMAKE_SYSTEM_NAME STREQUAL "Android")
352 if (OCOS_ENABLE_SPM_TOKENIZER)
353 target_link_libraries(ortcustomops PUBLIC log)
354 set_property(TARGET ortcustomops APPEND_STRING PROPERTY LINK_FLAGS "-Wl,-s -Wl,--version-script -Wl,${PROJECT_SOURCE_DIR}/shared/ortcustomops.ver")
355 endif()
356 endif()
357 standardize_output_folder(ortcustomops)
358endif()
359
360target_compile_definitions(ortcustomops PRIVATE ${OCOS_COMPILE_DEFINITIONS} ${GTEST_CXX_FLAGS})
361target_link_libraries(ortcustomops PUBLIC ocos_operators)
362
363if(OCOS_ENABLE_PYTHON)
364 message(STATUS "Fetch pybind11")
365 include(pybind11)
366 target_include_directories(ortcustomops PRIVATE
367 $<TARGET_PROPERTY:Python3::Module,INTERFACE_INCLUDE_DIRECTORIES>
368 $<TARGET_PROPERTY:Python3::NumPy,INTERFACE_INCLUDE_DIRECTORIES>
369 ${pybind11_INCLUDE_DIRS}
370 )
371
372 target_compile_definitions(ortcustomops PRIVATE
373 $<TARGET_PROPERTY:Python3::Module,INTERFACE_COMPILE_DEFINITIONS>)
374
375 target_link_libraries(ortcustomops PRIVATE Python3::Module)
376
377 if(NOT "${OCOS_EXTENTION_NAME}" STREQUAL "")
378 if(NOT WIN32)
379 set_target_properties(ortcustomops PROPERTIES
380 LIBRARY_OUTPUT_NAME ${OCOS_EXTENTION_NAME}
381 PREFIX ""
382 SUFFIX "")
383 endif()
384 endif()
385endif()
386
387# clean up the requirements.txt files from 3rd party project folder to suppress the code security false alarms
388file(GLOB_RECURSE NO_USE_FILES ${CMAKE_BINARY_DIR}/_deps/*requirements.txt)
389message("Found the follow requirements.txt: ${NO_USE_FILES}")
390foreach(nf ${NO_USE_FILES})
391 file(TO_NATIVE_PATH ${nf} nf_native)
392 if (CMAKE_SYSTEM_NAME MATCHES "Windows")
393 execute_process(COMMAND cmd /c "del ${nf_native}")
394 else()
395 execute_process(COMMAND bash -c "rm ${nf_native}")
396 endif()
397endforeach()
398
399# test section
400if (OCOS_ENABLE_CTEST)
401 # Enable CTest
402 SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
403 find_library(ONNXRUNTIME onnxruntime HINTS "${ONNXRUNTIME_LIB_DIR}")
404 if (NOT ONNXRUNTIME)
405 message(FATAL_ERROR "The ctest needs the prebuilt onnxruntime libraries directory, please specify it by ONNXRUNTIME_LIB_DIR.")
406 endif()
407
408 enable_testing()
409 message(STATUS "Fetch CTest")
410 include(CTest)
411
412 set(TEST_SRC_DIR ${PROJECT_SOURCE_DIR}/test)
413 message(STATUS "Fetch googletest")
414 include(googletest)
415 file(GLOB static_TEST_SRC "${TEST_SRC_DIR}/static_test/*.cc")
416 add_executable(operators_test ${static_TEST_SRC})
417 standardize_output_folder(operators_test)
418 target_link_libraries(operators_test PRIVATE gtest_main ocos_operators ${ocos_libraries})
419 add_test(NAME operators_test COMMAND $<TARGET_FILE:operators_test>)
420
421 set(LINUX_CC_FLAGS "")
422 # needs to link with stdc++fs in Linux
423 if(UNIX AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME STREQUAL "Android")
424 list(APPEND LINUX_CC_FLAGS stdc++fs -pthread)
425 endif()
426
427 file(GLOB shared_TEST_SRC "${TEST_SRC_DIR}/shared_test/*.cc")
428 add_executable(ortcustomops_test ${shared_TEST_SRC})
429 standardize_output_folder(ortcustomops_test)
430 if (ONNXRUNTIME_LIB_DIR)
431 target_link_directories(ortcustomops_test PRIVATE ${ONNXRUNTIME_LIB_DIR})
432 endif()
433 target_link_libraries(ortcustomops_test PRIVATE ortcustomops onnxruntime gtest_main ${ocos_libraries} ${LINUX_CC_FLAGS})
434 if (WIN32)
435 file(TO_CMAKE_PATH "${ONNXRUNTIME_LIB_DIR}/*" ONNXRUNTIME_LIB_FILEPATTERN)
436 file(GLOB ONNXRUNTIME_LIB_FILES CONFIGURE_DEPENDS "${ONNXRUNTIME_LIB_FILEPATTERN}")
437 add_custom_command(
438 TARGET ortcustomops_test POST_BUILD
439 COMMAND ${CMAKE_COMMAND} -E copy ${ONNXRUNTIME_LIB_FILES} $<TARGET_FILE_DIR:ortcustomops_test>)
440 endif()
441
442 set(TEST_DATA_SRC ${TEST_SRC_DIR}/data)
443 set(TEST_DATA_DES ${onnxruntime_extensions_BINARY_DIR}/data)
444
445 # Copy test data from source to destination.
446 add_custom_command(
447 TARGET ortcustomops_test POST_BUILD
448 COMMAND ${CMAKE_COMMAND} -E copy_directory
449 ${TEST_DATA_SRC}
450 ${TEST_DATA_DES})
451 add_test(NAME ortcustomops_test COMMAND $<TARGET_FILE:ortcustomops_test>)
452endif()
453