Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 4c829af
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Wed Aug 21 18:07:16 2024 +0200

    Bump version

commit a6aff78
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Jul 28 21:00:44 2024 +0200

    Update CMakeLists.txt

commit c7a3ced
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Jul 28 19:48:45 2024 +0200

    Update CMakeLists.txt

commit b9c5795
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Jul 28 17:42:45 2024 +0200

    Fixup ci

commit 3a81f92
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Jul 28 15:50:41 2024 +0200

    Update CMakeLists.txt

commit 763241b
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Jul 28 15:50:28 2024 +0200

    Rework tests to conditionally use modules

commit 43b8193
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Jul 28 14:50:41 2024 +0200

    Update CMakeLists.txt

commit fb0ae4a
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Jul 28 14:47:37 2024 +0200

    Another approach for modules

commit 79aae56
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Jul 28 14:12:26 2024 +0200

    Try to fix ci

commit f11a658
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Jul 28 14:07:39 2024 +0200

    Update module_tests.cpp

commit fc72bb2
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Jul 28 14:00:05 2024 +0200

    Try to fix modules ci

commit 3c887ee
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Jul 28 12:58:08 2024 +0200

    Update CMakeLists.txt

commit e9fe7da
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Jul 28 12:54:32 2024 +0200

    Try to fix module tests

commit 46f583f
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Jul 28 02:01:07 2024 +0200

    Update ci.yml

commit 26d0b71
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Jul 28 01:59:10 2024 +0200

    Update ci.yml

commit 4ce3474
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Jul 28 01:53:15 2024 +0200

    Update ci.yml

commit 262d4da
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Jul 28 01:47:55 2024 +0200

    Update ci.yml

commit 8383da3
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Jul 28 01:45:07 2024 +0200

    Update ci.yml

commit d7ce3f6
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Jul 28 01:39:43 2024 +0200

    Update ci.yml

commit 4b824a4
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Jul 28 01:35:10 2024 +0200

    Update module_tests.cpp

commit 9d9a708
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Jul 28 01:27:13 2024 +0200

    Try to fix ci

commit eae9e72
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Jul 28 00:35:44 2024 +0200

    Update CMakeLists.txt

commit bfa74d6
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Jul 28 00:24:07 2024 +0200

    Small fixes

commit e998bc6
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sat Jul 27 23:29:56 2024 +0200

    Update ci.yml

commit b1d1fa4
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sat Jul 27 23:22:41 2024 +0200

    Update ci.yml

commit 5691f9d
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sat Jul 27 23:11:45 2024 +0200

    Update ci.yml

commit 6fd25d2
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sat Jul 27 23:07:57 2024 +0200

    Update ci.yml

commit d3a0b46
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sat Jul 27 22:58:59 2024 +0200

    Update ci.yml

commit 7eaf45e
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sat Jul 27 22:51:57 2024 +0200

    Update sanitize.yml

commit 446b040
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sat Jul 27 22:41:33 2024 +0200

    Try to fix ci

commit 14a467b
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sat Jul 27 22:33:14 2024 +0200

    Try to fix ci

commit 7756003
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sat Jul 27 22:27:02 2024 +0200

    Try to fix ci

commit 3129c54
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sat Jul 27 22:12:17 2024 +0200

    Try to fix ci

commit 512375c
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sat Jul 27 21:40:05 2024 +0200

    Fixup CMake files

commit 72346ac
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sat Jun 8 02:37:55 2024 +0200

    Add module support
  • Loading branch information
z4kn4fein committed Aug 21, 2024
1 parent 6208357 commit 36600b6
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 66 deletions.
36 changes: 27 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ jobs:
macos:
runs-on: ${{matrix.os}}
strategy:
fail-fast: false
matrix:
os: [ macos-latest ]
os: [ macos-13 ]
build: [ Debug, Release ]
compiler: [ clang++ ]
name: ${{matrix.os}} ${{matrix.compiler}} ${{matrix.build}}
Expand All @@ -24,20 +25,30 @@ jobs:
run: ctest -C ${{matrix.build}} -j4

