Исправил shared сборку

This commit is contained in:
Aleksandr Orefkov 2025-11-15 13:07:52 +03:00
parent 4ddb1ae236
commit bddb3ae306
3 changed files with 4 additions and 26 deletions

View File

@ -5,7 +5,7 @@ include(FetchContent)
project( project(
simstr simstr
VERSION 1.0.0 VERSION 1.2.3
DESCRIPTION "Yet another string library" DESCRIPTION "Yet another string library"
HOMEPAGE_URL "https://github.com/orefkov/simstr" HOMEPAGE_URL "https://github.com/orefkov/simstr"
LANGUAGES CXX LANGUAGES CXX
@ -24,12 +24,6 @@ endif()
option(SIMSTR_BUILD_TESTS "Построить тесты" ON) option(SIMSTR_BUILD_TESTS "Построить тесты" ON)
option(SIMSTR_BENCHMARKS "Построить замеры производительности" Off) option(SIMSTR_BENCHMARKS "Построить замеры производительности" Off)
# При OFF - строится обычная статическая библиотека.
# При On - simstr собирается как статическая библиотека, которую потом встроят в shared библиотеку,
# и она будет свои функции объявлять как экспортируемые. Потребители же будут собираться с указанием,
# что функции - импортируемые
option(SIMSTR_IN_SHARED "Функции simstr будут экспортироваться или импортироваться" Off)
add_library(simstr_simstr add_library(simstr_simstr
src/sstring.cpp src/sstring.cpp
src/simple_unicode.cpp src/simple_unicode.cpp
@ -90,17 +84,11 @@ add_simdutf()
target_link_libraries(simstr_simstr PUBLIC simdutf::simdutf) target_link_libraries(simstr_simstr PUBLIC simdutf::simdutf)
if(SIMSTR_IN_SHARED) if(BUILD_SHARED_LIBS)
# Всем объявляем, что мы будем в shared библиотеке # Всем объявляем, что мы будем в shared библиотеке
add_compile_definitions(SIMSTR_IN_SHARED) add_compile_definitions(SIMSTR_IN_SHARED)
# Себе объявим, что мы должны экспортировать функции # Себе объявим, что мы должны экспортировать функции
target_compile_definitions(simstr_simstr PRIVATE SIMSTR_EXPORT) 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 "$<LINK_LIBRARY:WHOLE_ARCHIVE,simstr::simstr>")
endif(SIMSTR_IN_SHARED) endif(SIMSTR_IN_SHARED)
if(SIMSTR_BUILD_TESTS) if(SIMSTR_BUILD_TESTS)

View File

@ -1,7 +1,7 @@
# simstr - библиотека строковых объектов и функций # 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) [![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.3.
В этой библиотеке содержится реализация нескольких видов строковых объектов и различных алгоритмов для работы со строками. В этой библиотеке содержится реализация нескольких видов строковых объектов и различных алгоритмов для работы со строками.

View File

@ -4,17 +4,7 @@
add_executable(testStr test_str.cpp) add_executable(testStr test_str.cpp)
if (NOT SIMSTR_IN_SHARED) target_link_libraries(testStr simstr::simstr GTest::gtest_main)
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()
add_test(NAME testStr COMMAND testStr) add_test(NAME testStr COMMAND testStr)