Skip to content

Fixes in the CMake install setup for EXPORT #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ file(GLOB unicode_source_files
add_library(
tokenizers STATIC ${tokenizers_source_files} ${unicode_source_files}
)
add_library(tokenizers::tokenizers ALIAS tokenizers)

# Using abseil from sentencepiece/third_party
target_include_directories(
Expand Down Expand Up @@ -101,6 +102,7 @@ if(SUPPORT_REGEX_LOOKAHEAD)
${CMAKE_CURRENT_SOURCE_DIR}/src/regex_lookahead.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/std_regex.cpp
)
add_library(tokenizers::regex_lookahead ALIAS regex_lookahead)
target_link_libraries(regex_lookahead PUBLIC pcre2-8-static)
target_include_directories(
regex_lookahead
Expand Down
6 changes: 3 additions & 3 deletions Utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ function(kernel_link_options target_name)
# "$<LINK_LIBRARY:WHOLE_ARCHIVE,target_name>")
target_link_options(
${target_name} INTERFACE "SHELL:LINKER:--whole-archive \
$<TARGET_FILE:${target_name}> \
$<TARGET_FILE:tokenizers::${target_name}> \
LINKER:--no-whole-archive")
endfunction()

# Same as kernel_link_options but it's for MacOS linker
function(macos_kernel_link_options target_name)
target_link_options(${target_name} INTERFACE
"SHELL:LINKER:-force_load,$<TARGET_FILE:${target_name}>")
"SHELL:LINKER:-force_load,$<TARGET_FILE:tokenizers::${target_name}>")
endfunction()

# Same as kernel_link_options but it's for MSVC linker
function(msvc_kernel_link_options target_name)
target_link_options(
${target_name} INTERFACE
"SHELL:LINKER:/WHOLEARCHIVE:$<TARGET_FILE:${target_name}>")
"SHELL:LINKER:/WHOLEARCHIVE:$<TARGET_FILE:tokenizers::${target_name}>")
endfunction()

# Ensure that the load-time constructor functions run. By default, the linker
Expand Down
19 changes: 2 additions & 17 deletions cmake/tokenizers-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)

include(GNUInstallDirs)
# Find dependencies
find_dependency(re2 REQUIRED)
find_dependency(absl REQUIRED)
# Directly include sentencepiece library
set(SENTENCEPIECE_LIBRARY "${CMAKE_INSTALL_PREFIX}/lib64/libsentencepiece.a")
set(SENTENCEPIECE_LIBRARY "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libsentencepiece.a")
if(NOT EXISTS "${SENTENCEPIECE_LIBRARY}")
message(
FATAL_ERROR
Expand All @@ -26,21 +26,6 @@ include("${CMAKE_CURRENT_LIST_DIR}/tokenizers-targets.cmake")
# Set the include directories
set_and_check(TOKENIZERS_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")

# Add --whole-archive linker flag for tokenizers library
if(APPLE)
set(TOKENIZERS_LINK_OPTIONS
"SHELL:-force_load,$<TARGET_FILE:tokenizers::regex_lookahead>"
)
elseif(MSVC)
set(TOKENIZERS_LINK_OPTIONS
"SHELL:/WHOLEARCHIVE:$<TARGET_FILE:tokenizers::regex_lookahead>"
)
else()
set(TOKENIZERS_LINK_OPTIONS
"SHELL:LINKER:--whole-archive $<TARGET_FILE:tokenizers::regex_lookahead> LINKER:--no-whole-archive"
)
endif()

# Set the libraries and link options
set(TOKENIZERS_LIBRARIES tokenizers::tokenizers)
set_property(
Expand Down
Loading