linux:
runs-on: ${{matrix.os}}
runs-on: ${{matrix.platform.os}}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
build: [ Debug, Release ]
compiler: [ g++-11, g++-12, g++-13, clang++-15 ]
name: ${{matrix.os}} ${{matrix.compiler}} ${{matrix.build}}
platform:
- { os: "ubuntu-22.04", cxx: "g++-11", modules: "OFF" }
- { os: "ubuntu-22.04", cxx: "g++-12", modules: "OFF" }
- { os: "ubuntu-24.04", cxx: "g++-13", modules: "OFF" }
- { os: "ubuntu-24.04", cxx: "g++-14", modules: "ON" }
- { os: "ubuntu-22.04", cxx: "clang++-15", modules: "OFF" }
- { os: "ubuntu-24.04", cxx: "clang++-16", modules: "ON" }
name: ${{matrix.platform.os}} ${{matrix.platform.cxx}} ${{matrix.build}}
env:
CXX: ${{matrix.compiler}}
CXX: ${{matrix.platform.cxx}}
CTEST_OUTPUT_ON_FAILURE: 1
steps:
- uses: actions/checkout@v3
- name: Install Ninja
run: sudo apt install ninja-build
- name: cmake
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=${{matrix.build}}
run: cmake -GNinja -S . -B build
-DCMAKE_BUILD_TYPE=${{matrix.build}}
-DSEMVER_BUILD_MODULE=${{matrix.platform.modules}}
- name: build
run: cmake --build build --config ${{matrix.build}} --parallel 4
- name: test
Expand All @@ -47,17 +58,24 @@ jobs:
windows:
runs-on: ${{matrix.os}}
strategy:
fail-fast: false
matrix:
build: [ Debug, Release ]
os: [ windows-2019, windows-latest ]
arch: [ Win32, x64 ]
name: ${{matrix.os}} ${{matrix.arch}} ${{matrix.build}}
modules: [ "OFF", "ON" ]
exclude:
- os: windows-2019
modules: "ON"
name: ${{matrix.os}} ${{matrix.arch}} ${{matrix.build}} ${{matrix.modules}}
env:
CTEST_OUTPUT_ON_FAILURE: 1
steps:
- uses: actions/checkout@v3
- name: cmake
run: cmake -S . -B build -A ${{matrix.arch}} -DCMAKE_BUILD_TYPE=${{matrix.build}}
run: cmake -S . -B build -A ${{matrix.arch}}
-DCMAKE_BUILD_TYPE=${{matrix.build}}
-DSEMVER_BUILD_MODULE=${{matrix.modules}}
- name: build
run: cmake --build build --config ${{matrix.build}} --parallel 4
- name: test
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/sanitize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
compiler: [ clang++-15 ]
os: [ ubuntu-20.04 ]
flags:
- "-fsanitize=leak -g -O1 -fno-omit-frame-pointer" #LSAN
- "-fsanitize=address -g -O1 -fno-omit-frame-pointer" #ASAN
- "-fsanitize=thread -g -O1 -fno-omit-frame-pointer" #TSAN
- "-fsanitize=undefined -fno-omit-frame-pointer" #UBSAN
name: ${{matrix.os}} ${{matrix.compiler}} ${{matrix.build}} ${{matrix.flags}}
name: ${{matrix.os}} ${{matrix.flags}}
env:
CXX: ${{ matrix.compiler }}
CXX: clang++
CXXFLAGS: ${{ matrix.flags }}
CTEST_OUTPUT_ON_FAILURE: 1
steps:
Expand Down
79 changes: 53 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
cmake_minimum_required(VERSION 3.14)
project(semver LANGUAGES CXX VERSION 0.3.3)

