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
69 changes: 59 additions & 10 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]
build: [1, 2, 3, 4, 5, 6]
include:
# -------------------------------------------------------------------
# CLANG, Release
Expand Down Expand Up @@ -75,6 +75,36 @@ 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 @@ -88,17 +118,17 @@ jobs:
- name: Configure
run: |
cmake .. \
-DCMAKE_INSTALL_PREFIX=../_install \
-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/_install \
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
-DCMAKE_CXX_STANDARD=${{ matrix.cxx-standard }} \
-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: |
cmake --build . \
--target install \
--config ${{ matrix.build-type }}
working-directory: _build
- name: Test
Expand All @@ -115,7 +145,7 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
build: [1, 2]
build: [1, 2, 3]
include:

# Release
Expand All @@ -135,6 +165,16 @@ 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 @@ -146,17 +186,17 @@ jobs:
- name: Configure
run: |
cmake ../. \
-DCMAKE_INSTALL_PREFIX=../_install \
-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/_install \
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
-DCMAKE_CXX_STANDARD=${{ matrix.cxx-standard }} \
-DCMAKE_CXX_FLAGS=${{ matrix.cxx-flags }} \
-DCMAKE_VERBOSE_MAKEFILE:BOOL='OFF' \
-DBUILD_SHARED_LIBS=${{ matrix.build-shared }}
-DBUILD_SHARED_LIBS=${{ matrix.build-shared }} \
-DPYSTRING_HEADER_ONLY=${{ matrix.header-only }}
working-directory: _build
- name: Build
run: |
cmake --build . \
--target install \
--config ${{ matrix.build-type }} \
working-directory: _build
- name: Test
Expand Down Expand Up @@ -192,6 +232,15 @@ 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 @@ -205,19 +254,19 @@ jobs:
# the windows build needs the -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS to work
run: |
cmake ../. \
-DCMAKE_INSTALL_PREFIX=../_install \
-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/_install \
-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS='ON'\
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
-DCMAKE_CXX_STANDARD=${{ matrix.cxx-standard }} \
-DCMAKE_CXX_FLAGS=${{ matrix.cxx-flags }} \
-DCMAKE_VERBOSE_MAKEFILE:BOOL='OFF' \
-DBUILD_SHARED_LIBS=${{ matrix.build-shared }}
-DBUILD_SHARED_LIBS=${{ matrix.build-shared }} \
-DPYSTRING_HEADER_ONLY=${{ matrix.header-only }}
shell: bash
working-directory: _build
- name: Build
run: |
cmake --build . \
--target install \
--config ${{ matrix.build-type }}
shell: bash
working-directory: _build
Expand Down
40 changes: 33 additions & 7 deletions .github/workflows/meson.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ on:
jobs:
meson-build-and-tests:
runs-on: ${{ matrix.platform }}
name: ${{ matrix.platform }}, ${{ matrix.mode.name }} ${{ matrix.flavor }}
name: ${{ matrix.platform }}, ${{ matrix.mode.name }} ${{ matrix.flavor }} ${{ matrix.library_mode }}
strategy:
fail-fast: false
matrix:
flavor:
- debug
- release
library_mode:
- compiled
- header-only
mode:
- name: default
extra_envs: {}
Expand Down Expand Up @@ -61,6 +64,29 @@ 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 @@ -125,21 +151,21 @@ jobs:
if: ${{ matrix.platform == 'windows-2022' }}
env: ${{ matrix.mode.extra_envs }}
run: |
meson setup build-${{ matrix.flavor }} --buildtype=${{ matrix.flavor }} -Ddefault_library=static ${{ matrix.mode.args }} --vsenv
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
- name: Configuring
if: ${{ matrix.platform != 'windows-2022' }}
env: ${{ matrix.mode.extra_envs }}
run: |
meson setup build-${{ matrix.flavor }} --buildtype=${{ matrix.flavor }} ${{ matrix.mode.args }}
meson setup build-${{ matrix.flavor }}-${{ matrix.library_mode }} --buildtype=${{ matrix.flavor }} -Dheader_only=${{ matrix.library_mode == 'header-only' && 'true' || 'false' }} ${{ matrix.mode.args }}
- name: Building
run: |
meson compile -C build-${{ matrix.flavor }}
meson compile -C build-${{ matrix.flavor }}-${{ matrix.library_mode }}
- name: Running tests
env: ${{ matrix.mode.extra_envs }}
run: |
meson test -C build-${{ matrix.flavor }} --timeout-multiplier 0
meson test -C build-${{ matrix.flavor }}-${{ matrix.library_mode }} --timeout-multiplier 0
- uses: actions/upload-artifact@v4
if: failure()
with:
name: ${{ matrix.platform }}-${{ matrix.mode.name }}-${{ matrix.flavor }}-logs
path: build-${{ matrix.flavor }}/meson-logs
name: ${{ matrix.platform }}-${{ matrix.mode.name }}-${{ matrix.flavor }}-${{ matrix.library_mode }}-logs
path: build-${{ matrix.flavor }}-${{ matrix.library_mode }}/meson-logs
60 changes: 43 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.10)
project(pystring LANGUAGES CXX VERSION 1.1.4)

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 @@ -13,14 +14,48 @@ if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT
endif()
message (STATUS "Installation path will be ${CMAKE_INSTALL_PREFIX}")

add_library(pystring
pystring.cpp
pystring.h
)
set_target_properties(pystring PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)
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)
Expand All @@ -29,12 +64,3 @@ enable_testing()
add_test(NAME PyStringTest COMMAND pystring_test)

include(GNUInstallDirs)

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

69 changes: 47 additions & 22 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,58 @@ project(
default_options: ['cpp_std=c++17,c++11', 'warning_level=3'],
)

inc = include_directories('.')
# Option to build as header-only library
header_only = get_option('header_only')

srcs = files('pystring.cpp')
inc = include_directories('.')
hdrs = files('pystring.h')

pystring_lib = library(
'pystring',
srcs,
implicit_include_directories: false,
include_directories: inc,
version: meson.project_version(),
install: true,
)
pystring_dep = declare_dependency(
link_with: pystring_lib,
include_directories: inc,
)
if header_only
# Header-only mode: create a header-only dependency
message('Building pystring as header-only library')

pystring_dep = declare_dependency(
include_directories: inc,
compile_args: ['-DPYSTRING_HEADER_ONLY'],
)

# Install headers for header-only mode
install_headers(hdrs, files('pystring_impl.h'), subdir: 'pystring')

else
# Compiled mode: build as normal library
message('Building pystring as compiled library')

srcs = files('pystring.cpp')

pystring_lib = library(
'pystring',
srcs,
implicit_include_directories: false,
include_directories: inc,
version: meson.project_version(),
install: true,
)

pystring_dep = declare_dependency(
link_with: pystring_lib,
include_directories: inc,
)

# Install headers for compiled mode
install_headers(hdrs, subdir: 'pystring')

# Generate pkg-config file
pkgconfig = import('pkgconfig')
pkgconfig.generate(
pystring_lib,
description: 'C++ functions matching the interface and behavior of python string methods with std::string',
)
endif

meson.override_dependency('pystring', pystring_dep)

# Build and run tests
test(
'PyStringTest',
executable(
Expand All @@ -36,11 +69,3 @@ test(
build_by_default: false,
),
)

install_headers(hdrs, subdir: 'pystring')

pkgconfig = import('pkgconfig')
pkgconfig.generate(
pystring_lib,
description: 'C++ functions matching the interface and behavior of python string methods with std::string',
)
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
option('header_only', type: 'boolean', value: false, description: 'Build as header-only library')
Loading