Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 2 additions & 54 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
build: [1, 2, 3, 4, 5, 6]
build: [1, 2, 3, 4]
include:
# -------------------------------------------------------------------
# CLANG, Release
Expand Down Expand Up @@ -75,36 +75,6 @@ jobs:
compiler-desc: gcc
os: ubuntu-latest


# -------------------------------------------------------------------
# CLANG, Release header only
# -------------------------------------------------------------------
- build: 5
build-type: Release
build-shared: 'ON'
header-only: 'ON'
cxx-standard: 17
cxx-compiler: clang++
cxx-flags: ''
cc-compiler: clang
compiler-desc: clang
os: ubuntu-latest

# -------------------------------------------------------------------
# gcc, Release header only
# -------------------------------------------------------------------
- build: 6
build-type: Release
build-shared: 'ON'
header-only: 'ON'
cxx-standard: 17
cxx-compiler: g++
cxx-flags: ''
cc-compiler: gcc
compiler-desc: gcc
os: ubuntu-latest


env:
CXX: ${{ matrix.cxx-compiler }}
CC: ${{ matrix.cc-compiler }}
Expand All @@ -124,7 +94,6 @@ jobs:
-DCMAKE_CXX_FLAGS=${{ matrix.cxx-flags }} \
-DCMAKE_VERBOSE_MAKEFILE:BOOL='OFF' \
-DBUILD_SHARED_LIBS=${{ matrix.build-shared }} \
-DPYSTRING_HEADER_ONLY=${{ matrix.header-only }}
working-directory: _build
- name: Build
run: |
Expand All @@ -145,7 +114,7 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
build: [1, 2, 3]
build: [1, 2]
include:

# Release
Expand All @@ -165,16 +134,6 @@ jobs:
cxx-flags: ''
os: macos-latest


# Release header only
- build: 3
build-type: Release
build-shared: 'ON'
header-only: 'ON'
cxx-standard: 17
cxx-flags: ''
os: macos-latest

steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
Expand All @@ -192,7 +151,6 @@ jobs:
-DCMAKE_CXX_FLAGS=${{ matrix.cxx-flags }} \
-DCMAKE_VERBOSE_MAKEFILE:BOOL='OFF' \
-DBUILD_SHARED_LIBS=${{ matrix.build-shared }} \
-DPYSTRING_HEADER_ONLY=${{ matrix.header-only }}
working-directory: _build
- name: Build
run: |
Expand Down Expand Up @@ -232,15 +190,6 @@ jobs:
cxx-flags: ''
os: windows-latest

# Release header only
- build: 3
build-type: Release
build-shared: 'ON'
header-only: 'ON'
cxx-standard: 17
cxx-flags: ''
os: windows-latest


steps:
- name: Checkout
Expand All @@ -261,7 +210,6 @@ jobs:
-DCMAKE_CXX_FLAGS=${{ matrix.cxx-flags }} \
-DCMAKE_VERBOSE_MAKEFILE:BOOL='OFF' \
-DBUILD_SHARED_LIBS=${{ matrix.build-shared }} \
-DPYSTRING_HEADER_ONLY=${{ matrix.header-only }}
shell: bash
working-directory: _build
- name: Build
Expand Down
40 changes: 7 additions & 33 deletions .github/workflows/meson.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ on:
jobs:
meson-build-and-tests:
runs-on: ${{ matrix.platform }}
name: ${{ matrix.platform }}, ${{ matrix.mode.name }} ${{ matrix.flavor }} ${{ matrix.library_mode }}
name: ${{ matrix.platform }}, ${{ matrix.mode.name }} ${{ matrix.flavor }}
strategy:
fail-fast: false
matrix:
flavor:
- debug
- release
library_mode:
- compiled
- header-only
mode:
- name: default
extra_envs: {}
Expand Down Expand Up @@ -64,29 +61,6 @@ jobs:
- macos-latest

exclude:
# Only test header-only with a subset of configurations to reduce CI time
# Test header-only only with default compiler in release mode
- library_mode: header-only
flavor: debug
- library_mode: header-only
mode:
name: gcc
- library_mode: header-only
mode:
name: clang
- library_mode: header-only
mode:
name: sanitize
- library_mode: header-only
mode:
name: sanitize+asanonly
- library_mode: header-only
mode:
name: clang+sanitize
- library_mode: header-only
mode:
name: clang-cl+sanitize