set(TOP_PROJECT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(TOP_PROJECT ON)
endif()

option(SEMVER_BUILD_TESTS "Enable builds of tests" ${TOP_PROJECT})
option(SEMVER_INSTALL "Enable install target" ${TOP_PROJECT})
option(SEMVER_BUILD_MODULE "Build as C++20 module" OFF)

if (SEMVER_BUILD_MODULE)
cmake_minimum_required(VERSION 3.28)
else()
cmake_minimum_required(VERSION 3.14)
endif()

include(GNUInstallDirs)
project(semver LANGUAGES CXX VERSION 0.4.0)

## --------------------------------------------------------------------
## Build
Expand All @@ -22,14 +26,29 @@ message(VERBOSE " CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}")
message(VERBOSE " CMAKE_CXX_COMPILER_VERSION: ${CMAKE_CXX_COMPILER_VERSION}")
message(VERBOSE " CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")

add_library(${PROJECT_NAME} INTERFACE)
add_library (${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_include_directories(
${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
if(SEMVER_BUILD_MODULE)
add_library(${PROJECT_NAME})
set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF)
target_sources(${PROJECT_NAME}
PUBLIC
FILE_SET CXX_MODULES FILES module/semver.cppm)
target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20)
else()
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(
${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
endif()

target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
add_library (${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

## --------------------------------------------------------------------
## TESTS
Expand All @@ -42,21 +61,22 @@ endif()
## --------------------------------------------------------------------
## INSTALL
## --------------------------------------------------------------------
include(CMakePackageConfigHelpers)
if (SEMVER_INSTALL)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

configure_package_config_file(
${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}
PATH_VARS CMAKE_INSTALL_FULL_INCLUDEDIR)
configure_package_config_file(
${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}
PATH_VARS CMAKE_INSTALL_FULL_INCLUDEDIR)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
ARCH_INDEPENDENT)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
ARCH_INDEPENDENT)

if (SEMVER_INSTALL)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

Expand All @@ -69,9 +89,16 @@ if (SEMVER_INSTALL)
NAMESPACE ${PROJECT_NAME}::
FILE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-targets.cmake)

install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
if(SEMVER_BUILD_MODULE)
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
FILE_SET CXX_MODULES DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/module
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
else()
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()

install(EXPORT ${PROJECT_NAME}-targets
NAMESPACE ${PROJECT_NAME}::
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Peter Csajtai
Copyright (c) 2024 Peter Csajtai

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ provides the ability to **parse**, **compare**, and **increment** semantic versi
FetchContent_Declare(
cpp-semver
GIT_REPOSITORY https://github.com/z4kn4fein/cpp-semver.git
GIT_TAG v0.3.3)
GIT_TAG v0.4.0)
FetchContent_MakeAvailable(cpp-semver)
```

Expand Down
37 changes: 22 additions & 15 deletions include/semver/semver.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
License: MIT (http://opensource.org/licenses/MIT).
Copyright (c) 2022 Peter Csajtai <peter.csajtai@outlook.com>
Copyright (c) 2024 Peter Csajtai <peter.csajtai@outlook.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -25,6 +25,7 @@ SOFTWARE.
#ifndef Z4KN4FEIN_SEMVER_H
#define Z4KN4FEIN_SEMVER_H

#ifndef SEMVER_MODULE
#include <ostream>
#include <string>
#include <regex>
Expand All @@ -38,11 +39,17 @@ SOFTWARE.
#include <string_view>
#endif
#endif
#endif

#ifdef SEMVER_MODULE
#define SEMVER_EXPORT export
#else
#define SEMVER_EXPORT
#endif

namespace semver
{
const std::string default_prerelease_part = "0";
const char prerelease_delimiter = '.';
const std::string numbers = "0123456789";
const std::string prerelease_allowed_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-";
const std::string version_pattern = "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)"
Expand All @@ -52,7 +59,7 @@ namespace semver
"?(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))"
"?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$";

struct semver_exception : public std::runtime_error {
SEMVER_EXPORT struct semver_exception : public std::runtime_error {
explicit semver_exception(const std::string& message) : std::runtime_error(message) { }
};

Expand Down Expand Up @@ -117,14 +124,14 @@ namespace semver
[[nodiscard]] int compare(const prerelease_part& other) const {
if (m_numeric && !other.m_numeric) return -1;
if (!m_numeric && other.m_numeric) return 1;
if (m_numeric && other.m_numeric) {
if (m_numeric) {
return (m_numeric_value < other.m_numeric_value) ? -1 : (m_numeric_value > other.m_numeric_value);
}
return (m_value < other.m_value) ? -1 : (m_value > other.m_value);
}
};

class prerelease_descriptor {
SEMVER_EXPORT class prerelease_descriptor {
private:
std::vector<prerelease_part> m_parts;
std::string prerelease_str;
Expand All @@ -133,7 +140,7 @@ namespace semver
: m_parts(parts) {
if (parts.empty()) prerelease_str = "";
for (const auto &part : parts) {
if (!prerelease_str.empty()) prerelease_str += prerelease_delimiter;
if (!prerelease_str.empty()) prerelease_str += ".";
prerelease_str += part.value();
}
}
Expand Down Expand Up @@ -196,7 +203,7 @@ namespace semver
static prerelease_descriptor parse(const std::string& prerelease_part_str) {
if (prerelease_part_str.empty()) return empty();
std::vector<prerelease_part> prerelease_parts;
std::vector<std::string> parts = split(prerelease_part_str, prerelease_delimiter);
std::vector<std::string> parts = split(prerelease_part_str, '.');
for(auto& part : parts) {
prerelease_parts.emplace_back(part);
}
Expand All @@ -212,9 +219,9 @@ namespace semver
}
};

enum inc { major, minor, patch, prerelease };
SEMVER_EXPORT enum inc { major, minor, patch, prerelease };

class version {
SEMVER_EXPORT class version {
private:
uint64_t m_major;
uint64_t m_minor;
Expand Down Expand Up @@ -375,18 +382,18 @@ namespace semver
}
};

inline std::ostream & operator<<(std::ostream& str, const version& version) {
SEMVER_EXPORT inline std::ostream & operator<<(std::ostream& str, const version& version) {
for (const auto s : version.str()) str.put(s);
return str;
}

namespace literals
{
inline version operator""_v(const char* text, std::size_t length) {
SEMVER_EXPORT inline version operator""_v(const char* text, std::size_t length) {
return version::parse(std::string(text, length));
}

inline version operator""_lv(const char* text, std::size_t length) {
SEMVER_EXPORT inline version operator""_lv(const char* text, std::size_t length) {
return version::parse(std::string(text, length), false);
}
}
Expand All @@ -396,9 +403,9 @@ namespace semver
#ifdef __cpp_lib_format
#if __cpp_lib_format >= 201907L

template <>
struct std::formatter<semver::version> : std::formatter<std::string_view> {
template <typename FormatContext>
template <class CharT>
struct std::formatter<semver::version, CharT> : std::formatter<std::string_view> {
template <class FormatContext>
auto format(const semver::version& version, FormatContext& ctx) const {
return std::formatter<std::string_view>::format(version.str(), ctx);
}
Expand Down
Loading

0 comments on commit 36600b6

Please sign in to comment.