2018-07-24 09:22:49 +03:00
|
|
|
|
# Copyright 2018 Google Inc.
|
|
|
|
|
#
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
|
#
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
#
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
|
# limitations under the License.!
|
|
|
|
|
|
|
|
|
|
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
|
2020-11-12 11:27:56 +03:00
|
|
|
|
file(STRINGS "VERSION.txt" SPM_VERSION)
|
2018-08-09 20:12:26 +03:00
|
|
|
|
message(STATUS "VERSION: ${SPM_VERSION}")
|
2023-03-26 21:07:58 +03:00
|
|
|
|
|
|
|
|
|
if(POLICY CMP0091)
|
|
|
|
|
cmake_policy(SET CMP0091 NEW)
|
|
|
|
|
endif()
|
|
|
|
|
|
2019-05-21 17:33:39 +03:00
|
|
|
|
project(sentencepiece VERSION ${SPM_VERSION} LANGUAGES C CXX)
|
2018-07-24 09:22:49 +03:00
|
|
|
|
|
|
|
|
|
option(SPM_ENABLE_NFKC_COMPILE "Enables NFKC compile" OFF)
|
|
|
|
|
option(SPM_ENABLE_SHARED "Builds shared libaries in addition to static libraries." ON)
|
|
|
|
|
option(SPM_BUILD_TEST "Builds test binaries." OFF)
|
|
|
|
|
option(SPM_COVERAGE "Runs gcov to test coverage." OFF)
|
|
|
|
|
option(SPM_ENABLE_TENSORFLOW_SHARED "Makes a tensorflow compatible shared file." OFF)
|
|
|
|
|
option(SPM_ENABLE_TCMALLOC "Enable TCMalloc if available." ON)
|
|
|
|
|
option(SPM_TCMALLOC_STATIC "Link static library of TCMALLOC." OFF)
|
2018-08-14 11:26:39 +03:00
|
|
|
|
option(SPM_NO_THREADLOCAL "Disable thread_local operator" OFF)
|
2023-04-02 19:17:36 +03:00
|
|
|
|
option(SPM_ENABLE_MSVC_MT_BUILD, "Use /MT flag in MSVC build" OFF)
|
2023-05-14 12:08:39 +03:00
|
|
|
|
option(SPM_CROSS_SYSTEM_PROCESSOR, "Override system processor" "")
|
|
|
|
|
|
2024-01-16 05:15:46 +03:00
|
|
|
|
set(SPM_PROTOBUF_PROVIDER "internal" CACHE STRING "Provider of protobuf library")
|
|
|
|
|
set_property(CACHE SPM_PROTOBUF_PROVIDER PROPERTY STRINGS "internal" "package")
|
|
|
|
|
set(SPM_ABSL_PROVIDER "internal" CACHE STRING "Provider of absl library")
|
|
|
|
|
set_property(CACHE SPM_ABSL_PROVIDER PROPERTY STRINGS "internal" "module" "package")
|
|
|
|
|
|
2023-05-14 12:08:39 +03:00
|
|
|
|
if (SPM_CROSS_SYSTEM_PROCESSOR)
|
|
|
|
|
set(CMAKE_SYSTEM_PROCESSOR ${SPM_CROSS_SYSTEM_PROCESSOR})
|
|
|
|
|
endif()
|
2018-07-24 09:22:49 +03:00
|
|
|
|
|
2022-11-21 17:55:16 +03:00
|
|
|
|
# Disable shared build on windows
|
|
|
|
|
if(WIN32)
|
|
|
|
|
set(SPM_ENABLE_SHARED OFF)
|
2022-11-28 23:19:09 +03:00
|
|
|
|
endif()
|
2022-11-21 17:55:16 +03:00
|
|
|
|
|
2022-06-13 19:18:09 +03:00
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
2018-07-24 09:22:49 +03:00
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
|
|
2021-06-17 18:13:53 +03:00
|
|
|
|
if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
|
|
|
|
|
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 10.0) OR
|
|
|
|
|
(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
|
|
|
|
|
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.0))
|
|
|
|
|
string(APPEND CMAKE_CXX_FLAGS " -fmacro-prefix-map=${CMAKE_SOURCE_DIR}/=''")
|
|
|
|
|
endif()
|
|
|
|
|
|
2024-02-20 10:43:25 +03:00
|
|
|
|
if (NOT DEFINED CMAKE_INSTALL_BINDIR)
|
|
|
|
|
set(CMAKE_INSTALL_BINDIR bin)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if (NOT DEFINED CMAKE_INSTALL_LIBDIR)
|
|
|
|
|
set(CMAKE_INSTALL_LIBDIR lib)
|
|
|
|
|
endif()
|
|
|
|
|
|
2024-02-20 13:20:06 +03:00
|
|
|
|
if (NOT DEFINED CMAKE_INSTALL_INCLUDEDIR)
|
|
|
|
|
set(CMAKE_INSTALL_INCLUDEDIR include)
|
2024-02-20 10:43:25 +03:00
|
|
|
|
endif()
|
|
|
|
|
|
2020-10-17 11:41:05 +03:00
|
|
|
|
if (UNIX)
|
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
set(prefix ${CMAKE_INSTALL_PREFIX})
|
|
|
|
|
set(exec_prefix "\${prefix}")
|
|
|
|
|
set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
|
|
|
|
|
set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
|
|
|
|
|
else()
|
|
|
|
|
set(prefix ${CMAKE_INSTALL_PREFIX})
|
|
|
|
|
set(exec_prefix "\${prefix}")
|
|
|
|
|
set(libdir "\${exec_prefix}/lib")
|
|
|
|
|
set(includedir "\${prefix}/include")
|
|
|
|
|
endif()
|
2018-07-24 09:22:49 +03:00
|
|
|
|
set(GNUCXX_STD_SUPPORT_VERSION "4.3")
|
|
|
|
|
|
2021-09-10 23:06:15 +03:00
|
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
|
|
|
|
|
add_definitions(-D_FREEBSD)
|
|
|
|
|
endif()
|
|
|
|
|
|
2019-01-08 05:40:08 +03:00
|
|
|
|
if (SPM_USE_BUILTIN_PROTOBUF)
|
|
|
|
|
set(libprotobuf_lite "")
|
|
|
|
|
else()
|
2023-05-21 21:38:08 +03:00
|
|
|
|
set(libprotobuf_lite "protobuf-lite")
|
2019-01-08 05:40:08 +03:00
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if (MSVC)
|
2020-05-09 18:51:03 +03:00
|
|
|
|
add_definitions("/wd4267 /wd4244 /wd4305 /Zc:strictStrings /utf-8")
|
2023-04-02 19:17:36 +03:00
|
|
|
|
if (SPM_ENABLE_MSVC_MT_BUILD)
|
|
|
|
|
string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
|
|
|
|
|
string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_MINSIZEREL ${CMAKE_CXX_FLAGS_MINSIZEREL})
|
|
|
|
|
string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
|
|
|
|
|
string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
|
|
|
|
|
endif()
|
2019-01-08 05:40:08 +03:00
|
|
|
|
endif()
|
2018-07-31 08:29:30 +03:00
|
|
|
|
|
2018-07-24 09:22:49 +03:00
|
|
|
|
if (APPLE)
|
|
|
|
|
set(CMAKE_MACOSX_RPATH ON)
|
|
|
|
|
set(CMAKE_SKIP_BUILD_RPATH FALSE)
|
|
|
|
|
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
|
|
|
|
|
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
|
|
|
|
|
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
|
|
|
|
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
|
|
|
|
|
if ("${isSystemDir}" STREQUAL "-1")
|
|
|
|
|
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-08-21 06:44:31 +03:00
|
|
|
|
# SPDX-License-Identifier: (MIT OR CC0-1.0)
|
|
|
|
|
# Copyright 2020 Jan Tojnar
|
|
|
|
|
# https://github.com/jtojnar/cmake-snips
|
|
|
|
|
#
|
|
|
|
|
# Modelled after Python’s os.path.join
|
|
|
|
|
# https://docs.python.org/3.7/library/os.path.html#os.path.join
|
|
|
|
|
# Windows not supported
|
|
|
|
|
function(join_paths joined_path first_path_segment)
|
|
|
|
|
set(temp_path "${first_path_segment}")
|
|
|
|
|
foreach(current_segment IN LISTS ARGN)
|
|
|
|
|
if(NOT ("${current_segment}" STREQUAL ""))
|
|
|
|
|
if(IS_ABSOLUTE "${current_segment}")
|
|
|
|
|
set(temp_path "${current_segment}")
|
|
|
|
|
else()
|
|
|
|
|
set(temp_path "${temp_path}/${current_segment}")
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
set(${joined_path} "${temp_path}" PARENT_SCOPE)
|
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
|
join_paths(libdir_for_pc_file "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}")
|
|
|
|
|
join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
|
|
|
|
|
|
2018-07-24 09:22:49 +03:00
|
|
|
|
configure_file("${PROJECT_SOURCE_DIR}/config.h.in" "config.h")
|
|
|
|
|
configure_file("${PROJECT_SOURCE_DIR}/sentencepiece.pc.in" "sentencepiece.pc" @ONLY)
|
|
|
|
|
|
|
|
|
|
if (NOT MSVC)
|
2022-06-13 19:18:09 +03:00
|
|
|
|
# suppress warning for C++11 features.
|
|
|
|
|
# add_definitions("-Wno-deprecated-declarations -Wno-deprecated-enum-enum-conversion")
|
2020-08-21 20:15:42 +03:00
|
|
|
|
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sentencepiece.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
2018-07-24 09:22:49 +03:00
|
|
|
|
endif()
|
|
|
|
|
|
2020-05-25 12:15:02 +03:00
|
|
|
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_BINARY_DIR})
|
2018-07-24 09:22:49 +03:00
|
|
|
|
|
|
|
|
|
if (SPM_BUILD_TEST)
|
|
|
|
|
enable_testing()
|
|
|
|
|
endif()
|
|
|
|
|
|
2024-01-16 05:15:46 +03:00
|
|
|
|
if (SPM_ABSL_PROVIDER STREQUAL "internal")
|
|
|
|
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl)
|
|
|
|
|
elseif (SPM_ABSL_PROVIDER STREQUAL "module")
|
|
|
|
|
include(FetchContent)
|
|
|
|
|
FetchContent_Populate(abseil-cpp
|
|
|
|
|
GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
|
|
|
|
|
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/abseil-cpp
|
|
|
|
|
GIT_PROGRESS TRUE)
|
|
|
|
|
add_subdirectory(third_party/abseil-cpp)
|
2024-01-18 03:32:48 +03:00
|
|
|
|
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl.org)
|
|
|
|
|
file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl ${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl.org)
|
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/third_party/abseil-cpp/absl
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl)
|
|
|
|
|
endif()
|
2024-01-16 05:15:46 +03:00
|
|
|
|
elseif (SPM_ABSL_PROVIDER STREQUAL "package")
|
|
|
|
|
find_package(absl REQUIRED)
|
|
|
|
|
get_target_property(ABSL_INCLUDE_DIRS absl::base INTERFACE_INCLUDE_DIRECTORIES)
|
2024-01-18 03:32:48 +03:00
|
|
|
|
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl.org)
|
|
|
|
|
file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl ${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl.org)
|
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
|
|
|
|
|
${ABSL_INCLUDE_DIRS}/absl ${CMAKE_CURRENT_SOURCE_DIR}/third_party/absl)
|
|
|
|
|
endif()
|
2024-01-16 05:15:46 +03:00
|
|
|
|
include_directories(${ABSL_INCLUDE_DIRS})
|
2021-01-08 05:33:31 +03:00
|
|
|
|
endif()
|
|
|
|
|
|
2018-07-24 09:22:49 +03:00
|
|
|
|
add_subdirectory(src)
|
2018-12-10 18:24:18 +03:00
|
|
|
|
add_subdirectory(third_party)
|
2018-08-09 13:56:47 +03:00
|
|
|
|
|
2018-08-09 19:17:43 +03:00
|
|
|
|
set(CPACK_SOURCE_GENERATOR "TXZ")
|
2018-08-10 04:42:52 +03:00
|
|
|
|
set(CPACK_GENERATOR "7Z")
|
2018-08-09 20:12:26 +03:00
|
|
|
|
set(CPACK_PACKAGE_VERSION "${SPM_VERSION}")
|
2018-08-09 19:17:43 +03:00
|
|
|
|
set(CPACK_STRIP_FILES TRUE)
|
|
|
|
|
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
|
|
|
|
|
set(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README.md")
|
2018-08-22 12:33:32 +03:00
|
|
|
|
set(CPACK_PACKAGE_CONTACT "taku@google.com")
|
|
|
|
|
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Taku Kudo")
|
2018-08-10 04:42:52 +03:00
|
|
|
|
set(CPACK_SOURCE_IGNORE_FILES "/build/;/.git/;/dist/;/sdist/;~$;${CPACK_SOURCE_IGNORE_FILES}")
|
2018-08-09 13:56:47 +03:00
|
|
|
|
include(CPack)
|