From 8d8ec95faab82a014216f016b569a3b8d9d43c4a Mon Sep 17 00:00:00 2001 From: Aleksandr Orefkov Date: Sat, 15 Nov 2025 13:07:52 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20shared=20=D1=81=D0=B1=D0=BE=D1=80=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 38 +++++++++++++++++--------------------- readme.md | 2 +- tests/CMakeLists.txt | 12 +----------- 3 files changed, 19 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c32dfdb..7b20b27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ include(FetchContent) project( simstr - VERSION 1.0.0 + VERSION 1.2.4 DESCRIPTION "Yet another string library" HOMEPAGE_URL "https://github.com/orefkov/simstr" LANGUAGES CXX @@ -24,12 +24,6 @@ endif() option(SIMSTR_BUILD_TESTS "Построить тесты" ON) option(SIMSTR_BENCHMARKS "Построить замеры производительности" Off) -# При OFF - строится обычная статическая библиотека. -# При On - simstr собирается как статическая библиотека, которую потом встроят в shared библиотеку, -# и она будет свои функции объявлять как экспортируемые. Потребители же будут собираться с указанием, -# что функции - импортируемые -option(SIMSTR_IN_SHARED "Функции simstr будут экспортироваться или импортироваться" Off) - add_library(simstr_simstr src/sstring.cpp src/simple_unicode.cpp @@ -54,12 +48,20 @@ if(EMSCRIPTEN) endif() endif(EMSCRIPTEN) -if (NOT CMAKE_CXX_SIMULATE_ID) - set (CMAKE_CXX_SIMULATE_ID "None") -endif() -# Для MSVC подключаем natvis файл для красивой отладки -if(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC OR ${CMAKE_CXX_SIMULATE_ID} STREQUAL MSVC) - target_link_options(simstr_simstr PUBLIC "/natvis:${CMAKE_CURRENT_SOURCE_DIR}/for_debug/simstr.natvis") +if (${CMAKE_BUILD_TYPE} STREQUAL Debug) + if (NOT CMAKE_CXX_SIMULATE_ID) + set (CMAKE_CXX_SIMULATE_ID "None") + endif() + # Для 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_SOURCE_DIR}/for_debug/simstr.natvis + ${CMAKE_CURRENT_BINARY_DIR}/simstr.natvis + ) + target_link_options(simstr_simstr PUBLIC "/natvis:simstr.natvis") + endif() endif() set_target_properties( @@ -90,18 +92,12 @@ add_simdutf() target_link_libraries(simstr_simstr PUBLIC simdutf::simdutf) -if(SIMSTR_IN_SHARED) +if(BUILD_SHARED_LIBS) # Всем объявляем, что мы будем в shared библиотеке add_compile_definitions(SIMSTR_IN_SHARED) # Себе объявим, что мы должны экспортировать функции target_compile_definitions(simstr_simstr PRIVATE SIMSTR_EXPORT) - # Пример построения shared библиотеки, которая включит в себя simstr. - # Как при этом создать экзешник, пользующийся этой dll - пример в tests/CMakeLists.txt - # Нельзя объявить библиотеку без исходников, добавим просто .h файл - add_library(simstr_dll SHARED include/simstr/sstring.h) - # simstr должна войти в simstr_dll целиком - target_link_libraries(simstr_dll PRIVATE "$") -endif(SIMSTR_IN_SHARED) +endif(BUILD_SHARED_LIBS) if(SIMSTR_BUILD_TESTS) enable_testing() diff --git a/readme.md b/readme.md index 84f8b33..ee5ceef 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,7 @@ # simstr - библиотека строковых объектов и функций [![CMake on multiple platforms](https://github.com/orefkov/simstr/actions/workflows/cmake-multi-platform.yml/badge.svg)](https://github.com/orefkov/simstr/actions/workflows/cmake-multi-platform.yml) -Версия 1.0. +Версия 1.2.4. В этой библиотеке содержится реализация нескольких видов строковых объектов и различных алгоритмов для работы со строками. diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2e7b302..42e6e50 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -4,17 +4,7 @@ add_executable(testStr test_str.cpp) -if (NOT SIMSTR_IN_SHARED) - target_link_libraries(testStr simstr::simstr GTest::gtest_main) -else() - # Пример создания экзешника, если simstr экспортируются из dll. - # Так как мы подключаем только simstr_dll, и входящие в неё либы не видны - # нужно вручную задать каталоги include и стандарт C++20 - target_link_libraries(testStr simstr_dll GTest::gtest_main) - get_target_property(SIMSTR_INCLUDES simstr::simstr INCLUDE_DIRECTORIES) - target_include_directories(testStr PRIVATE ${SIMSTR_INCLUDES}) - target_compile_features(testStr PUBLIC cxx_std_20) -endif() +target_link_libraries(testStr simstr::simstr GTest::gtest_main) add_test(NAME testStr COMMAND testStr)