Skip to content

Commit

Permalink
Dynamic linking with msvc runtime (openvinotoolkit#260)
Browse files Browse the repository at this point in the history
* set mt flags

* force set /MD

* patch fast_tokenizer CMakeLists.txt

* Revert "patch fast_tokenizer CMakeLists.txt"

This reverts commit a734b49.

* Revert "patch fast_tokenizer CMakeLists.txt"

This reverts commit a734b49.

* update patches
  • Loading branch information
mryzhov authored Sep 12, 2024
1 parent 3f12937 commit 56a4a59
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,20 @@ if(WIN32 OR APPLE)
endif()

if(BUILD_FAST_TOKENIZERS)
# FastTokenizers use static MSVC runtime, hence we have to use it as well
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(THIRD_PARTY_BUILD_TYPE ${CMAKE_BUILD_TYPE})

# Set FastTokenizers to use dynamic MSVC runtime
set(MSVC_STATIC_CRT OFF) # PADDLE_LIB
set(PCRE2_STATIC_RUNTIME OFF) # PCRE2_LIB
set(SPM_ENABLE_MSVC_MT_BUILD OFF) # sentencepiece libs
if(WIN32)
foreach(
flag_var
CMAKE_CXX_FLAGS_DEBUG
CMAKE_C_FLAGS_DEBUG)
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MTd" ${flag_var} "${${flag_var}}")
elseif(NOT (${flag_var} MATCHES "/MTd"))
set(${flag_var} "${${flag_var}} /MTd")
CMAKE_CXX_FLAGS
CMAKE_C_FLAGS)
if(${flag_var} MATCHES "/MT")
string(REGEX REPLACE "/MT" "/MD$<$<CONFIG:Debug>:d>" ${flag_var} "${${flag_var}}")
elseif(NOT (${flag_var} MATCHES "/MD$<$<CONFIG:Debug>:d>"))
set(${flag_var} "${${flag_var}} /MD$<$<CONFIG:Debug>:d>")
endif()
set(${flag_var} "${${flag_var}}" CACHE STRING "msvc compiler flags" FORCE)
endforeach()
Expand Down
14 changes: 14 additions & 0 deletions src/patches/fast_tokenizers.patch
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,17 @@ index 3b68f082..6ae7e8f0 100644
if (ICU_STATIC)
list(APPEND ${ICU_LIB_VAR} ${ICU_STATIC_LIB})
else()

diff --git a/fast_tokenizer/CMakeLists.txt b/fast_tokenizer/CMakeLists.txt
index ce238239..103a4f3e 100644
--- a/fast_tokenizer/CMakeLists.txt
+++ b/fast_tokenizer/CMakeLists.txt
@@ -51,7 +51,7 @@ else()
set(CMAKE_CXX_STANDARD 11)
endif()

-IF(WIN32)
+IF(WIN32 AND MSVC_STATIC_CRT)
# Need to add flags for windows
foreach(
flag_var

0 comments on commit 56a4a59

Please sign in to comment.