2025-11-12 08:07:40 +00:00
|
|
|
|
cmake_minimum_required(VERSION 3.20)
|
2025-11-09 17:07:23 +00:00
|
|
|
|
include(cmake/prelude.cmake)
|
2025-04-05 14:21:11 +00:00
|
|
|
|
include(CMakeDependentOption)
|
2025-11-09 17:07:23 +00:00
|
|
|
|
include(FetchContent)
|
2025-04-05 14:21:11 +00:00
|
|
|
|
|
2025-11-12 08:07:40 +00:00
|
|
|
|
project(
|
|
|
|
|
|
simstr
|
2026-03-08 14:53:28 +00:00
|
|
|
|
VERSION 1.7.3
|
2025-11-26 19:15:50 +00:00
|
|
|
|
DESCRIPTION "Yet another modern C++ string library"
|
2025-11-11 08:52:42 +00:00
|
|
|
|
HOMEPAGE_URL "https://github.com/orefkov/simstr"
|
2025-11-09 17:07:23 +00:00
|
|
|
|
LANGUAGES CXX
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
include(cmake/project-is-top-level.cmake)
|
|
|
|
|
|
include(cmake/variables.cmake)
|
2025-04-05 14:21:11 +00:00
|
|
|
|
|
2025-11-12 08:07:40 +00:00
|
|
|
|
if(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
|
|
|
|
|
|
set(MSVC_COMPILER ON)
|
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8 /Zc:strictStrings")
|
|
|
|
|
|
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
|
|
|
|
|
|
set(CLANG_COMPILER ON)
|
|
|
|
|
|
endif()
|
2025-04-05 14:21:11 +00:00
|
|
|
|
|
2025-12-02 08:05:41 +00:00
|
|
|
|
if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC OR "${CMAKE_CXX_SIMULATE_ID} " STREQUAL "MSVC ")
|
|
|
|
|
|
set(CAN_LINK_NATVIS On)
|
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
|
|
option(SIMSTR_BUILD_TESTS "Build tests" ON)
|
|
|
|
|
|
option(SIMSTR_BENCHMARKS "Build benchmarks" Off)
|
2025-12-22 12:52:18 +00:00
|
|
|
|
option(USE_SYSTEM_DEPS "Use system dependencies" Off)
|
2025-12-02 08:05:41 +00:00
|
|
|
|
cmake_dependent_option(SIMSTR_LINK_NATVIS "Link natvis file" On CAN_LINK_NATVIS Off)
|
2026-02-27 20:05:49 +00:00
|
|
|
|
cmake_dependent_option(SIMSTR_USE_LIBCXX "Use libc++" Off "NOT CAN_LINK_NATVIS" Off)
|
|
|
|
|
|
|
|
|
|
|
|
if (SIMSTR_USE_LIBCXX)
|
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
|
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi")
|
|
|
|
|
|
endif(SIMSTR_USE_LIBCXX)
|
2025-04-05 14:21:11 +00:00
|
|
|
|
|
2025-11-09 17:07:23 +00:00
|
|
|
|
add_library(simstr_simstr
|
2025-04-05 14:21:11 +00:00
|
|
|
|
src/sstring.cpp
|
|
|
|
|
|
src/simple_unicode.cpp
|
|
|
|
|
|
)
|
2025-11-09 17:07:23 +00:00
|
|
|
|
add_library(simstr::simstr ALIAS simstr_simstr)
|
|
|
|
|
|
|
|
|
|
|
|
target_include_directories(
|
|
|
|
|
|
simstr_simstr ${warning_guard}
|
|
|
|
|
|
PUBLIC
|
|
|
|
|
|
"\$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
target_compile_features(simstr_simstr PUBLIC cxx_std_20)
|
2025-04-05 14:21:11 +00:00
|
|
|
|
|
2025-11-13 14:57:42 +00:00
|
|
|
|
if(EMSCRIPTEN)
|
|
|
|
|
|
option(SIMSTR_EMSCRIPTEN_MT "Использовать многопоточность в Emscripten" OFF)
|
|
|
|
|
|
target_compile_options(simstr_simstr PUBLIC -Wno-warn-absolute-paths -Wno-unknown-warning-option -msimd128 -msse4.2 -msse3)
|
|
|
|
|
|
|
|
|
|
|
|
if(SIMSTR_EMSCRIPTEN_MT)
|
|
|
|
|
|
message("Build MT emscripten")
|
|
|
|
|
|
target_compile_options(simstr_simstr PUBLIC -pthread)
|
|
|
|
|
|
endif()
|
|
|
|
|
|
endif(EMSCRIPTEN)
|
|
|
|
|
|
|
2025-11-20 11:13:41 +00:00
|
|
|
|
message("Configuring simstr for [${CMAKE_BUILD_TYPE}]")
|
|
|
|
|
|
|
2025-12-02 08:05:41 +00:00
|
|
|
|
if (SIMSTR_LINK_NATVIS)
|
|
|
|
|
|
# Для MSVC подключаем natvis файл для красивой отладки
|
|
|
|
|
|
if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC OR "${CMAKE_CXX_SIMULATE_ID} " STREQUAL "MSVC ")
|
|
|
|
|
|
add_custom_command(
|
|
|
|
|
|
TARGET simstr_simstr PRE_BUILD
|
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/for_debug/simstr.natvis
|
|
|
|
|
|
${CMAKE_BINARY_DIR}/simstr.natvis
|
|
|
|
|
|
)
|
|
|
|
|
|
target_link_options(simstr_simstr PUBLIC "/natvis:${CMAKE_BINARY_DIR}/simstr.natvis")
|
|
|
|
|
|
endif()
|
2025-11-12 08:07:40 +00:00
|
|
|
|
endif()
|
|
|
|
|
|
|
2025-11-09 17:07:23 +00:00
|
|
|
|
set_target_properties(
|
|
|
|
|
|
simstr_simstr PROPERTIES
|
|
|
|
|
|
CXX_VISIBILITY_PRESET hidden
|
|
|
|
|
|
VISIBILITY_INLINES_HIDDEN YES
|
|
|
|
|
|
VERSION "${PROJECT_VERSION}"
|
|
|
|
|
|
SOVERSION "${PROJECT_VERSION_MAJOR}"
|
|
|
|
|
|
EXPORT_NAME simstr
|
|
|
|
|
|
OUTPUT_NAME simstr
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-11-13 14:57:42 +00:00
|
|
|
|
function(add_simdutf)
|
2025-11-12 08:07:40 +00:00
|
|
|
|
set(SIMDUTF_TOOLS OFF)
|
|
|
|
|
|
set(SIMDUTF_TESTS OFF)
|
|
|
|
|
|
set(SIMDUTF_BENCHMARKS OFF)
|
|
|
|
|
|
FetchContent_Declare(
|
|
|
|
|
|
simdutf
|
|
|
|
|
|
GIT_REPOSITORY https://github.com/simdutf/simdutf.git
|
|
|
|
|
|
GIT_SHALLOW TRUE
|
|
|
|
|
|
GIT_TAG tags/v7.5.0
|
|
|
|
|
|
FIND_PACKAGE_ARGS
|
|
|
|
|
|
)
|
|
|
|
|
|
FetchContent_MakeAvailable(simdutf)
|
2025-11-09 17:07:23 +00:00
|
|
|
|
endfunction()
|
|
|
|
|
|
|
2025-12-22 12:52:18 +00:00
|
|
|
|
if (USE_SYSTEM_DEPS)
|
|
|
|
|
|
find_package(simdutf REQUIRED)
|
|
|
|
|
|
else ()
|
|
|
|
|
|
add_simdutf()
|
|
|
|
|
|
endif()
|
2025-11-12 08:07:40 +00:00
|
|
|
|
|
2025-11-09 17:07:23 +00:00
|
|
|
|
target_link_libraries(simstr_simstr PUBLIC simdutf::simdutf)
|
2025-04-05 14:21:11 +00:00
|
|
|
|
|
2025-11-15 10:07:52 +00:00
|
|
|
|
if(BUILD_SHARED_LIBS)
|
2025-11-13 14:57:42 +00:00
|
|
|
|
# Всем объявляем, что мы будем в shared библиотеке
|
|
|
|
|
|
add_compile_definitions(SIMSTR_IN_SHARED)
|
|
|
|
|
|
# Себе объявим, что мы должны экспортировать функции
|
2025-11-09 17:07:23 +00:00
|
|
|
|
target_compile_definitions(simstr_simstr PRIVATE SIMSTR_EXPORT)
|
2025-11-15 10:07:52 +00:00
|
|
|
|
endif(BUILD_SHARED_LIBS)
|
2025-04-05 14:21:11 +00:00
|
|
|
|
|
2025-11-12 08:07:40 +00:00
|
|
|
|
if(SIMSTR_BUILD_TESTS)
|
2025-04-05 14:21:11 +00:00
|
|
|
|
enable_testing()
|
2025-11-12 08:07:40 +00:00
|
|
|
|
set(BUILD_TESTS ON)
|
2025-04-05 14:21:11 +00:00
|
|
|
|
# Load and build GTest
|
|
|
|
|
|
FetchContent_Declare(
|
2025-11-12 08:07:40 +00:00
|
|
|
|
googletest
|
|
|
|
|
|
# Specify the commit you depend on and update it regularly.
|
2026-01-21 11:59:17 +00:00
|
|
|
|
URL https://github.com/google/googletest/archive/refs/tags/v1.17.0.zip
|
2026-01-25 10:39:22 +00:00
|
|
|
|
FIND_PACKAGE_ARGS NAMES "GTest 1.17.0"
|
2025-04-05 14:21:11 +00:00
|
|
|
|
)
|
|
|
|
|
|
# For Windows: Prevent overriding the parent project's compiler/linker settings
|
|
|
|
|
|
set(gtest_force_shared_crt FALSE CACHE BOOL "" FORCE)
|
|
|
|
|
|
FetchContent_MakeAvailable(googletest)
|
|
|
|
|
|
add_subdirectory(tests)
|
2026-01-21 11:59:17 +00:00
|
|
|
|
if(TARGET gtest)
|
|
|
|
|
|
target_compile_features(gtest PUBLIC cxx_std_23)
|
|
|
|
|
|
target_compile_features(gtest_main PUBLIC cxx_std_23)
|
2026-03-08 14:53:28 +00:00
|
|
|
|
if (CLANG_COMPILER)
|
|
|
|
|
|
target_compile_options(gtest PRIVATE -Wno-error=character-conversion)
|
|
|
|
|
|
endif(CLANG_COMPILER)
|
2026-01-21 11:59:17 +00:00
|
|
|
|
endif()
|
2025-04-05 14:21:11 +00:00
|
|
|
|
endif()
|
|
|
|
|
|
|
2025-11-12 08:07:40 +00:00
|
|
|
|
function(GBencmark)
|
2025-04-05 14:21:11 +00:00
|
|
|
|
# Load and build Google benchmarks
|
|
|
|
|
|
FetchContent_Declare(
|
2025-11-12 08:07:40 +00:00
|
|
|
|
googlebench
|
|
|
|
|
|
# Specify the commit you depend on and update it regularly.
|
2025-11-13 14:57:42 +00:00
|
|
|
|
URL https://github.com/google/benchmark/archive/refs/tags/v1.9.4.zip
|
2026-01-25 10:39:22 +00:00
|
|
|
|
FIND_PACKAGE_ARGS NAMES "benchmark 1.9.4"
|
2025-04-05 14:21:11 +00:00
|
|
|
|
)
|
2025-11-12 08:07:40 +00:00
|
|
|
|
set(BENCHMARK_ENABLE_TESTING OFF)
|
|
|
|
|
|
set(BENCHMARK_ENABLE_LTO OFF)
|
|
|
|
|
|
set(BENCHMARK_ENABLE_INSTALL OFF)
|
|
|
|
|
|
set(BENCHMARK_INSTALL_DOCS OFF)
|
|
|
|
|
|
set(BENCHMARK_DOWNLOAD_DEPENDENCIES ON)
|
|
|
|
|
|
set(BENCHMARK_ENABLE_GTEST_TESTS OFF)
|
2026-02-27 20:05:49 +00:00
|
|
|
|
if (SIMSTR_USE_LIBCXX)
|
|
|
|
|
|
set(BENCHMARK_USE_LIBCXX On)
|
|
|
|
|
|
endif(SIMSTR_USE_LIBCXX)
|
|
|
|
|
|
|
2025-04-05 14:21:11 +00:00
|
|
|
|
add_compile_definitions(BENCHMARK_STATIC_DEFINE)
|
|
|
|
|
|
FetchContent_MakeAvailable(googlebench)
|
2026-01-21 11:59:17 +00:00
|
|
|
|
if(TARGET benchmark)
|
|
|
|
|
|
target_compile_features(benchmark PUBLIC cxx_std_23)
|
|
|
|
|
|
endif()
|
2025-11-13 14:57:42 +00:00
|
|
|
|
|
|
|
|
|
|
if(EMSCRIPTEN)
|
|
|
|
|
|
# Свежий Clang в Emscripten ругается на __COUNTER__
|
|
|
|
|
|
target_compile_options(benchmark PUBLIC -Wno-c2y-extensions)
|
|
|
|
|
|
if(SIMSTR_EMSCRIPTEN_MT)
|
|
|
|
|
|
target_compile_options(benchmark PUBLIC -pthread)
|
|
|
|
|
|
endif()
|
|
|
|
|
|
endif()
|
2025-04-05 14:21:11 +00:00
|
|
|
|
endfunction()
|
|
|
|
|
|
|
2025-11-12 08:07:40 +00:00
|
|
|
|
if(SIMSTR_BENCHMARKS) # AND CMAKE_BUILD_TYPE STREQUAL Release)
|
|
|
|
|
|
set(BUILD_BENCHMARKS ON)
|
2025-04-05 14:21:11 +00:00
|
|
|
|
GBencmark()
|
|
|
|
|
|
add_subdirectory(bench)
|
2025-11-12 08:07:40 +00:00
|
|
|
|
endif()
|
2025-11-09 17:07:23 +00:00
|
|
|
|
|
|
|
|
|
|
# ---- Install rules ----
|
|
|
|
|
|
|
|
|
|
|
|
if(NOT CMAKE_SKIP_INSTALL_RULES)
|
2025-11-12 08:07:40 +00:00
|
|
|
|
include(cmake/install-rules.cmake)
|
2025-11-09 17:07:23 +00:00
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
|
|
# ---- Developer mode ----
|
|
|
|
|
|
|
|
|
|
|
|
if(NOT simstr_DEVELOPER_MODE)
|
2025-11-12 08:07:40 +00:00
|
|
|
|
return()
|
2025-11-09 17:07:23 +00:00
|
|
|
|
elseif(NOT PROJECT_IS_TOP_LEVEL)
|
2025-11-12 08:07:40 +00:00
|
|
|
|
message(
|
|
|
|
|
|
AUTHOR_WARNING
|
|
|
|
|
|
"Developer mode is intended for developers of simstr"
|
|
|
|
|
|
)
|
2025-11-09 17:07:23 +00:00
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
|
|
include(cmake/dev-mode.cmake)
|