Skip to content

Commit 2ae9534

Browse files
committed
Fixes in the CMake install setup for EXPORT
- lib64 is not consistently used; usually it's lib, and CMAKE_INSTALL_LIBDIR is the right way to get the name - the link options for regex_lookahead are already exported; don't need to do them again in our manual config.cmake - had to unbreak the macros we use to set the link options so that they work when exported, though
1 parent 23359bd commit 2ae9534

File tree

3 files changed

+7
-20
lines changed

3 files changed

+7
-20
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ file(GLOB unicode_source_files
6161
add_library(
6262
tokenizers STATIC ${tokenizers_source_files} ${unicode_source_files}
6363
)
64+
add_library(tokenizers::tokenizers ALIAS tokenizers)
6465

6566
# Using abseil from sentencepiece/third_party
6667
target_include_directories(
@@ -101,6 +102,7 @@ if(SUPPORT_REGEX_LOOKAHEAD)
101102
${CMAKE_CURRENT_SOURCE_DIR}/src/regex_lookahead.cpp
102103
${CMAKE_CURRENT_SOURCE_DIR}/src/std_regex.cpp
103104
)
105+
add_library(tokenizers::regex_lookahead ALIAS regex_lookahead)
104106
target_link_libraries(regex_lookahead PUBLIC pcre2-8-static)
105107
target_include_directories(
106108
regex_lookahead

Utils.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ function(kernel_link_options target_name)
2020
# "$<LINK_LIBRARY:WHOLE_ARCHIVE,target_name>")
2121
target_link_options(
2222
${target_name} INTERFACE "SHELL:LINKER:--whole-archive \
23-
$<TARGET_FILE:${target_name}> \
23+
$<TARGET_FILE:tokenizers::${target_name}> \
2424
LINKER:--no-whole-archive")
2525
endfunction()
2626

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

3333
# Same as kernel_link_options but it's for MSVC linker
3434
function(msvc_kernel_link_options target_name)
3535
target_link_options(
3636
${target_name} INTERFACE
37-
"SHELL:LINKER:/WHOLEARCHIVE:$<TARGET_FILE:${target_name}>")
37+
"SHELL:LINKER:/WHOLEARCHIVE:$<TARGET_FILE:tokenizers::${target_name}>")
3838
endfunction()
3939

4040
# Ensure that the load-time constructor functions run. By default, the linker

cmake/tokenizers-config.cmake.in

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
@PACKAGE_INIT@
88

99
include(CMakeFindDependencyMacro)
10-
10+
include(GNUInstallDirs)
1111
# Find dependencies
1212
find_dependency(re2 REQUIRED)
1313
find_dependency(absl REQUIRED)
1414
# Directly include sentencepiece library
15-
set(SENTENCEPIECE_LIBRARY "${CMAKE_INSTALL_PREFIX}/lib64/libsentencepiece.a")
15+
set(SENTENCEPIECE_LIBRARY "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libsentencepiece.a")
1616
if(NOT EXISTS "${SENTENCEPIECE_LIBRARY}")
1717
message(
1818
FATAL_ERROR
@@ -26,21 +26,6 @@ include("${CMAKE_CURRENT_LIST_DIR}/tokenizers-targets.cmake")
2626
# Set the include directories
2727
set_and_check(TOKENIZERS_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
2828

29-
# Add --whole-archive linker flag for tokenizers library
30-
if(APPLE)
31-
set(TOKENIZERS_LINK_OPTIONS
32-
"SHELL:-force_load,$<TARGET_FILE:tokenizers::regex_lookahead>"
33-
)
34-
elseif(MSVC)
35-
set(TOKENIZERS_LINK_OPTIONS
36-
"SHELL:/WHOLEARCHIVE:$<TARGET_FILE:tokenizers::regex_lookahead>"
37-
)
38-
else()
39-
set(TOKENIZERS_LINK_OPTIONS
40-
"SHELL:LINKER:--whole-archive $<TARGET_FILE:tokenizers::regex_lookahead> LINKER:--no-whole-archive"
41-
)
42-
endif()
43-
4429
# Set the libraries and link options
4530
set(TOKENIZERS_LIBRARIES tokenizers::tokenizers)
4631
set_property(

0 commit comments

Comments
 (0)