-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from dr8co/dev
Initial Pre-release
- Loading branch information
Showing
72 changed files
with
6,377 additions
and
1,115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"output": "CHANGELOG.md", | ||
"template": "keepachangelog", | ||
"unreleased": true, | ||
"commitLimit": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
name: CMake Builds | ||
|
||
on: | ||
push: | ||
branches: [ "main", "dev" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
fail-fast: false | ||
|
||
matrix: | ||
os: [ ubuntu-latest, windows-latest, macos-latest ] | ||
build_type: [ Debug, Release ] | ||
c_compiler: [ gcc-13, clang, cl ] | ||
include: | ||
- os: windows-latest | ||
c_compiler: cl | ||
cpp_compiler: cl | ||
- os: ubuntu-latest | ||
c_compiler: gcc-13 | ||
cpp_compiler: g++-13 | ||
- os: ubuntu-latest | ||
c_compiler: clang | ||
cpp_compiler: clang++-15 | ||
- os: macos-latest | ||
c_compiler: clang | ||
cpp_compiler: clang++ | ||
|
||
exclude: | ||
- os: windows-latest | ||
c_compiler: gcc-13 | ||
- os: windows-latest | ||
c_compiler: clang | ||
- os: ubuntu-latest | ||
c_compiler: cl | ||
- os: macos-latest | ||
c_compiler: cl | ||
- os: macos-latest | ||
c_compiler: gcc-13 | ||
|
||
steps: | ||
- name: Install Ninja | ||
# Install Ninja, a build system that can be used as an alternative to make. | ||
# Ninja is faster and recommended for large projects. | ||
if: matrix.os == 'ubuntu-latest' | ||
run: sudo apt-get install ninja-build -y | ||
|
||
- uses: actions/checkout@v4 | ||
|
||
- name: Set reusable strings | ||
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. | ||
id: strings | ||
shell: bash | ||
run: | | ||
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" | ||
- name: Set the generator | ||
id: set-generator | ||
shell: bash | ||
run: | | ||
if [[ "${{ runner.os }}" == "Windows" ]]; then | ||
echo "generator='Visual Studio 17 2022'" >> "$GITHUB_OUTPUT" | ||
elif [[ "${{ runner.os }}" == "macOS" ]]; then | ||
echo "generator=Xcode" >> "$GITHUB_OUTPUT" | ||
else | ||
echo "generator=Ninja" >> "$GITHUB_OUTPUT" | ||
fi | ||
- name: Configure CMake | ||
run: > | ||
cmake -B ${{ steps.strings.outputs.build-output-dir }} | ||
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} | ||
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }} | ||
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} | ||
-S ${{ github.workspace }} -G ${{ steps.set-generator.outputs.generator }} | ||
- name: Build | ||
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} -j 4 | ||
|
||
- name: Test | ||
working-directory: ${{ steps.strings.outputs.build-output-dir }} | ||
run: ctest --build-config ${{ matrix.build_type }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
name: CPack Multi-Platform | ||
|
||
on: | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
fail-fast: false | ||
|
||
matrix: | ||
os: [ubuntu-latest, windows-latest, macos-latest] | ||
build_type: [Release] | ||
c_compiler: [gcc-13, clang, cl] | ||
include: | ||
- os: windows-latest | ||
c_compiler: cl | ||
cpp_compiler: cl | ||
- os: ubuntu-latest | ||
c_compiler: gcc-13 | ||
cpp_compiler: g++-13 | ||
- os: macos-latest | ||
c_compiler: clang | ||
cpp_compiler: clang++ | ||
exclude: | ||
- os: windows-latest | ||
c_compiler: gcc-13 | ||
- os: windows-latest | ||
c_compiler: clang | ||
- os: ubuntu-latest | ||
c_compiler: cl | ||
- os: ubuntu-latest | ||
c_compiler: clang | ||
- os: macos-latest | ||
c_compiler: cl | ||
- os: macos-latest | ||
c_compiler: gcc-13 | ||
|
||
steps: | ||
- name: Upgrade Build Tools and install Ninja | ||
if: matrix.os == 'ubuntu-latest' | ||
run: sudo apt update && sudo apt upgrade -y && sudo apt install ninja-build -y | ||
|
||
- uses: actions/checkout@v4 | ||
|
||
- name: Set reusable strings | ||
id: strings | ||
shell: bash | ||
run: | | ||
if [[ "${{ runner.os }}" == "Windows" ]]; then | ||
echo "build-output-dir=${{ github.workspace }}\build" >> "$GITHUB_OUTPUT" | ||
else | ||
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" | ||
fi | ||
- name: Set the generator | ||
id: set-generator | ||
shell: bash | ||
run: | | ||
if [[ "${{ runner.os }}" == "Windows" ]]; then | ||
echo "generator='Visual Studio 17 2022'" >> "$GITHUB_OUTPUT" | ||
elif [[ "${{ runner.os }}" == "macOS" ]]; then | ||
echo "generator='Xcode'" >> "$GITHUB_OUTPUT" | ||
else | ||
echo "generator='Ninja'" >> "$GITHUB_OUTPUT" | ||
fi | ||
- name: Configure CMake for Static Build | ||
run: > | ||
cmake -B ${{ steps.strings.outputs.build-output-dir }} | ||
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} | ||
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }} | ||
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} | ||
-S ${{ github.workspace }} -G ${{ steps.set-generator.outputs.generator }} | ||
-DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DBUILD_EXAMPLES=OFF | ||
- name: Build Static Library | ||
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} -j 4 | ||
|
||
- name: Configure CMake for Shared Build | ||
run: > | ||
cmake -B ${{ steps.strings.outputs.build-output-dir }} | ||
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} | ||
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }} | ||
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} | ||
-S ${{ github.workspace }} -G ${{ steps.set-generator.outputs.generator }} | ||
-DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF -DBUILD_EXAMPLES=OFF | ||
- name: Build Shared Library | ||
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} -j 4 | ||
|
||
- name: Package | ||
working-directory: ${{ steps.strings.outputs.build-output-dir }} | ||
run: cpack | ||
|
||
- name: Upload Release Artifacts | ||
if: matrix.build_type == 'Release' | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: "${{ matrix.os }}-${{ matrix.c_compiler }}-release" | ||
path: "${{ steps.strings.outputs.build-output-dir }}/Packages" | ||
overwrite: true | ||
if-no-files-found: 'warn' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -517,3 +517,6 @@ FodyWeavers.xsd | |
# JetBrains Rider | ||
*.sln.iml | ||
|
||
Doxyfile | ||
|
||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"schedule": "daily", | ||
"aggressiveCompression": false, | ||
"compressWiki": true, | ||
"minKBReduced": 10 | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,175 @@ | ||
cmake_minimum_required(VERSION 3.28) | ||
|
||
project(LiteStr C CXX) | ||
project(LiteString | ||
VERSION 0.1.0 | ||
DESCRIPTION "A lightweight byte string library for C" | ||
HOMEPAGE_URL "https://github.com/dr8co/LiteString" | ||
LANGUAGES C CXX) | ||
|
||
set(CMAKE_C_STANDARD 23) | ||
# C23 is not supported by MSVC, as of cl 19.37.32824 | ||
if (NOT MSVC) | ||
set(CMAKE_C_STANDARD 23) | ||
endif () | ||
|
||
add_library(LiteStr STATIC lite_str.h lite_str.c) | ||
set(CMAKE_C_STANDARD_REQUIRED ON) | ||
|
||
# Google Test requires at least C++14 | ||
set(CMAKE_CXX_STANDARD 20) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
# Options | ||
option(BUILD_SHARED_LIBS "Build shared libraries" OFF) | ||
option(BUILD_EXAMPLES "Build examples" ON) | ||
option(BUILD_TESTS "Build tests" ON) | ||
|
||
# Additional compile options for the Debug build | ||
if (NOT MSVC AND CMAKE_C_COMPILER_ID MATCHES "GNU|Clang|AppleClang") | ||
if (CMAKE_BUILD_TYPE STREQUAL "Debug") | ||
add_compile_options( | ||
-Wall | ||
-Wextra | ||
-Werror | ||
-Wpedantic | ||
-g | ||
) | ||
endif () | ||
endif () | ||
|
||
# Sanitizers for debugging and testing | ||
# GCC does not support all sanitizers, so Clang is recommended for this purpose. Requires llvm-symbolizer. | ||
# The build type should be RelWithDebInfo (or Debug, adjust the variables appropriately) for sanitizers to work properly. | ||
if (${CMAKE_C_COMPILER_ID} STREQUAL "Clang") | ||
# Common flags for all sanitizers | ||
set(sanitizer_common_flags "-fno-omit-frame-pointer -g -O1") | ||
|
||
# Address, leak, undefined, integer, nullability sanitizers | ||
set(address_sanitizer_flags "-fsanitize=address,leak,undefined,integer,nullability") | ||
|
||
# Thread sanitizer, cannot be used with address sanitizer | ||
set(thread_sanitizer_flags "-fsanitize=thread -fPIE") | ||
|
||
# Memory sanitizer, cannot be used with address sanitizer. | ||
set(memory_sanitizer_flags "-fsanitize=memory -fPIE -fno-optimize-sibling-calls") | ||
|
||
# Add flags for Release with Debug Info build | ||
if (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") | ||
add_compile_options( | ||
${sanitizer_common_flags} | ||
${address_sanitizer_flags} | ||
) | ||
endif () | ||
endif () | ||
|
||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") | ||
|
||
add_library(lite-string) | ||
target_sources(lite-string PRIVATE lite_string.c) | ||
add_library(LiteString::lite-string ALIAS lite-string) | ||
|
||
# Set the include directory for the library | ||
target_include_directories(lite-string PUBLIC | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> | ||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> | ||
) | ||
|
||
set_target_properties(lite-string PROPERTIES | ||
VERSION ${PROJECT_VERSION} | ||
SOVERSION 1 | ||
PUBLIC_HEADER lite_string.h | ||
) | ||
|
||
# Additional definitions for the library | ||
if (${CMAKE_C_COMPILER_ID} STREQUAL "Clang" OR ${CMAKE_C_COMPILER_ID} STREQUAL "GNU") | ||
target_compile_definitions(lite-string PRIVATE _GNU_SOURCE) | ||
endif () | ||
|
||
include(GNUInstallDirs) | ||
|
||
install(TARGETS lite-string | ||
EXPORT LiteStringTargets | ||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT libraries | ||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT libraries | ||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT libraries | ||
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" COMPONENT headers | ||
) | ||
|
||
install(EXPORT LiteStringTargets | ||
FILE LiteStringTargets.cmake | ||
NAMESPACE LiteString:: | ||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/LiteString" | ||
COMPONENT CMakeConfig | ||
) | ||
|
||
include(CMakePackageConfigHelpers) | ||
|
||
configure_package_config_file(LiteStringConfig.cmake.in | ||
"${CMAKE_CURRENT_BINARY_DIR}/LiteStringConfig.cmake" | ||
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/LiteString") | ||
|
||
write_basic_package_version_file( | ||
"${CMAKE_CURRENT_BINARY_DIR}/LiteStringConfigVersion.cmake" | ||
VERSION "${PROJECT_VERSION}" | ||
COMPATIBILITY AnyNewerVersion) | ||
|
||
install(FILES | ||
"${CMAKE_CURRENT_BINARY_DIR}/LiteStringConfig.cmake" | ||
"${CMAKE_CURRENT_BINARY_DIR}/LiteStringConfigVersion.cmake" | ||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/LiteString" | ||
COMPONENT CMakeConfig | ||
) | ||
|
||
configure_file(liblite-string.pc.in liblite-string.pc @ONLY) | ||
|
||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/liblite-string.pc" | ||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" | ||
COMPONENT pkgconfig | ||
) | ||
|
||
# Notify about MinGW builds in the version_info.txt file | ||
if (MINGW) | ||
set(C_COMPILER_EXTRA_INFO "(For MinGW)") | ||
endif () | ||
|
||
# Get the current date and time in UTC | ||
string(TIMESTAMP CURRENT_DATE "%Y-%m-%d %H:%M:%S" UTC) | ||
|
||
# Get the build flags | ||
set(FLAGS_VAR "CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE}") | ||
string(TOUPPER "${FLAGS_VAR}" FLAGS_VAR) | ||
string(CONFIGURE "@${FLAGS_VAR}@" BUILD_FLAGS) | ||
|
||
# Configure the version_info.txt file | ||
configure_file(version_info.txt.in "${CMAKE_CURRENT_BINARY_DIR}/version_info.txt" @ONLY) | ||
|
||
# Install the version_info.txt file | ||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/version_info.txt" | ||
DESTINATION "${CMAKE_INSTALL_DATADIR}/LiteString" | ||
COMPONENT data | ||
) | ||
|
||
# Examples | ||
if (BUILD_EXAMPLES) | ||
add_subdirectory(examples) | ||
endif () | ||
|
||
# Testing | ||
if (BUILD_TESTS) | ||
include(FetchContent) | ||
FetchContent_Declare( | ||
googletest | ||
URL https://github.com/google/googletest/archive/f10e11fb27301fba21caa71030bb5024e67aa135.zip) | ||
|
||
# For Windows: Prevent overriding the parent project's compiler/linker settings | ||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) | ||
|
||
FetchContent_GetProperties(googletest) | ||
if (NOT googletest_POPULATED) | ||
FetchContent_Populate(googletest) | ||
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL) | ||
endif () | ||
|
||
enable_testing() | ||
add_subdirectory(tests) | ||
endif () | ||
|
||
include(Packing) |
Oops, something went wrong.