2020-10-21 04:49:41 +03:00
|
|
|
cmake_minimum_required(VERSION 3.16.0)
|
2021-05-12 22:02:57 +03:00
|
|
|
project(onnxruntime_extensions LANGUAGES C CXX)
|
2021-05-31 09:46:33 +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()
|
|
|
|
|
2021-05-05 03:12:28 +03:00
|
|
|
|
|
|
|
set(CPACK_PACKAGE_NAME "onnxruntime_extensions")
|
|
|
|
set(CPACK_PACKAGE_VERSION_MAJOR "0")
|
2021-05-31 09:46:33 +03:00
|
|
|
set(CPACK_PACKAGE_VERSION_MINOR "3")
|
2021-06-04 07:23:13 +03:00
|
|
|
set(CPACK_PACKAGE_VERSION_PATCH "1")
|
2021-05-05 03:12:28 +03:00
|
|
|
set(VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH})
|
|
|
|
|
|
|
|
|
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)
|
2021-02-03 22:17:35 +03:00
|
|
|
option(OCOS_ENABLE_PYTHON "Enable Python component building" 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-03-11 21:19:49 +03:00
|
|
|
option(OCOS_ENABLE_BERT_TOKENIZER "Enable the BertTokenizer building" ON)
|
2021-06-24 09:29:16 +03:00
|
|
|
option(OCOS_ENABLE_BLINGFIRE "Enable the Blingfire building" ON)
|
2021-05-05 03:12:28 +03:00
|
|
|
option(OCOS_ENABLE_MATH "Enable the math tensor operators building" ON)
|
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)
|
2021-04-14 09:01:29 +03:00
|
|
|
|
2021-08-16 21:08:03 +03:00
|
|
|
|
|
|
|
function(disable_all_operators)
|
|
|
|
set(OCOS_ENABLE_TF_STRING OFF CACHE INTERNAL "")
|
|
|
|
set(OCOS_ENABLE_GPT2_TOKENIZER OFF CACHE INTERNAL "")
|
|
|
|
set(OCOS_ENABLE_SPM_TOKENIZER OFF CACHE INTERNAL "")
|
|
|
|
set(OCOS_ENABLE_BERT_TOKENIZER OFF CACHE INTERNAL "")
|
|
|
|
set(OCOS_ENABLE_BLINGFIRE OFF CACHE INTERNAL "")
|
|
|
|
set(OCOS_ENABLE_MATH OFF CACHE INTERNAL "")
|
|
|
|
endfunction()
|
|
|
|
|
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
|
|
|
|
|
|
|
if (NOT WIN32)
|
|
|
|
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
|
|
|
|
2021-01-12 00:44:17 +03:00
|
|
|
# Build the libraries with -fPIC
|
|
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
|
|
|
2020-10-20 22:53:14 +03:00
|
|
|
set(CMAKE_FIND_FRAMEWORK NEVER CACHE STRING "...")
|
|
|
|
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)
|
|
|
|
|
2021-08-19 20:38:05 +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()
|
|
|
|
|
2021-08-16 21:08:03 +03:00
|
|
|
if(NOT OCOS_ENABLE_CPP_EXCEPTIONS)
|
|
|
|
include(noexcep_ops)
|
|
|
|
add_compile_definitions(OCOS_NO_EXCEPTIONS ORT_NO_EXCEPTIONS)
|
|
|
|
if(MSVC)
|
|
|
|
string(REGEX REPLACE "/EHsc" "/EHs-c-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
|
|
|
add_compile_definitions("_HAS_EXCEPTIONS=0")
|
|
|
|
else()
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2020-11-13 03:46:49 +03:00
|
|
|
include(FetchContent)
|
2021-08-26 02:09:35 +03:00
|
|
|
|
|
|
|
if (NOT TARGET farmhash)
|
|
|
|
message(STATUS "Fetch farmhash")
|
|
|
|
include(farmhash)
|
|
|
|
FetchContent_GetProperties(farmhash)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (OCOS_ENABLE_RE2_REGEX)
|
2021-04-22 07:36:40 +03:00
|
|
|
if (NOT TARGET re2::re2)
|
|
|
|
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)
|
|
|
|
FetchContent_GetProperties(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
|
|
|
|
2021-08-26 02:09:35 +03:00
|
|
|
|
2021-05-05 03:12:28 +03:00
|
|
|
file(GLOB TARGET_SRC "operators/*.cc" "operators/*.h")
|
2021-02-03 22:17:35 +03:00
|
|
|
if (OCOS_ENABLE_TF_STRING)
|
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.*")
|
|
|
|
list(APPEND TARGET_SRC ${TARGET_SRC_KERNELS} ${TARGET_SRC_HASH})
|
|
|
|
endif()
|
2020-11-13 01:59:00 +03:00
|
|
|
|
2021-05-05 03:12:28 +03:00
|
|
|
if (OCOS_ENABLE_MATH)
|
|
|
|
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)
|
|
|
|
file(GLOB TARGET_SRC_MATH "operators/math/*.cc" "operators/math/*.h*")
|
|
|
|
list(APPEND TARGET_SRC ${TARGET_SRC_MATH})
|
|
|
|
endif()
|
|
|
|
|
2021-02-03 22:17:35 +03:00
|
|
|
if (OCOS_ENABLE_GPT2_TOKENIZER)
|
2021-01-28 01:55:50 +03:00
|
|
|
# GPT2
|
2021-05-05 03:12:28 +03:00
|
|
|
file(GLOB tok_TARGET_SRC "operators/tokenizer/gpt*.cc" "operators/tokenizer/unicode*.*")
|
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
|
|
|
|
2021-02-03 22:17:35 +03:00
|
|
|
if (OCOS_ENABLE_SPM_TOKENIZER)
|
2021-01-28 01:55:50 +03:00
|
|
|
# SentencePiece
|
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()
|
|
|
|
|
2021-03-11 21:19:49 +03:00
|
|
|
if (OCOS_ENABLE_BERT_TOKENIZER)
|
|
|
|
# Bert
|
2021-05-05 03:12:28 +03:00
|
|
|
file(GLOB bert_TARGET_SRC "operators/tokenizer/wordpiece*.*")
|
2021-03-11 21:19:49 +03:00
|
|
|
list(APPEND TARGET_SRC ${bert_TARGET_SRC})
|
|
|
|
endif()
|
2021-02-16 14:22:53 +03:00
|
|
|
|
2021-08-16 21:08:03 +03:00
|
|
|
if (OCOS_ENABLE_GPT2_TOKENIZER OR OCOS_ENABLE_BERT_TOKENIZER)
|
|
|
|
if (NOT TARGET nlohmann_json)
|
|
|
|
set(JSON_BuildTests OFF CACHE INTERNAL "")
|
|
|
|
message(STATUS "Fetch json")
|
|
|
|
include(json)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2021-06-24 09:29:16 +03:00
|
|
|
if (OCOS_ENABLE_BLINGFIRE)
|
|
|
|
file(GLOB blingfire_TARGET_SRC "operators/tokenizer/blingfire*.*")
|
|
|
|
list(APPEND TARGET_SRC ${blingfire_TARGET_SRC})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
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>")
|
2021-05-30 06:17:15 +03:00
|
|
|
add_library(ocos_operators STATIC ${TARGET_SRC})
|
|
|
|
target_include_directories(ocos_operators PUBLIC operators/tokenizer)
|
2021-01-28 01:55:50 +03:00
|
|
|
|
2021-08-17 08:21:12 +03:00
|
|
|
set(ocos_libraries "")
|
2021-02-03 22:17:35 +03:00
|
|
|
if (OCOS_ENABLE_TF_STRING)
|
|
|
|
list(APPEND ocos_libraries re2)
|
|
|
|
endif()
|
|
|
|
|
2021-05-30 06:17:15 +03:00
|
|
|
target_include_directories(ocos_operators PUBLIC
|
2021-02-03 22:17:35 +03:00
|
|
|
${PROJECT_SOURCE_DIR}/includes
|
|
|
|
${PROJECT_SOURCE_DIR}/includes/onnxruntime
|
2021-05-05 03:12:28 +03:00
|
|
|
${PROJECT_SOURCE_DIR}/operators)
|
2021-02-03 22:17:35 +03:00
|
|
|
|
|
|
|
set(OCOS_COMPILE_DEFINITIONS "")
|
|
|
|
|
|
|
|
if (OCOS_ENABLE_TF_STRING)
|
2021-05-30 06:17:15 +03:00
|
|
|
target_include_directories(ocos_operators PUBLIC
|
2021-02-03 22:17:35 +03:00
|
|
|
${googlere2_SOURCE_DIR}
|
|
|
|
${farmhash_SOURCE_DIR}/src)
|
|
|
|
list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_TF_STRING)
|
|
|
|
endif()
|
|
|
|
|
2021-08-26 02:09:35 +03:00
|
|
|
if (OCOS_ENABLE_RE2_REGEX)
|
|
|
|
list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_RE2_REGEX)
|
|
|
|
endif()
|
|
|
|
|
2021-05-05 03:12:28 +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)
|
|
|
|
# The dlib matrix implementation is all in the headers, no library compiling needed.
|
2021-08-26 02:09:35 +03:00
|
|
|
list(APPEND ocos_libraries dlib::dlib)
|
2021-05-05 03:12:28 +03:00
|
|
|
endif()
|
|
|
|
|
2021-02-03 22:17:35 +03:00
|
|
|
if (OCOS_ENABLE_GPT2_TOKENIZER)
|
|
|
|
# GPT2
|
2021-05-30 06:17:15 +03:00
|
|
|
target_include_directories(ocos_operators PRIVATE ${json_SOURCE_DIR}/single_include)
|
2021-02-03 22:17:35 +03:00
|
|
|
list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_GPT2_TOKENIZER)
|
|
|
|
list(APPEND ocos_libraries nlohmann_json::nlohmann_json)
|
|
|
|
endif()
|
|
|
|
|
2021-08-16 21:08:03 +03:00
|
|
|
if (OCOS_ENABLE_BERT_TOKENIZER)
|
|
|
|
list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_BERT_TOKENIZER)
|
|
|
|
endif()
|
|
|
|
|
2021-02-03 22:17:35 +03:00
|
|
|
if (OCOS_ENABLE_SPM_TOKENIZER)
|
|
|
|
# SentencePiece
|
2021-05-30 06:17:15 +03:00
|
|
|
target_include_directories(ocos_operators PUBLIC ${sentencepieceproject_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()
|
|
|
|
|
2021-08-16 21:08:03 +03:00
|
|
|
if (OCOS_ENABLE_GPT2_TOKENIZER OR OCOS_ENABLE_BERT_TOKENIZER)
|
|
|
|
target_include_directories(ocos_operators PRIVATE ${json_SOURCE_DIR}/single_include)
|
|
|
|
list(APPEND ocos_libraries nlohmann_json::nlohmann_json)
|
|
|
|
endif()
|
|
|
|
|
2021-06-24 09:29:16 +03:00
|
|
|
if (OCOS_ENABLE_BLINGFIRE)
|
|
|
|
include(blingfire)
|
|
|
|
list(APPEND OCOS_COMPILE_DEFINITIONS ENABLE_BLINGFIRE)
|
|
|
|
list(APPEND ocos_libraries bingfirtinydll_static)
|
|
|
|
endif()
|
|
|
|
|
2021-02-03 22:17:35 +03:00
|
|
|
if (OCOS_ENABLE_TF_STRING)
|
2021-05-30 06:17:15 +03:00
|
|
|
target_compile_definitions(ocos_operators PRIVATE
|
2021-02-03 22:17:35 +03:00
|
|
|
NOMINMAX
|
|
|
|
FARMHASH_NO_BUILTIN_EXPECT)
|
|
|
|
endif()
|
|
|
|
|
2021-03-11 21:19:49 +03:00
|
|
|
|
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
|
|
|
|
|
|
|
file(GLOB shared_TARGET_SRC "shared/*.cc" "shared/*.h")
|
|
|
|
if(OCOS_ENABLE_PYTHON)
|
2020-10-21 04:49:41 +03:00
|
|
|
set(Python3_FIND_REGISTRY NEVER CACHE STRING "...")
|
|
|
|
if(NOT "${Python3_FIND_REGISTRY}" STREQUAL "NEVER")
|
|
|
|
message(FATAL_ERROR "Python3_FIND_REGISTRY is not NEVER")
|
|
|
|
endif()
|
2021-05-30 06:17:15 +03:00
|
|
|
find_package(Python3 COMPONENTS Interpreter Development.Module NumPy)
|
2021-06-24 09:29:16 +03:00
|
|
|
if (NOT Python3_FOUND)
|
|
|
|
message(FATAL_ERROR "Python3 or NumPy not found!")
|
|
|
|
endif()
|
2021-01-12 00:44:17 +03:00
|
|
|
if (WIN32)
|
2021-05-12 22:02:57 +03:00
|
|
|
list(APPEND shared_TARGET_SRC "${PROJECT_SOURCE_DIR}/onnxruntime_extensions/ortcustomops.def")
|
2021-01-12 00:44:17 +03:00
|
|
|
endif()
|
2021-02-03 22:17:35 +03:00
|
|
|
|
2021-05-30 06:17:15 +03:00
|
|
|
file(GLOB TARGET_SRC_PYOPS "pyop/*.cc" "pyop/*.h")
|
|
|
|
add_library(ortcustomops SHARED ${TARGET_SRC_PYOPS} ${shared_TARGET_SRC})
|
2021-02-03 22:17:35 +03:00
|
|
|
list(APPEND OCOS_COMPILE_DEFINITIONS PYTHON_OP_SUPPORT)
|
2021-04-22 07:36:40 +03:00
|
|
|
# building static lib has higher priority
|
|
|
|
elseif(OCOS_ENABLE_STATIC_LIB)
|
|
|
|
add_library(ortcustomops STATIC ${shared_TARGET_SRC})
|
2021-04-14 09:01:29 +03:00
|
|
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
|
|
|
|
add_executable(ortcustomops ${shared_TARGET_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")
|
|
|
|
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
|
|
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()
|
2021-02-03 22:17:35 +03:00
|
|
|
list(APPEND shared_TARGET_SRC "${PROJECT_SOURCE_DIR}/shared/ortcustomops.def")
|
|
|
|
add_library(ortcustomops SHARED ${shared_TARGET_SRC})
|
2021-01-12 00:44:17 +03:00
|
|
|
endif()
|
2021-01-28 01:55:50 +03:00
|
|
|
|
2021-02-03 22:17:35 +03:00
|
|
|
target_compile_definitions(ortcustomops PRIVATE ${OCOS_COMPILE_DEFINITIONS})
|
2021-08-17 08:21:12 +03:00
|
|
|
target_link_libraries(ortcustomops PUBLIC ocos_operators)
|
2020-10-21 04:49:41 +03:00
|
|
|
|
2021-02-03 22:17:35 +03:00
|
|
|
if(OCOS_ENABLE_PYTHON)
|
2021-05-05 03:12:28 +03:00
|
|
|
message(STATUS "Fetch pybind11")
|
2020-10-21 04:49:41 +03:00
|
|
|
include(pybind11)
|
|
|
|
target_include_directories(ortcustomops PRIVATE
|
2021-05-30 06:17:15 +03:00
|
|
|
$<TARGET_PROPERTY:Python3::Module,INTERFACE_INCLUDE_DIRECTORIES>
|
|
|
|
$<TARGET_PROPERTY:Python3::NumPy,INTERFACE_INCLUDE_DIRECTORIES>
|
|
|
|
${pybind11_INCLUDE_DIRS}
|
2021-01-12 00:44:17 +03:00
|
|
|
)
|
2021-05-30 06:17:15 +03:00
|
|
|
|
|
|
|
target_compile_definitions(ortcustomops PRIVATE
|
|
|
|
$<TARGET_PROPERTY:Python3::Module,INTERFACE_COMPILE_DEFINITIONS>)
|
|
|
|
|
|
|
|
target_link_libraries(ortcustomops PRIVATE Python3::Module)
|
|
|
|
|
2021-01-12 00:44:17 +03:00
|
|
|
if(NOT "${OCOS_EXTENTION_NAME}" STREQUAL "")
|
|
|
|
if(NOT WIN32)
|
|
|
|
set_target_properties(ortcustomops PROPERTIES
|
|
|
|
LIBRARY_OUTPUT_NAME ${OCOS_EXTENTION_NAME}
|
|
|
|
PREFIX ""
|
|
|
|
SUFFIX "")
|
|
|
|
endif()
|
2020-11-13 01:59:00 +03:00
|
|
|
endif()
|
2020-10-21 04:49:41 +03:00
|
|
|
endif()
|
|
|
|
|
2021-02-03 22:17:35 +03:00
|
|
|
|
2020-11-13 01:59:00 +03:00
|
|
|
# test section
|
2021-04-14 09:01:29 +03:00
|
|
|
if (OCOS_ENABLE_CTEST)
|
2021-02-03 22:17:35 +03:00
|
|
|
# Enable CTest
|
2021-04-14 09:01:29 +03:00
|
|
|
find_library(ONNXRUNTIME onnxruntime HINTS "${ONNXRUNTIME_LIB_DIR}")
|
|
|
|
if (NOT ONNXRUNTIME)
|
2021-05-30 06:17:15 +03:00
|
|
|
message(FATAL_ERROR "The ctest needs the prebuilt onnxruntime libraries directory, please specify it by ONNXRUNTIME_LIB_DIR.")
|
2021-04-14 09:01:29 +03:00
|
|
|
endif()
|
|
|
|
|
2021-02-03 22:17:35 +03:00
|
|
|
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")
|
2021-05-30 06:17:15 +03:00
|
|
|
add_executable(operators_test ${static_TEST_SRC})
|
2021-08-17 08:21:12 +03:00
|
|
|
target_link_libraries(operators_test PRIVATE gtest_main ocos_operators ${ocos_libraries})
|
2021-05-30 06:17:15 +03:00
|
|
|
add_test(NAME operators_test COMMAND $<TARGET_FILE:operators_test>)
|
2021-02-03 22:17:35 +03:00
|
|
|
|
2021-05-05 03:12:28 +03:00
|
|
|
# needs to link with stdc++fs in Linux
|
|
|
|
if(UNIX AND NOT APPLE)
|
|
|
|
set(FS_STDLIB stdc++fs)
|
|
|
|
endif()
|
2021-05-30 06:17:15 +03:00
|
|
|
|
2021-02-03 22:17:35 +03:00
|
|
|
file(GLOB shared_TEST_SRC "${TEST_SRC_DIR}/shared_test/*.cc")
|
|
|
|
add_executable(ortcustomops_test ${shared_TEST_SRC})
|
|
|
|
if (ONNXRUNTIME_LIB_DIR)
|
|
|
|
target_link_directories(ortcustomops_test PRIVATE ${ONNXRUNTIME_LIB_DIR})
|
2021-05-05 03:12:28 +03:00
|
|
|
endif()
|
2021-08-17 08:21:12 +03:00
|
|
|
target_link_libraries(ortcustomops_test PRIVATE ortcustomops onnxruntime gtest_main ${ocos_libraries} ${FS_STDLIB})
|
2021-05-05 03:12:28 +03:00
|
|
|
if (WIN32)
|
|
|
|
file(TO_CMAKE_PATH "${ONNXRUNTIME_LIB_DIR}/*" ONNXRUNTIME_LIB_FILEPATTERN)
|
|
|
|
file(GLOB ONNXRUNTIME_LIB_FILES CONFIGURE_DEPENDS "${ONNXRUNTIME_LIB_FILEPATTERN}")
|
|
|
|
add_custom_command(
|
|
|
|
TARGET ortcustomops_test POST_BUILD
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${ONNXRUNTIME_LIB_FILES} $<TARGET_FILE_DIR:ortcustomops_test>)
|
2021-02-03 22:17:35 +03:00
|
|
|
endif()
|
2020-10-21 04:49:41 +03:00
|
|
|
|
2021-02-03 22:17:35 +03:00
|
|
|
set(TEST_DATA_SRC ${TEST_SRC_DIR}/data)
|
2021-05-12 22:02:57 +03:00
|
|
|
set(TEST_DATA_DES ${onnxruntime_extensions_BINARY_DIR}/data)
|
2021-02-03 22:17:35 +03:00
|
|
|
|
|
|
|
# Copy test data from source to destination.
|
|
|
|
add_custom_command(
|
|
|
|
TARGET ortcustomops_test POST_BUILD
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
|
|
|
${TEST_DATA_SRC}
|
|
|
|
${TEST_DATA_DES})
|
|
|
|
add_test(NAME ortcustomops_test COMMAND $<TARGET_FILE:ortcustomops_test>)
|
|
|
|
endif()
|