2022-12-07 21:37:05 +03:00
|
|
|
cmake_minimum_required(VERSION 3.20)
|
2021-05-12 22:02:57 +03:00
|
|
|
project(onnxruntime_extensions LANGUAGES C CXX)
|
2020-10-20 22:53:14 +03:00
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
# set(CMAKE_VERBOSE_MAKEFILE ON)
|
2020-10-20 22:53:14 +03:00
|
|
|
if(NOT CMAKE_BUILD_TYPE)
|
|
|
|
message(STATUS "Build type not set - using RelWithDebInfo")
|
|
|
|
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose build type: Debug Release RelWithDebInfo." FORCE)
|
|
|
|
endif()
|
|
|
|
|
2022-12-16 21:14:28 +03:00
|
|
|
function(read_version_file major_var minor_var patch_var)
|
|
|
|
set(version_file ${PROJECT_SOURCE_DIR}/version.txt)
|
|
|
|
file(READ ${version_file} version_file_content)
|
2023-02-28 01:12:37 +03:00
|
|
|
if(version_file_content MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)[\n]?$")
|
2022-12-16 21:14:28 +03:00
|
|
|
set(${major_var} ${CMAKE_MATCH_1} PARENT_SCOPE)
|
|
|
|
set(${minor_var} ${CMAKE_MATCH_2} PARENT_SCOPE)
|
|
|
|
set(${patch_var} ${CMAKE_MATCH_3} PARENT_SCOPE)
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Failed to parse version from file: ${version_file}")
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2021-05-05 03:12:28 +03:00
|
|
|
set(CPACK_PACKAGE_NAME "onnxruntime_extensions")
|
2022-12-16 21:14:28 +03:00
|
|
|
read_version_file(CPACK_PACKAGE_VERSION_MAJOR CPACK_PACKAGE_VERSION_MINOR CPACK_PACKAGE_VERSION_PATCH)
|
2021-05-05 03:12:28 +03:00
|
|
|
set(VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH})
|
|
|
|
|
2023-02-17 07:50:11 +03:00
|
|
|
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
|
|
|
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
|
|
|
|
cmake_policy(SET CMP0135 NEW)
|
|
|
|
cmake_policy(SET CMP0077 NEW)
|
|
|
|
endif()
|
|
|
|
|
2022-10-05 02:22:28 +03:00
|
|
|
# Needed for Java
|
|
|
|
set(CMAKE_C_STANDARD 99)
|
2021-05-05 03:12:28 +03:00
|
|
|
|
2020-12-22 04:12:32 +03:00
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
2020-10-20 22:53:14 +03:00
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
include(CheckLanguage)
|
|
|
|
|
2020-10-21 04:49:41 +03:00
|
|
|
option(CC_OPTIMIZE "Allow compiler optimizations, Set to OFF to disable" ON)
|
2022-10-05 02:22:28 +03:00
|
|
|
option(OCOS_ENABLE_PYTHON "Enable Python component building, (deprecated)" OFF)
|
2021-05-05 03:12:28 +03:00
|
|
|
option(OCOS_ENABLE_CTEST "Enable C++ test" OFF)
|
2021-08-16 21:08:03 +03:00
|
|
|
option(OCOS_ENABLE_CPP_EXCEPTIONS "Enable C++ Exception" ON)
|
2021-02-03 22:17:35 +03:00
|
|
|
option(OCOS_ENABLE_TF_STRING "Enable String Operator Set" ON)
|
2021-08-26 02:09:35 +03:00
|
|
|
option(OCOS_ENABLE_RE2_REGEX "Enable StringRegexReplace and StringRegexSplit" ON)
|
2021-02-03 22:17:35 +03:00
|
|
|
option(OCOS_ENABLE_GPT2_TOKENIZER "Enable the GPT2 tokenizer building" ON)
|
|
|
|
option(OCOS_ENABLE_SPM_TOKENIZER "Enable the SentencePiece tokenizer building" ON)
|
2021-08-27 23:54:02 +03:00
|
|
|
option(OCOS_ENABLE_WORDPIECE_TOKENIZER "Enable the WordpieceTokenizer building" ON)
|
2021-03-11 21:19:49 +03:00
|
|
|
option(OCOS_ENABLE_BERT_TOKENIZER "Enable the BertTokenizer building" ON)
|
2022-06-16 09:22:10 +03:00
|
|
|
option(OCOS_ENABLE_BLINGFIRE "Enable operators depending on the Blingfire library" ON)
|
|
|
|
option(OCOS_ENABLE_MATH "Enable math tensor operators building" ON)
|
|
|
|
option(OCOS_ENABLE_DLIB "Enable operators like Inverse depending on DLIB" ON)
|
2022-11-24 00:40:56 +03:00
|
|
|
option(OCOS_ENABLE_OPENCV_CODECS "Enable cv2 and vision operators that require opencv imgcodecs." ON)
|
|
|
|
option(OCOS_ENABLE_CV2 "Enable the operators in `operators/cv2`" ON)
|
|
|
|
option(OCOS_ENABLE_VISION "Enable the operators in `operators/vision`" ON)
|
2023-01-24 00:52:18 +03:00
|
|
|
|
2021-04-22 07:36:40 +03:00
|
|
|
option(OCOS_ENABLE_STATIC_LIB "Enable generating static library" OFF)
|
2021-08-19 20:38:05 +03:00
|
|
|
option(OCOS_ENABLE_SELECTED_OPLIST "Enable including the selected_ops tool file" OFF)
|
2022-10-05 02:22:28 +03:00
|
|
|
option(OCOS_BUILD_PYTHON "Enable building the Python package" OFF)
|
|
|
|
option(OCOS_BUILD_JAVA "Enable building the Java package" OFF)
|
|
|
|
option(OCOS_BUILD_ANDROID "Enable building the Android package" OFF)
|
2022-12-07 21:37:05 +03:00
|
|
|
option(OCOS_BUILD_APPLE_FRAMEWORK "Enable building of the MacOS/iOS framework" OFF)
|
2021-08-16 21:08:03 +03:00
|
|
|
|
|
|
|
function(disable_all_operators)
|
2023-01-24 00:52:18 +03:00
|
|
|
set(OCOS_ENABLE_RE2_REGEX OFF CACHE INTERNAL "" FORCE)
|
|
|
|
set(OCOS_ENABLE_TF_STRING OFF CACHE INTERNAL "" FORCE)
|
|
|
|
set(OCOS_ENABLE_WORDPIECE_TOKENIZER OFF CACHE INTERNAL "" FORCE)
|
|
|
|
set(OCOS_ENABLE_GPT2_TOKENIZER OFF CACHE INTERNAL "" FORCE)
|
|
|
|
set(OCOS_ENABLE_SPM_TOKENIZER OFF CACHE INTERNAL "" FORCE)
|
|
|
|
set(OCOS_ENABLE_BERT_TOKENIZER OFF CACHE INTERNAL "" FORCE)
|
|
|
|
set(OCOS_ENABLE_BLINGFIRE OFF CACHE INTERNAL "" FORCE)
|
|
|
|
set(OCOS_ENABLE_MATH OFF CACHE INTERNAL "" FORCE)
|
|
|
|
set(OCOS_ENABLE_DLIB OFF CACHE INTERNAL "" FORCE)
|
|
|
|
set(OCOS_ENABLE_OPENCV_CODECS OFF CACHE INTERNAL "" FORCE)
|
|
|
|
set(OCOS_ENABLE_CV2 OFF CACHE INTERNAL "" FORCE)
|
|
|
|
set(OCOS_ENABLE_VISION OFF CACHE INTERNAL "" FORCE)
|
2021-08-16 21:08:03 +03:00
|
|
|
endfunction()
|
|
|
|
|
2023-02-22 20:33:04 +03:00
|
|
|
if (CMAKE_GENERATOR_PLATFORM)
|
|
|
|
# Multi-platform generator
|
|
|
|
set(ocos_target_platform ${CMAKE_GENERATOR_PLATFORM})
|
|
|
|
else()
|
|
|
|
set(ocos_target_platform ${CMAKE_SYSTEM_PROCESSOR})
|
|
|
|
endif()
|
|
|
|
|
2020-10-21 04:49:41 +03:00
|
|
|
if(NOT CC_OPTIMIZE)
|
|
|
|
message("!!!THE COMPILER OPTIMIZATION HAS BEEN DISABLED, DEBUG-ONLY!!!")
|
2020-10-21 20:19:06 +03:00
|
|
|
string(REGEX REPLACE "([\-\/]O[123])" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
|
|
|
|
string(REGEX REPLACE "([\-\/]O[123])" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
|
|
|
|
string(REGEX REPLACE "([\-\/]O[123])" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
|
|
|
|
string(REGEX REPLACE "([\-\/]O[123])" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
|
2020-10-21 04:49:41 +03:00
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(NOT WIN32)
|
2020-10-21 04:49:41 +03:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
|
|
|
|
else()
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Od")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Od")
|
|
|
|
endif()
|
|
|
|
endif()
|
2020-10-20 22:53:14 +03:00
|
|
|
|
2023-02-17 07:50:11 +03:00
|
|
|
if (MSVC)
|
2023-02-22 20:33:04 +03:00
|
|
|
check_cxx_compiler_flag(-sdl HAS_SDL)
|
|
|
|
check_cxx_compiler_flag(-Qspectre HAS_QSPECTRE)
|
|
|
|
if (HAS_QSPECTRE)
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Qspectre")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qspectre")
|
|
|
|
endif()
|
2023-02-17 07:50:11 +03:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DYNAMICBASE")
|
|
|
|
check_cxx_compiler_flag(-guard:cf HAS_GUARD_CF)
|
|
|
|
if (HAS_GUARD_CF)
|
|
|
|
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /guard:cf")
|
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /guard:cf")
|
|
|
|
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /guard:cf")
|
|
|
|
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /guard:cf")
|
|
|
|
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} /guard:cf")
|
|
|
|
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /guard:cf")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /guard:cf")
|
|
|
|
endif()
|
|
|
|
endif()
|
2023-01-24 00:52:18 +03:00
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(NOT OCOS_BUILD_PYTHON AND OCOS_ENABLE_PYTHON)
|
2022-10-05 02:22:28 +03:00
|
|
|
message("OCOS_ENABLE_PYTHON IS DEPRECATED, USE OCOS_BUILD_PYTHON INSTEAD")
|
|
|
|
set(OCOS_BUILD_PYTHON ON CACHE INTERNAL "")
|
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_BUILD_ANDROID)
|
2023-01-02 07:55:31 +03:00
|
|
|
if(NOT CMAKE_TOOLCHAIN_FILE MATCHES "android.toolchain.cmake")
|
|
|
|
message(FATAL_ERROR "CMAKE_TOOLCHAIN_FILE must be set to build/cmake/android.toolchain.cmake from the Android NDK.")
|
|
|
|
endif()
|
2023-01-14 01:06:00 +03:00
|
|
|
if(NOT ANDROID_PLATFORM OR NOT ANDROID_ABI)
|
|
|
|
message(FATAL_ERROR "The Android platform (ANDROID_PLATFORM) and ABI (ANDROID_ABI) must be specified.")
|
2022-10-05 02:22:28 +03:00
|
|
|
endif()
|
2022-12-10 01:30:24 +03:00
|
|
|
|
2022-10-05 02:22:28 +03:00
|
|
|
set(OCOS_BUILD_JAVA ON CACHE INTERNAL "")
|
|
|
|
endif()
|
|
|
|
|
2021-01-12 00:44:17 +03:00
|
|
|
# Build the libraries with -fPIC
|
|
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
|
|
|
2022-08-04 20:13:17 +03:00
|
|
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
|
|
|
|
2020-10-20 22:53:14 +03:00
|
|
|
set(CMAKE_FIND_FRAMEWORK NEVER CACHE STRING "...")
|
2022-12-10 01:30:24 +03:00
|
|
|
|
2020-10-20 22:53:14 +03:00
|
|
|
if(NOT "${CMAKE_FIND_FRAMEWORK}" STREQUAL "NEVER")
|
|
|
|
message(FATAL_ERROR "CMAKE_FIND_FRAMEWORK is not NEVER")
|
|
|
|
endif()
|
|
|
|
|
2020-11-13 03:46:49 +03:00
|
|
|
# External dependencies
|
2021-08-16 21:08:03 +03:00
|
|
|
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/externals ${PROJECT_SOURCE_DIR}/cmake)
|
|
|
|
|
2023-02-27 21:31:44 +03:00
|
|
|
# PROJECT_IS_TOP_LEVEL is available since 3.21
|
|
|
|
get_property(not_top DIRECTORY PROPERTY PARENT_DIRECTORY)
|
|
|
|
if(not_top AND ONNXRUNTIME_ROOT)
|
|
|
|
set(_ONNXRUNTIME_EMBEDDED TRUE)
|
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_SELECTED_OPLIST)
|
2021-08-24 22:31:05 +03:00
|
|
|
# Need to ensure _selectedoplist.cmake file is already generated in folder: ${PROJECT_SOURCE_DIR}/cmake/
|
|
|
|
# You could run gen_selectedops.py in folder: tools/ to generate _selectedoplist.cmake
|
2021-08-16 21:08:03 +03:00
|
|
|
message(STATUS "Looking for the _selectedoplist.cmake")
|
|
|
|
disable_all_operators()
|
2021-07-30 22:43:47 +03:00
|
|
|
include(_selectedoplist)
|
|
|
|
endif()
|
|
|
|
|
2023-02-27 21:31:44 +03:00
|
|
|
set(_OCOS_EXCEPTIONS_REQUIRED OFF)
|
|
|
|
if (OCOS_ENABLE_GPT2_TOKENIZER OR
|
|
|
|
OCOS_ENABLE_WORDPIECE_TOKENIZER OR
|
|
|
|
OCOS_ENABLE_BLINGFIRE OR
|
|
|
|
OCOS_ENABLE_SPM_TOKENIZER OR
|
|
|
|
(OCOS_ENABLE_CV2 OR OCOS_ENABLE_OPENCV_CODECS OR OCOS_ENABLE_VISION))
|
|
|
|
set(_OCOS_EXCEPTIONS_REQUIRED ON)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Special case an embedded build with ORT exceptions disabled but custom ops that require exceptions.
|
|
|
|
# Allow using an override so we can do a direct build of ort-ext in a CI without having to embed it in an ORT build.
|
|
|
|
set(_OCOS_PREVENT_EXCEPTION_PROPAGATION OFF)
|
|
|
|
if (_OCOS_PREVENT_EXCEPTION_PROPAGATION_OVERRIDE)
|
|
|
|
set(_OCOS_PREVENT_EXCEPTION_PROPAGATION ${_OCOS_PREVENT_EXCEPTION_PROPAGATION_OVERRIDE})
|
|
|
|
elseif(_ONNXRUNTIME_EMBEDDED AND onnxruntime_DISABLE_EXCEPTIONS AND _OCOS_EXCEPTIONS_REQUIRED)
|
|
|
|
set(_OCOS_PREVENT_EXCEPTION_PROPAGATION ON)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (_OCOS_PREVENT_EXCEPTION_PROPAGATION)
|
|
|
|
message(STATUS "Embedded build as part of ONNX Runtime with exceptions disabled. "
|
|
|
|
"Extensions will be built with exceptions enabled due to included custom ops "
|
|
|
|
"using 3rd party libraries that require exceptions.")
|
|
|
|
|
|
|
|
if (NOT OCOS_ENABLE_CPP_EXCEPTIONS)
|
|
|
|
message(WARNING "Enabling C++ exception support as custom ops included in the build require them to be enabled.")
|
|
|
|
set(OCOS_ENABLE_CPP_EXCEPTIONS ON)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# undo the flags that ORT has set to disable exceptions.
|
|
|
|
# see https://github.com/microsoft/onnxruntime/blob/b1abb8c656c597bf221bd85682ae3d9e350d9aba/cmake/adjust_global_compile_flags.cmake#L160-L169
|
|
|
|
if(MSVC)
|
|
|
|
string(REPLACE "/EHs-c-" "/EHsc" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
|
|
|
else()
|
|
|
|
string(REPLACE "-fno-exceptions" "-fexceptions" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
|
|
|
|
string(REPLACE "-fno-unwind-tables" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
|
|
|
|
string(REPLACE "-fno-asynchronous-unwind-tables" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# the ort-ext code has to provide a barrier between the exception enabled custom op code and ORT.
|
|
|
|
add_compile_definitions(OCOS_PREVENT_EXCEPTION_PROPAGATION)
|
|
|
|
endif()
|
|
|
|
|
2021-08-16 21:08:03 +03:00
|
|
|
if(NOT OCOS_ENABLE_CPP_EXCEPTIONS)
|
|
|
|
add_compile_definitions(OCOS_NO_EXCEPTIONS ORT_NO_EXCEPTIONS)
|
|
|
|
endif()
|
|
|
|
|
2020-11-13 03:46:49 +03:00
|
|
|
include(FetchContent)
|
2021-08-26 02:09:35 +03:00
|
|
|
|
2023-02-17 07:50:11 +03:00
|
|
|
function(set_msvc_c_cpp_compiler_warning_level warning_level)
|
|
|
|
if (NOT "${warning_level}" MATCHES "^[0-4]$")
|
|
|
|
message(FATAL_ERROR "Expected warning_level value of 0-4, got '${warning_level}'.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (MSVC)
|
|
|
|
set(warning_flag "/W${warning_level}")
|
|
|
|
get_property(opts DIRECTORY PROPERTY COMPILE_OPTIONS)
|
|
|
|
# only match the generator expression added by this function
|
|
|
|
list(FILTER opts
|
|
|
|
EXCLUDE REGEX "^\\$<\\$<OR:\\$<COMPILE_LANGUAGE:C>,\\$<COMPILE_LANGUAGE:CXX>>:/W[0-4]>$")
|
|
|
|
list(APPEND opts "$<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:${warning_flag}>")
|
|
|
|
set_property(DIRECTORY PROPERTY COMPILE_OPTIONS "${opts}")
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# set default MSVC warning level to 3 for external dependencies
|
|
|
|
set_msvc_c_cpp_compiler_warning_level(3)
|
2022-12-10 01:30:24 +03:00
|
|
|
include(ext_ortlib)
|
2023-01-24 05:11:00 +03:00
|
|
|
include(gsl)
|
|
|
|
|
2023-02-24 04:44:13 +03:00
|
|
|
macro(standardize_output_folder bin_target)
|
|
|
|
set_target_properties(${bin_target} PROPERTIES
|
|
|
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
|
|
|
|
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
|
|
|
|
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
|
|
|
|
PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
|
|
|
endmacro()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_RE2_REGEX)
|
|
|
|
if(NOT TARGET re2::re2)
|
2021-04-22 07:36:40 +03:00
|
|
|
set(RE2_BUILD_TESTING OFF CACHE INTERNAL "")
|
2021-05-05 03:12:28 +03:00
|
|
|
message(STATUS "Fetch googlere2")
|
2021-04-22 07:36:40 +03:00
|
|
|
include(googlere2)
|
|
|
|
endif()
|
|
|
|
|
2021-04-14 09:01:29 +03:00
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
|
2021-08-26 02:09:35 +03:00
|
|
|
set_property(TARGET re2 PROPERTY COMPILE_OPTIONS)
|
2021-04-14 09:01:29 +03:00
|
|
|
endif()
|
2021-02-03 22:17:35 +03:00
|
|
|
endif()
|
2020-11-13 03:46:49 +03:00
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
# ### scan all source files
|
2023-02-24 04:44:13 +03:00
|
|
|
set(TARGET_SRC_NOEXCEPTION)
|
2023-02-27 21:31:44 +03:00
|
|
|
file(GLOB TARGET_SRC "operators/*.cc" "operators/*.h" "includes/*.h*")
|
2022-12-10 01:30:24 +03:00
|
|
|
|
|
|
|
if(OCOS_ENABLE_TF_STRING)
|
2021-09-28 02:04:46 +03:00
|
|
|
set(farmhash_SOURCE_DIR ${PROJECT_SOURCE_DIR}/cmake/externals/farmhash)
|
2021-05-05 03:12:28 +03:00
|
|
|
file(GLOB TARGET_SRC_KERNELS "operators/text/*.cc" "operators/text/*.h*")
|
2021-02-03 22:17:35 +03:00
|
|
|
file(GLOB TARGET_SRC_HASH "${farmhash_SOURCE_DIR}/src/farmhash.*")
|
2023-02-24 04:44:13 +03:00
|
|
|
list(APPEND TARGET_SRC_NOEXCEPTION ${TARGET_SRC_KERNELS} ${TARGET_SRC_HASH})
|
2021-02-03 22:17:35 +03:00
|
|
|
endif()
|
2020-11-13 01:59:00 +03:00
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_RE2_REGEX)
|
2021-09-02 21:19:18 +03:00
|
|
|
file(GLOB TARGET_SRC_RE2_KERNELS "operators/text/re2_strings/*.cc" "operators/text/re2_strings/*.h*")
|
2023-02-24 04:44:13 +03:00
|
|
|
list(APPEND TARGET_SRC_NOEXCEPTION ${TARGET_SRC_RE2_KERNELS})
|
2021-09-02 21:19:18 +03:00
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_MATH)
|
2021-09-10 20:23:35 +03:00
|
|
|
if(OCOS_ENABLE_DLIB)
|
|
|
|
set(DLIB_ISO_CPP_ONLY ON CACHE INTERNAL "")
|
|
|
|
set(DLIB_NO_GUI_SUPPORT ON CACHE INTERNAL "")
|
|
|
|
set(DLIB_USE_CUDA OFF CACHE INTERNAL "")
|
|
|
|
set(DLIB_USE_LAPACK OFF CACHE INTERNAL "")
|
|
|
|
set(DLIB_USE_BLAS OFF CACHE INTERNAL "")
|
|
|
|
include(dlib)
|
2022-12-10 01:30:24 +03:00
|
|
|
|
2021-09-10 20:23:35 +03:00
|
|
|
# Ideally, dlib should be included as
|
2022-12-10 01:30:24 +03:00
|
|
|
# file(GLOB TARGET_SRC_DLIB "${dlib_SOURCE_DIR}/dlib/all/source.cpp")
|
2021-09-10 20:23:35 +03:00
|
|
|
# To avoid the unintentional using some unwanted component, only include
|
|
|
|
file(GLOB TARGET_SRC_DLIB "${dlib_SOURCE_DIR}/dlib/test_for_odr_violations.cpp")
|
|
|
|
file(GLOB TARGET_SRC_INVERSE "operators/math/dlib/*.cc" "operators/math/dlib/*.h*")
|
|
|
|
endif()
|
2022-12-10 01:30:24 +03:00
|
|
|
|
2021-05-05 03:12:28 +03:00
|
|
|
file(GLOB TARGET_SRC_MATH "operators/math/*.cc" "operators/math/*.h*")
|
2021-09-10 20:23:35 +03:00
|
|
|
list(APPEND TARGET_SRC ${TARGET_SRC_MATH} ${TARGET_SRC_DLIB} ${TARGET_SRC_INVERSE})
|
2021-05-05 03:12:28 +03:00
|
|
|
endif()
|
|
|
|
|
2022-11-24 00:40:56 +03:00
|
|
|
# enable the opencv dependency if we have ops that require it
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_CV2 OR OCOS_ENABLE_VISION)
|
2022-11-24 00:40:56 +03:00
|
|
|
set(_ENABLE_OPENCV ON)
|
2022-05-12 02:51:59 +03:00
|
|
|
message(STATUS "Fetch opencv")
|
|
|
|
include(opencv)
|
2022-11-24 00:40:56 +03:00
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_CV2)
|
2022-11-24 00:40:56 +03:00
|
|
|
file(GLOB TARGET_SRC_CV2 "operators/cv2/*.cc" "operators/cv2/*.h*")
|
2022-12-20 06:47:17 +03:00
|
|
|
file(GLOB TARGET_SRC_CV2_IMGPROC_OPS "operators/cv2/imgproc/*.cc" "operators/cv2/imgproc/*.h*")
|
|
|
|
file(GLOB TARGET_SRC_CV2_IMGCODECS_OPS "operators/cv2/imgcodecs/*.cc" "operators/cv2/imgcodecs/*.h*")
|
|
|
|
|
2022-11-24 00:40:56 +03:00
|
|
|
list(APPEND TARGET_SRC ${TARGET_SRC_CV2})
|
2022-12-20 06:47:17 +03:00
|
|
|
list(APPEND TARGET_SRC ${TARGET_SRC_CV2_IMGPROC_OPS})
|
|
|
|
if (OCOS_ENABLE_OPENCV_CODECS)
|
|
|
|
list(APPEND TARGET_SRC ${TARGET_SRC_CV2_IMGCODECS_OPS})
|
|
|
|
endif()
|
2022-11-24 00:40:56 +03:00
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_VISION)
|
|
|
|
if(NOT OCOS_ENABLE_OPENCV_CODECS)
|
|
|
|
message(FATAL_ERROR "OCOS_ENABLE_VISION requires OCOS_ENABLE_OPENCV_CODECS to be ON")
|
2022-11-24 00:40:56 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
file(GLOB TARGET_SRC_VISION "operators/vision/*.cc" "operators/vision/*.h*")
|
|
|
|
list(APPEND TARGET_SRC ${TARGET_SRC_VISION})
|
2022-05-12 02:51:59 +03:00
|
|
|
endif()
|
|
|
|
|
2021-08-26 21:04:45 +03:00
|
|
|
set(_HAS_TOKENIZER OFF)
|
2022-12-10 01:30:24 +03:00
|
|
|
|
|
|
|
if(OCOS_ENABLE_GPT2_TOKENIZER)
|
2021-01-28 01:55:50 +03:00
|
|
|
# GPT2
|
2021-08-26 21:04:45 +03:00
|
|
|
set(_HAS_TOKENIZER ON)
|
2022-12-14 02:52:47 +03:00
|
|
|
file(GLOB tok_TARGET_SRC "operators/tokenizer/gpt*.cc" "operators/tokenizer/unicode*.*" "operators/tokenizer/clip*.cc")
|
2020-12-22 04:12:32 +03:00
|
|
|
list(APPEND TARGET_SRC ${tok_TARGET_SRC})
|
2021-02-03 22:17:35 +03:00
|
|
|
endif()
|
2021-03-11 21:19:49 +03:00
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_SPM_TOKENIZER)
|
2021-01-28 01:55:50 +03:00
|
|
|
# SentencePiece
|
2021-08-26 21:04:45 +03:00
|
|
|
set(_HAS_TOKENIZER ON)
|
2021-02-03 22:17:35 +03:00
|
|
|
set(SPM_ENABLE_TCMALLOC OFF CACHE INTERNAL "")
|
|
|
|
set(SPM_ENABLE_SHARED OFF CACHE INTERNAL "")
|
2021-05-05 03:12:28 +03:00
|
|
|
message(STATUS "Fetch sentencepiece")
|
2021-01-28 01:55:50 +03:00
|
|
|
include(sentencepieceproject)
|
2021-05-05 03:12:28 +03:00
|
|
|
file(GLOB stpiece_TARGET_SRC "operators/tokenizer/sentencepiece/*.cc" "operators/tokenizer/sentencepiece*")
|
2021-01-28 01:55:50 +03:00
|
|
|
list(REMOVE_ITEM stpiece_TARGET_SRC INCLUDE REGEX ".*((spm)|(train)).*")
|
|
|
|
list(APPEND TARGET_SRC ${stpiece_TARGET_SRC})
|
2020-12-22 04:12:32 +03:00
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_WORDPIECE_TOKENIZER)
|
2021-08-27 23:54:02 +03:00
|
|
|
set(_HAS_TOKENIZER ON)
|
|
|
|
file(GLOB wordpiece_TARGET_SRC "operators/tokenizer/wordpiece*.*")
|
|
|
|
list(APPEND TARGET_SRC ${wordpiece_TARGET_SRC})
|
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_BERT_TOKENIZER)
|
2021-03-11 21:19:49 +03:00
|
|
|
# Bert
|
2021-08-26 21:04:45 +03:00
|
|
|
set(_HAS_TOKENIZER ON)
|
2022-12-10 01:30:24 +03:00
|
|
|
file(GLOB bert_TARGET_SRC "operators/tokenizer/basic_tokenizer.*" "operators/tokenizer/bert_tokenizer.*" "operators/tokenizer/bert_tokenizer_decoder.*")
|
2021-03-11 21:19:49 +03:00
|
|
|
list(APPEND TARGET_SRC ${bert_TARGET_SRC})
|
|
|
|
endif()
|
2021-02-16 14:22:53 +03:00
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_BLINGFIRE)
|
2021-08-26 21:04:45 +03:00
|
|
|
# blingfire
|
|
|
|
set(_HAS_TOKENIZER ON)
|
|
|
|
file(GLOB blingfire_TARGET_SRC "operators/tokenizer/blingfire*.*")
|
|
|
|
list(APPEND TARGET_SRC ${blingfire_TARGET_SRC})
|
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_GPT2_TOKENIZER OR OCOS_ENABLE_WORDPIECE_TOKENIZER)
|
|
|
|
if(NOT TARGET nlohmann_json)
|
2021-08-16 21:08:03 +03:00
|
|
|
set(JSON_BuildTests OFF CACHE INTERNAL "")
|
|
|
|
message(STATUS "Fetch json")
|
|
|
|
include(json)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(_HAS_TOKENIZER)
|
2021-08-26 21:04:45 +03:00
|
|
|
message(STATUS "Tokenizer needed.")
|
|
|
|
file(GLOB tokenizer_TARGET_SRC "operators/tokenizer/tokenizers.*")
|
|
|
|
list(APPEND TARGET_SRC ${tokenizer_TARGET_SRC})
|
2021-06-24 09:29:16 +03:00
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
# ### make all compile options.
|
2021-02-16 14:22:53 +03:00
|
|
|
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
|
|
|
|
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
|
2023-02-24 04:44:13 +03:00
|
|
|
add_library(noexcep_operators STATIC ${TARGET_SRC_NOEXCEPTION})
|
2021-05-30 06:17:15 +03:00
|
|
|
add_library(ocos_operators STATIC ${TARGET_SRC})
|
2023-02-22 20:33:04 +03:00
|
|
|
# TODO: need to address the SDL warnings happens on custom operator code.
|
|
|
|
# if (HAS_SDL)
|
|
|
|
# target_compile_options(ocos_operators PRIVATE "/sdl")
|
|
|
|
# endif()
|
2023-02-24 04:44:13 +03:00
|
|
|
set_target_properties(noexcep_operators PROPERTIES FOLDER "operators")
|
2022-11-24 00:40:56 +03:00
|
|
|
set_target_properties(ocos_operators PROPERTIES FOLDER "operators")
|
2022-12-07 21:37:05 +03:00
|
|
|
|
|
|
|
# filter out any files in ${TARGET_SRC} which don't have prefix of ${PROJECT_SOURCE_DIR} before calling source_group
|
|
|
|
set(_TARGET_SRC_FOR_SOURCE_GROUP)
|
|
|
|
foreach(_TARGET_SRC_FILE IN LISTS TARGET_SRC)
|
|
|
|
cmake_path(IS_PREFIX PROJECT_SOURCE_DIR ${_TARGET_SRC_FILE}
|
|
|
|
NORMALIZE
|
|
|
|
_is_prefix_result)
|
|
|
|
if(_is_prefix_result)
|
|
|
|
list(APPEND _TARGET_SRC_FOR_SOURCE_GROUP ${_TARGET_SRC_FILE})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
source_group(TREE ${PROJECT_SOURCE_DIR} FILES ${_TARGET_SRC_FOR_SOURCE_GROUP})
|
|
|
|
|
2023-02-24 04:44:13 +03:00
|
|
|
standardize_output_folder(noexcep_operators)
|
2022-05-12 02:51:59 +03:00
|
|
|
standardize_output_folder(ocos_operators)
|
2021-02-03 22:17:35 +03:00
|
|
|
|
2023-02-24 04:44:13 +03:00
|
|
|
target_include_directories(noexcep_operators PUBLIC
|
|
|
|
${ONNXRUNTIME_INCLUDE_DIR}
|
|
|
|
${PROJECT_SOURCE_DIR}/includes
|
|
|
|
${PROJECT_SOURCE_DIR}/operators)
|
|
|
|
|
2021-05-30 06:17:15 +03:00
|
|
|
target_include_directories(ocos_operators PUBLIC
|
2022-12-10 01:30:24 +03:00
|
|
|
${ONNXRUNTIME_INCLUDE_DIR}
|
2021-02-03 22:17:35 +03:00
|
|
|
${PROJECT_SOURCE_DIR}/includes
|
2022-05-12 02:51:59 +03:00
|
|
|
${PROJECT_SOURCE_DIR}/operators
|
|
|
|
${PROJECT_SOURCE_DIR}/operators/tokenizer)
|
2023-02-24 04:44:13 +03:00
|
|
|
|
|
|
|
set(ocos_libraries)
|
|
|
|
set(OCOS_COMPILE_DEFINITIONS)
|
2021-02-03 22:17:35 +03:00
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_DLIB)
|
2022-05-12 02:51:59 +03:00
|
|
|
list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_DLIB)
|
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(_HAS_TOKENIZER)
|
2022-05-12 02:51:59 +03:00
|
|
|
list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_TOKENIZER)
|
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_TF_STRING)
|
2023-02-24 04:44:13 +03:00
|
|
|
target_include_directories(noexcep_operators PUBLIC
|
2021-02-03 22:17:35 +03:00
|
|
|
${googlere2_SOURCE_DIR}
|
|
|
|
${farmhash_SOURCE_DIR}/src)
|
2022-08-02 20:09:35 +03:00
|
|
|
list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_TF_STRING NOMINMAX FARMHASH_NO_BUILTIN_EXPECT FARMHASH_DEBUG=0)
|
2023-02-24 04:44:13 +03:00
|
|
|
target_link_libraries(noexcep_operators PRIVATE re2)
|
2021-02-03 22:17:35 +03:00
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_RE2_REGEX)
|
2021-08-26 02:09:35 +03:00
|
|
|
list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_RE2_REGEX)
|
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_MATH)
|
2021-05-30 06:17:15 +03:00
|
|
|
target_include_directories(ocos_operators PUBLIC ${dlib_SOURCE_DIR})
|
2021-05-05 03:12:28 +03:00
|
|
|
list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_MATH)
|
2021-08-26 21:04:45 +03:00
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(_ENABLE_OPENCV)
|
2022-05-12 02:51:59 +03:00
|
|
|
list(APPEND ocos_libraries ${opencv_LIBS})
|
2022-09-23 21:16:44 +03:00
|
|
|
target_include_directories(ocos_operators PUBLIC ${opencv_INCLUDE_DIRS})
|
2021-05-05 03:12:28 +03:00
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_OPENCV_CODECS)
|
2022-11-24 00:40:56 +03:00
|
|
|
list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_OPENCV_CODECS)
|
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_CV2)
|
2022-11-24 00:40:56 +03:00
|
|
|
list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_CV2)
|
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_VISION)
|
2022-11-24 00:40:56 +03:00
|
|
|
list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_VISION)
|
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_GPT2_TOKENIZER)
|
2021-02-03 22:17:35 +03:00
|
|
|
# GPT2
|
|
|
|
list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_GPT2_TOKENIZER)
|
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_WORDPIECE_TOKENIZER)
|
2021-08-27 23:54:02 +03:00
|
|
|
list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_WORDPIECE_TOKENIZER)
|
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_BERT_TOKENIZER)
|
2021-08-16 21:08:03 +03:00
|
|
|
list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_BERT_TOKENIZER)
|
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_SPM_TOKENIZER)
|
2021-02-03 22:17:35 +03:00
|
|
|
# SentencePiece
|
2021-09-25 10:40:12 +03:00
|
|
|
target_include_directories(ocos_operators PUBLIC ${spm_INCLUDE_DIRS})
|
2021-02-03 22:17:35 +03:00
|
|
|
list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_SPM_TOKENIZER)
|
|
|
|
list(APPEND ocos_libraries sentencepiece-static)
|
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_BLINGFIRE)
|
2021-06-24 09:29:16 +03:00
|
|
|
include(blingfire)
|
|
|
|
list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_BLINGFIRE)
|
|
|
|
list(APPEND ocos_libraries bingfirtinydll_static)
|
|
|
|
endif()
|
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(OCOS_ENABLE_GPT2_TOKENIZER OR OCOS_ENABLE_WORDPIECE_TOKENIZER)
|
2021-08-26 21:04:45 +03:00
|
|
|
target_include_directories(ocos_operators PRIVATE ${json_SOURCE_DIR}/single_include)
|
|
|
|
list(APPEND ocos_libraries nlohmann_json::nlohmann_json)
|
|
|
|
endif()
|
|
|
|
|
2023-01-24 05:11:00 +03:00
|
|
|
target_include_directories(ocos_operators PRIVATE ${GSL_INCLUDE_DIR})
|
|
|
|
list(APPEND ocos_libraries Microsoft.GSL::GSL)
|
|
|
|
|
2021-08-26 21:04:45 +03:00
|
|
|
list(REMOVE_DUPLICATES OCOS_COMPILE_DEFINITIONS)
|
2023-02-24 04:44:13 +03:00
|
|
|
target_compile_definitions(noexcep_operators PRIVATE ${OCOS_COMPILE_DEFINITIONS})
|
|
|
|
if(NOT OCOS_ENABLE_CPP_EXCEPTIONS)
|
|
|
|
if(MSVC)
|
|
|
|
get_target_property(_target_cxx_flags noexcep_operators COMPILE_OPTIONS)
|
|
|
|
list(REMOVE_ITEM _target_cxx_flags "/EHsc")
|
|
|
|
list(APPEND _target_cxx_flags "/EHs-c-")
|
|
|
|
set_target_properties(noexcep_operators PROPERTIES COMPILE_OPTIONS "${_target_cxx_flags}")
|
|
|
|
else()
|
|
|
|
target_compile_options(noexcep_operators PRIVATE -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
list(APPEND ocos_libraries noexcep_operators)
|
2021-05-30 06:17:15 +03:00
|
|
|
target_compile_definitions(ocos_operators PRIVATE ${OCOS_COMPILE_DEFINITIONS})
|
2021-08-17 08:21:12 +03:00
|
|
|
target_link_libraries(ocos_operators PRIVATE ${ocos_libraries})
|
2021-02-03 22:17:35 +03:00
|
|
|
|
2022-10-05 02:22:28 +03:00
|
|
|
file(GLOB shared_TARGET_LIB_SRC "shared/lib/*.cc" "shared/lib/*.h")
|
2022-12-10 01:30:24 +03:00
|
|
|
|
2022-11-22 10:03:46 +03:00
|
|
|
if(NOT OCOS_ENABLE_STATIC_LIB AND CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
|
2022-10-05 02:22:28 +03:00
|
|
|
add_executable(ortcustomops ${shared_TARGET_LIB_SRC})
|
2021-05-30 06:17:15 +03:00
|
|
|
set_target_properties(ortcustomops PROPERTIES LINK_FLAGS " \
|
2021-04-14 09:01:29 +03:00
|
|
|
-s WASM=1 \
|
|
|
|
-s NO_EXIT_RUNTIME=0 \
|
|
|
|
-s ALLOW_MEMORY_GROWTH=1 \
|
|
|
|
-s SAFE_HEAP=0 \
|
|
|
|
-s MODULARIZE=1 \
|
|
|
|
-s SAFE_HEAP_LOG=0 \
|
|
|
|
-s STACK_OVERFLOW_CHECK=0 \
|
|
|
|
-s EXPORT_ALL=0 \
|
|
|
|
-s VERBOSE=0 \
|
|
|
|
--no-entry")
|
2022-12-10 01:30:24 +03:00
|
|
|
|
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
2021-04-14 09:01:29 +03:00
|
|
|
set_property(TARGET ortcustomops APPEND_STRING PROPERTY LINK_FLAGS " -s ASSERTIONS=1 -s DEMANGLE_SUPPORT=1")
|
|
|
|
else()
|
|
|
|
set_property(TARGET ortcustomops APPEND_STRING PROPERTY LINK_FLAGS " -s ASSERTIONS=0 -s DEMANGLE_SUPPORT=0")
|
|
|
|
endif()
|
2020-10-21 04:49:41 +03:00
|
|
|
else()
|
2022-10-05 02:22:28 +03:00
|
|
|
add_library(ortcustomops STATIC ${shared_TARGET_LIB_SRC})
|
2023-02-22 20:33:04 +03:00
|
|
|
if (HAS_SDL)
|
|
|
|
target_compile_options(ortcustomops PRIVATE "/sdl")
|
|
|
|
endif()
|
2022-10-05 02:22:28 +03:00
|
|
|
add_library(onnxruntime_extensions ALIAS ortcustomops)
|
2022-05-12 02:51:59 +03:00
|
|
|
standardize_output_folder(ortcustomops)
|
2022-10-05 02:22:28 +03:00
|
|
|
set(_BUILD_SHARED_LIBRARY TRUE)
|
2021-01-12 00:44:17 +03:00
|
|
|
endif()
|
2021-01-28 01:55:50 +03:00
|
|
|
|
2023-02-24 04:44:13 +03:00
|
|
|
target_compile_definitions(ortcustomops PUBLIC ${OCOS_COMPILE_DEFINITIONS})
|
2022-10-05 02:22:28 +03:00
|
|
|
target_include_directories(ortcustomops PUBLIC
|
|
|
|
"$<TARGET_PROPERTY:ocos_operators,INTERFACE_INCLUDE_DIRECTORIES>")
|
2021-08-17 08:21:12 +03:00
|
|
|
target_link_libraries(ortcustomops PUBLIC ocos_operators)
|
2020-10-21 04:49:41 +03:00
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(_BUILD_SHARED_LIBRARY)
|
2022-10-05 02:22:28 +03:00
|
|
|
file(GLOB shared_TARGET_SRC "shared/*.cc" "shared/*.h" "shared/*.def")
|
|
|
|
add_library(extensions_shared SHARED ${shared_TARGET_SRC})
|
2022-11-24 00:40:56 +03:00
|
|
|
source_group(TREE ${PROJECT_SOURCE_DIR} FILES ${shared_TARGET_SRC})
|
2022-10-05 02:22:28 +03:00
|
|
|
standardize_output_folder(extensions_shared)
|
2022-12-10 01:30:24 +03:00
|
|
|
|
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "Android")
|
|
|
|
if(OCOS_ENABLE_SPM_TOKENIZER)
|
2022-10-05 02:22:28 +03:00
|
|
|
target_link_libraries(extensions_shared PUBLIC log)
|
2021-01-12 00:44:17 +03:00
|
|
|
endif()
|
2020-11-13 01:59:00 +03:00
|
|
|
endif()
|
2022-11-24 00:40:56 +03:00
|
|
|
|
2022-12-10 01:30:24 +03:00
|
|
|
if(LINUX OR CMAKE_SYSTEM_NAME STREQUAL "Android")
|
2022-10-05 02:22:28 +03:00
|
|
|
set_property(TARGET extensions_shared APPEND_STRING PROPERTY LINK_FLAGS "-Wl,-s -Wl,--version-script -Wl,${PROJECT_SOURCE_DIR}/shared/ortcustomops.ver")
|
|
|
|
endif()
|
2022-11-24 00:40:56 +03:00
|
|
|
|
2022-10-05 02:22:28 +03:00
|
|
|
target_include_directories(extensions_shared PUBLIC
|
|
|
|
"$<TARGET_PROPERTY:ortcustomops,INTERFACE_INCLUDE_DIRECTORIES>")
|
|
|
|
target_link_libraries(extensions_shared PRIVATE ortcustomops)
|
|
|
|
set_target_properties(extensions_shared PROPERTIES OUTPUT_NAME "ortextensions")
|
2023-02-22 20:33:04 +03:00
|
|
|
if(MSVC AND ocos_target_platform MATCHES "x86|x64")
|
|
|
|
target_link_options(extensions_shared PRIVATE "/CETCOMPAT")
|
|
|
|
endif()
|
|
|
|
|
2022-10-05 02:22:28 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(OCOS_BUILD_PYTHON)
|
|
|
|
message(STATUS "Python Build is enabled")
|
|
|
|
include(ext_python)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(OCOS_BUILD_JAVA)
|
|
|
|
message(STATUS "Java Build is enabled")
|
|
|
|
include(ext_java)
|
2020-10-21 04:49:41 +03:00
|
|
|
endif()
|
|
|
|
|
2022-12-07 21:37:05 +03:00
|
|
|
if(OCOS_BUILD_APPLE_FRAMEWORK)
|
|
|
|
include(ext_apple_framework)
|
|
|
|
endif()
|
|
|
|
|
2022-08-04 20:13:17 +03:00
|
|
|
# clean up the requirements.txt files from 3rd party project folder to suppress the code security false alarms
|
|
|
|
file(GLOB_RECURSE NO_USE_FILES ${CMAKE_BINARY_DIR}/_deps/*requirements.txt)
|
2023-01-02 07:55:31 +03:00
|
|
|
message(STATUS "Found the following requirements.txt: ${NO_USE_FILES}")
|
2022-12-10 01:30:24 +03:00
|
|
|
|
2022-08-04 20:13:17 +03:00
|
|
|
foreach(nf ${NO_USE_FILES})
|
2023-01-02 07:55:31 +03:00
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E remove ${nf})
|
2022-08-04 20:13:17 +03:00
|
|
|
endforeach()
|
2021-02-03 22:17:35 +03:00
|
|
|
|
2020-11-13 01:59:00 +03:00
|
|
|
# test section
|
2023-02-24 04:44:13 +03:00
|
|
|
if(OCOS_ENABLE_CTEST)
|
|
|
|
if (OCOS_ENABLE_SELECTED_OPLIST)
|
|
|
|
# currently the tests don't handle operator exclusion cleanly.
|
2023-02-27 21:31:44 +03:00
|
|
|
message(FATAL_ERROR "Due to usage of OCOS_ENABLE_SELECTED_OPLIST excluding operators the tests are unable to be built and run")
|
2023-02-24 04:44:13 +03:00
|
|
|
endif()
|
|
|
|
|
2021-02-03 22:17:35 +03:00
|
|
|
# Enable CTest
|
|
|
|
enable_testing()
|
2021-05-05 03:12:28 +03:00
|
|
|
message(STATUS "Fetch CTest")
|
2021-02-03 22:17:35 +03:00
|
|
|
include(CTest)
|
|
|
|
|
|
|
|
set(TEST_SRC_DIR ${PROJECT_SOURCE_DIR}/test)
|
2021-05-05 03:12:28 +03:00
|
|
|
message(STATUS "Fetch googletest")
|
2021-02-03 22:17:35 +03:00
|
|
|
include(googletest)
|
|
|
|
file(GLOB static_TEST_SRC "${TEST_SRC_DIR}/static_test/*.cc")
|
2022-10-05 02:22:28 +03:00
|
|
|
add_executable(ocos_test ${static_TEST_SRC})
|
|
|
|
standardize_output_folder(ocos_test)
|
|
|
|
target_link_libraries(ocos_test PRIVATE gtest_main ocos_operators ${ocos_libraries})
|
|
|
|
add_test(NAME ocos_test COMMAND $<TARGET_FILE:ocos_test>)
|
2021-05-30 06:17:15 +03:00
|
|
|
|
2022-10-05 02:22:28 +03:00
|
|
|
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
|
|
|
|
find_library(ONNXRUNTIME onnxruntime HINTS "${ONNXRUNTIME_LIB_DIR}")
|
2022-12-10 01:30:24 +03:00
|
|
|
|
|
|
|
if(ONNXRUNTIME-NOTFOUND)
|
2022-10-05 02:22:28 +03:00
|
|
|
message(WARNING "The prebuilt onnxruntime libraries directory cannot found (via ONNXRUNTIME_LIB_DIR), the extensions_test will be skipped.")
|
|
|
|
else()
|
|
|
|
set(LINUX_CC_FLAGS "")
|
2022-12-10 01:30:24 +03:00
|
|
|
|
2022-10-05 02:22:28 +03:00
|
|
|
# needs to link with stdc++fs in Linux
|
|
|
|
if(UNIX AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME STREQUAL "Android")
|
|
|
|
list(APPEND LINUX_CC_FLAGS stdc++fs -pthread)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
file(GLOB shared_TEST_SRC "${TEST_SRC_DIR}/shared_test/*.cc")
|
|
|
|
add_executable(extensions_test ${shared_TEST_SRC})
|
|
|
|
standardize_output_folder(extensions_test)
|
|
|
|
target_include_directories(extensions_test PRIVATE ${spm_INCLUDE_DIRS}
|
|
|
|
"$<TARGET_PROPERTY:extensions_shared,INTERFACE_INCLUDE_DIRECTORIES>")
|
2022-12-10 01:30:24 +03:00
|
|
|
|
|
|
|
if(ONNXRUNTIME_LIB_DIR)
|
2022-10-05 02:22:28 +03:00
|
|
|
target_link_directories(extensions_test PRIVATE ${ONNXRUNTIME_LIB_DIR})
|
|
|
|
endif()
|
2022-12-10 01:30:24 +03:00
|
|
|
|
2023-02-27 21:31:44 +03:00
|
|
|
target_link_libraries(extensions_test PRIVATE ocos_operators extensions_shared onnxruntime gtest_main gmock_main
|
|
|
|
${ocos_libraries} ${LINUX_CC_FLAGS})
|
2022-12-10 01:30:24 +03:00
|
|
|
|
2023-02-24 04:44:13 +03:00
|
|
|
# Copy ONNXRuntime DLLs into bin folder for testing on Windows platform
|
2022-12-10 01:30:24 +03:00
|
|
|
if(WIN32)
|
2022-10-05 02:22:28 +03:00
|
|
|
file(TO_CMAKE_PATH "${ONNXRUNTIME_LIB_DIR}/*" ONNXRUNTIME_LIB_FILEPATTERN)
|
|
|
|
file(GLOB ONNXRUNTIME_LIB_FILES CONFIGURE_DEPENDS "${ONNXRUNTIME_LIB_FILEPATTERN}")
|
|
|
|
add_custom_command(
|
|
|
|
TARGET extensions_test POST_BUILD
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${ONNXRUNTIME_LIB_FILES} $<TARGET_FILE_DIR:extensions_test>)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(TEST_DATA_SRC ${TEST_SRC_DIR}/data)
|
|
|
|
set(TEST_DATA_DES ${onnxruntime_extensions_BINARY_DIR}/data)
|
2021-02-03 22:17:35 +03:00
|
|
|
|
2022-10-05 02:22:28 +03:00
|
|
|
# Copy test data from source to destination.
|
|
|
|
add_custom_command(
|
|
|
|
TARGET extensions_test POST_BUILD
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
|
|
|
${TEST_DATA_SRC}
|
|
|
|
${TEST_DATA_DES})
|
|
|
|
add_test(NAME extensions_test COMMAND $<TARGET_FILE:extensions_test>)
|
|
|
|
endif()
|
2021-02-03 22:17:35 +03:00
|
|
|
endif()
|