# clang-cl only makes sense on windows.
- platform: ubuntu-22.04
mode:
Expand Down Expand Up @@ -151,21 +125,21 @@ jobs:
if: ${{ matrix.platform == 'windows-2022' }}
env: ${{ matrix.mode.extra_envs }}
run: |
meson setup build-${{ matrix.flavor }}-${{ matrix.library_mode }} --buildtype=${{ matrix.flavor }} -Ddefault_library=static -Dheader_only=${{ matrix.library_mode == 'header-only' && 'true' || 'false' }} ${{ matrix.mode.args }} --vsenv
meson setup build-${{ matrix.flavor }} --buildtype=${{ matrix.flavor }} -Ddefault_library=static ${{ matrix.mode.args }} --vsenv
- name: Configuring
if: ${{ matrix.platform != 'windows-2022' }}
env: ${{ matrix.mode.extra_envs }}
run: |
meson setup build-${{ matrix.flavor }}-${{ matrix.library_mode }} --buildtype=${{ matrix.flavor }} -Dheader_only=${{ matrix.library_mode == 'header-only' && 'true' || 'false' }} ${{ matrix.mode.args }}
meson setup build-${{ matrix.flavor }} --buildtype=${{ matrix.flavor }} ${{ matrix.mode.args }}
- name: Building
run: |
meson compile -C build-${{ matrix.flavor }}-${{ matrix.library_mode }}
meson compile -C build-${{ matrix.flavor }}
- name: Running tests
env: ${{ matrix.mode.extra_envs }}
run: |
meson test -C build-${{ matrix.flavor }}-${{ matrix.library_mode }} --timeout-multiplier 0
meson test -C build-${{ matrix.flavor }} --timeout-multiplier 0
- uses: actions/upload-artifact@v4
if: failure()
with:
name: ${{ matrix.platform }}-${{ matrix.mode.name }}-${{ matrix.flavor }}-${{ matrix.library_mode }}-logs
path: build-${{ matrix.flavor }}-${{ matrix.library_mode }}/meson-logs
name: ${{ matrix.platform }}-${{ matrix.mode.name }}-${{ matrix.flavor }}-logs
path: build-${{ matrix.flavor }}/meson-logs
129 changes: 81 additions & 48 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
cmake_minimum_required(VERSION 3.10)
project(pystring LANGUAGES CXX VERSION 1.1.4)
project(pystring LANGUAGES CXX VERSION 1.2.0)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

option (BUILD_SHARED_LIBS "Build shared libraries (set to OFF to build static libs)" ON)
option(PYSTRING_HEADER_ONLY "Build as header-only library" OFF)

# If the user hasn't configured cmake with an explicit
# -DCMAKE_INSTALL_PREFIX=..., then set it to safely install into ./dist, to
Expand All @@ -19,52 +18,86 @@ endif()
message (STATUS "Installation path will be ${CMAKE_INSTALL_PREFIX}")
include(GNUInstallDirs)

if(PYSTRING_HEADER_ONLY)
message(STATUS "Building pystring as header-only library")
add_library(pystring INTERFACE)

target_compile_definitions(pystring INTERFACE PYSTRING_HEADER_ONLY)

target_include_directories(pystring INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

# Install both headers for header-only mode
install(FILES pystring.h pystring_impl.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
)
else()
message(STATUS "Building pystring as compiled library")

add_library(pystring
pystring.cpp
pystring.h
)

set_target_properties(pystring PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)

install(TARGETS pystring
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
)

install (FILES pystring.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
COMPONENT developer
)

endif()

# Test executable

add_executable (pystring_test test.cpp)
TARGET_LINK_LIBRARIES (pystring_test pystring)
# --- Compiled library target: pystring::pystring ---
add_library(pystring
pystring.cpp
pystring.h
)

set_target_properties(pystring PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)

target_include_directories(pystring PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

install(TARGETS pystring
EXPORT pystringTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)


# --- Header-only target: pystring::pystring_header_only ---
add_library(pystring_header_only INTERFACE)

target_compile_definitions(pystring_header_only INTERFACE PYSTRING_HEADER_ONLY)

target_include_directories(pystring_header_only INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

install(TARGETS pystring_header_only
EXPORT pystringTargets
)

install(FILES pystring.h pystring_impl.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
)

# --- Export & package config ---
install(EXPORT pystringTargets
FILE pystringTargets.cmake
NAMESPACE pystring::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/pystring
)

include(CMakePackageConfigHelpers)

configure_package_config_file(
cmake/pystringConfig.cmake.in
pystringConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/pystring
)

write_basic_package_version_file(
pystringConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/pystringConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/pystringConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/pystring
)

# --- Tests ---
add_executable(pystring_test test.cpp)
target_link_libraries(pystring_test pystring)

add_executable(pystring_test_header_only test.cpp)
target_link_libraries(pystring_test_header_only pystring_header_only)

# Compile-time check that PYSTRING_HEADER_ONLY propagates correctly
add_executable(pystring_test_header_only_define test_header_only_define.cpp)
target_link_libraries(pystring_test_header_only_define pystring_header_only)

enable_testing()
add_test(NAME PyStringTest COMMAND pystring_test)

add_test(NAME PyStringTestHeaderOnly COMMAND pystring_test_header_only)
8 changes: 8 additions & 0 deletions cmake/pystringConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@PACKAGE_INIT@

# Prevent double-definition errors
if(NOT TARGET pystring::pystring AND NOT TARGET pystring::pystring_header_only)
include("${CMAKE_CURRENT_LIST_DIR}/pystringTargets.cmake")
endif()

check_required_components(pystring)
Loading
Loading