diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7a6e58f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,264 @@ +name: CI & Library Install + +on: + push: + branches: [ main, master ] + tags: [ 'v*' ] + pull_request: + branches: [ main, master ] + +jobs: + # ========================================================================= + # 1. Native OS Builds (Windows & Linux Ubuntu) + # ========================================================================= + native-builds: + name: Native (${{ matrix.os }} - ${{ matrix.build_type }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + build_type: [Release, Debug] + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Extract Version from Git Tag + shell: bash + run: | + if [[ "${GITHUB_REF}" == refs/tags/* ]]; then + VER="${GITHUB_REF_NAME#v}" + else + VER="1.0.0" + fi + echo "VERSION=${VER}" >> $GITHUB_ENV + echo "Building version: ${VER}" + + - name: Checkout cpp-utils dependency + uses: actions/checkout@v4 + with: + repository: jayasankar-jp/cpp-utils + path: cpp-utils + + - name: Build & Install cpp-utils + run: | + cmake -B cpp-utils/build -S cpp-utils -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_INSTALL_PREFIX=${{ runner.temp }}/install_dir + cmake --build cpp-utils/build --config ${{ matrix.build_type }} + cmake --install cpp-utils/build --config ${{ matrix.build_type }} + + - name: Configure CMake + run: > + cmake -B build + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -DCMAKE_INSTALL_PREFIX=${{ runner.temp }}/install_dir + -DCMAKE_PREFIX_PATH=${{ runner.temp }}/install_dir + + - name: Build Library & Tests + run: cmake --build build --config ${{ matrix.build_type }} + + - name: Run CTest Suite + run: ctest --test-dir build -C ${{ matrix.build_type }} --output-on-failure + + - name: Install Library + run: cmake --install build --config ${{ matrix.build_type }} + + - name: Create Versioned Archive (Linux tar.gz) + if: runner.os == 'Linux' + run: | + cd ${{ runner.temp }} + tar -czvf logger-cpp-v${{ env.VERSION }}-${{ matrix.os }}-${{ matrix.build_type }}.tar.gz -C install_dir . + + - name: Create Versioned Archive (Windows zip) + if: runner.os == 'Windows' + shell: powershell + run: | + cd ${{ runner.temp }} + Compress-Archive -Path install_dir\* -DestinationPath logger-cpp-v$env:VERSION-${{ matrix.os }}-${{ matrix.build_type }}.zip + + - name: Upload Versioned Linux Archive + if: runner.os == 'Linux' + uses: actions/upload-artifact@v4 + with: + name: logger-cpp-v${{ env.VERSION }}-${{ matrix.os }}-${{ matrix.build_type }}.tar.gz + path: ${{ runner.temp }}/logger-cpp-v${{ env.VERSION }}-${{ matrix.os }}-${{ matrix.build_type }}.tar.gz + + - name: Upload Versioned Windows Archive + if: runner.os == 'Windows' + uses: actions/upload-artifact@v4 + with: + name: logger-cpp-v${{ env.VERSION }}-${{ matrix.os }}-${{ matrix.build_type }}.zip + path: ${{ runner.temp }}/logger-cpp-v${{ env.VERSION }}-${{ matrix.os }}-${{ matrix.build_type }}.zip + + # ========================================================================= + # 2. Linux Distributions Matrix (Ubuntu, Debian, Fedora, Alpine, Arch) + # ========================================================================= + linux-distros: + name: Distro (${{ matrix.distro }}) + runs-on: ubuntu-latest + container: + image: ${{ matrix.image }} + strategy: + fail-fast: false + matrix: + include: + - distro: ubuntu-22.04 + image: ubuntu:22.04 + pkg_cmd: apt-get update && apt-get install -y cmake build-essential tar git + - distro: ubuntu-24.04 + image: ubuntu:24.04 + pkg_cmd: apt-get update && apt-get install -y cmake build-essential tar git + - distro: debian-latest + image: debian:latest + pkg_cmd: apt-get update && apt-get install -y cmake build-essential tar git + - distro: fedora-latest + image: fedora:latest + pkg_cmd: dnf install -y cmake gcc-c++ make tar git + - distro: alpine-latest + image: alpine:latest + pkg_cmd: apk add --no-cache cmake make g++ build-base linux-headers tar git bash + - distro: archlinux-latest + image: archlinux:latest + pkg_cmd: pacman -Syu --noconfirm cmake gcc make tar git + + steps: + - name: Install Toolchain & Dependencies + run: ${{ matrix.pkg_cmd }} + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Checkout cpp-utils dependency + uses: actions/checkout@v4 + with: + repository: jayasankar-jp/cpp-utils + path: cpp-utils + + - name: Build & Install cpp-utils + run: | + cmake -B cpp-utils/build -S cpp-utils -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local + cmake --build cpp-utils/build + cmake --install cpp-utils/build + + - name: Extract Version from Git Tag + shell: bash + run: | + if [[ "${GITHUB_REF}" == refs/tags/* ]]; then + VER="${GITHUB_REF_NAME#v}" + else + VER="1.0.0" + fi + echo "VERSION=${VER}" >> $GITHUB_ENV + + - name: Configure CMake + run: cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/install_dir + + - name: Build Library & Tests + run: cmake --build build + + - name: Run CTest Suite + run: ctest --test-dir build --output-on-failure + + - name: Install Library + run: cmake --install build + + - name: Create Versioned Tarball (.tar.gz) + run: | + cd /tmp + tar -czvf logger-cpp-v${{ env.VERSION }}-${{ matrix.distro }}-x86_64.tar.gz -C install_dir . + + - name: Upload Versioned Distro Archive + uses: actions/upload-artifact@v4 + with: + name: logger-cpp-v${{ env.VERSION }}-${{ matrix.distro }}-x86_64.tar.gz + path: /tmp/logger-cpp-v${{ env.VERSION }}-${{ matrix.distro }}-x86_64.tar.gz + + # ========================================================================= + # 3. Raspberry Pi & ARM Architectures (ARMv7 32-bit & AArch64 64-bit) + # ========================================================================= + raspberry-pi-arm: + name: Raspberry Pi (${{ matrix.arch }}) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - arch: armv7 + distro: ubuntu22.04 + - arch: aarch64 + distro: ubuntu22.04 + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Extract Version from Git Tag + shell: bash + run: | + if [[ "${GITHUB_REF}" == refs/tags/* ]]; then + VER="${GITHUB_REF_NAME#v}" + else + VER="1.0.0" + fi + echo "VERSION=${VER}" >> $GITHUB_ENV + + - name: Run Build, Test, Install & Packaging on ARM Runner (${{ matrix.arch }}) + uses: uraimo/run-on-arch-action@v2.8.0 + with: + arch: ${{ matrix.arch }} + distro: ${{ matrix.distro }} + githubToken: ${{ github.token }} + env: | + VERSION: ${{ env.VERSION }} + install: | + apt-get update + apt-get install -y cmake g++ make tar git + run: | + ulimit -s unlimited || true + git clone https://github.com/jayasankar-jp/cpp-utils.git cpp-utils + cmake -B cpp-utils/build -S cpp-utils -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-O0" -DCMAKE_INSTALL_PREFIX=/usr/local + cmake --build cpp-utils/build + cmake --install cpp-utils/build + + cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-O0" -DCMAKE_INSTALL_PREFIX=/tmp/install_dir + cmake --build build + ctest --test-dir build --output-on-failure + cmake --install build + + cd /tmp + tar -czvf logger-cpp-v${VERSION}-raspberrypi-${{ matrix.arch }}.tar.gz -C install_dir . + + - name: Upload Versioned Raspberry Pi Tarball + uses: actions/upload-artifact@v4 + with: + name: logger-cpp-v${{ env.VERSION }}-raspberrypi-${{ matrix.arch }}.tar.gz + path: /tmp/logger-cpp-v${{ env.VERSION }}-raspberrypi-${{ matrix.arch }}.tar.gz + + # ========================================================================= + # 4. Automatic GitHub Release Publishing (Triggered on Git Tag Push: v*) + # ========================================================================= + create-github-release: + name: Create GitHub Release + if: startsWith(github.ref, 'refs/tags/') + needs: [native-builds, linux-distros, raspberry-pi-arm] + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Download All Build Artifacts + uses: actions/download-artifact@v4 + with: + path: release_artifacts + + - name: Collect & Flatten Binary Archives + run: | + mkdir release_dist + find release_artifacts -type f \( -name "*.tar.gz" -o -name "*.zip" \) -exec cp {} release_dist/ \; + ls -la release_dist/ + + - name: Publish Official GitHub Release + uses: softprops/action-gh-release@v2 + with: + files: release_dist/* + generate_release_notes: true diff --git a/CMakeLists.txt b/CMakeLists.txt index 28dbb44..062fa11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,22 @@ project(Logger VERSION 1.0 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) +# ----------------------------- +# Dependencies (cpp-utils) +# ----------------------------- +include(FetchContent) +find_package(cpp-utils QUIET) + +if(NOT cpp-utils_FOUND) + message(STATUS "cpp-utils not found locally. Fetching from GitHub repository...") + FetchContent_Declare( + cpp-utils + GIT_REPOSITORY https://github.com/jayasankar-jp/cpp-utils.git + GIT_TAG master + ) + FetchContent_MakeAvailable(cpp-utils) +endif() + # ----------------------------- # Library Target # ----------------------------- @@ -15,25 +31,39 @@ add_library(Logger STATIC src/FileWriter.cpp ) -# Proper include visibility +# Proper include visibility & dependencies target_include_directories(Logger PUBLIC $ $ ) +if(TARGET internalLib) + target_link_libraries(Logger PUBLIC internalLib) + target_include_directories(Logger PUBLIC $) +elseif(TARGET cpp-utils::cpp-utils) + target_link_libraries(Logger PUBLIC cpp-utils::cpp-utils) +else() + # Fallback to prefix path includes if installed to custom prefix + target_include_directories(Logger PUBLIC $) +endif() + # ----------------------------- # Test Executable # ----------------------------- -add_executable(test +enable_testing() + +add_executable(logger_test test/Test.cpp ) -target_link_libraries(test PRIVATE Logger) +target_link_libraries(logger_test PRIVATE Logger) -set_target_properties(test PROPERTIES +set_target_properties(logger_test PROPERTIES OUTPUT_NAME "test.exe" ) +add_test(NAME LoggerTest COMMAND logger_test) + add_executable(benchmark test/Benchmark.cpp ) diff --git a/README.md b/README.md index bfd9a3e..3ba949a 100644 --- a/README.md +++ b/README.md @@ -19,47 +19,72 @@ cd logger-cpp --- -# ⚙️ Installation -## 📦 Install Dependency: cpp-utils +# ⚙️ Installation & Build -This project requires **cpp-utils**. +## 📋 Prerequisites +- C++17 compliant compiler (`g++`, `clang++`, or MSVC) +- CMake 3.15 or higher +--- + +## 📦 Option 1: Install from Release Binaries (Pre-built Archives) + +Download the pre-compiled archive for your OS/architecture from [GitHub Releases](https://github.com/jayasankar-jp/logger-cpp/releases). + +### Linux (Ubuntu / Debian / Fedora / Alpine / Arch / Raspberry Pi) ```bash -git clone https://github.com/jayasankar-jp/cpp-utils.git -cd cpp-utils -mkdir build -cd build -cmake .. -make -sudo make install +# Download and extract to system path or custom directory (e.g. /usr/local) +sudo tar -xzvf logger-cpp-v1.0.0-ubuntu-22.04-x86_64.tar.gz -C /usr/local ``` -## ✅ Build logger-cpp -Navigate to your project directory. +### Windows +Extract the downloaded `.zip` package to your desired directory (e.g., `C:\Program Files\Logger`). + +--- + +## 🛠️ Option 2: Build & Install from Source + +> 💡 **Note:** If `cpp-utils` is not installed on your system, CMake will **automatically fetch and build it** for you during configuration! + +### Quick Build & Install (Automatic Dependency Resolution) ```bash git clone git@github.com:jayasankar-jp/logger-cpp.git cd logger-cpp -mkdir build -cd build -cmake .. -make + +# Configure (Fetches cpp-utils automatically if needed) +cmake -B build -DCMAKE_BUILD_TYPE=Release + +# Build +cmake --build build + +# Install (Linux/macOS) +sudo cmake --install build ``` --- -## ✅ Install - +### Optional: Pre-installing `cpp-utils` Manually +If you prefer to install `cpp-utils` onto your system beforehand: ```bash -sudo make install +git clone https://github.com/jayasankar-jp/cpp-utils.git +cd cpp-utils +cmake -B build -DCMAKE_BUILD_TYPE=Release +cmake --build build +sudo cmake --install build +cd .. +``` + +# Install (Windows - Run as Administrator / Powershell) +cmake --install build --prefix "C:\Program Files\Logger" ``` -### 📦 Installed Files +### 📦 Installed Files Location -| Type | Path | -| ------------ | ------------------------------ | -| Library | `/usr/local/lib/libLogger.a` | -| Headers | `/usr/local/include/` | -| CMake Config | `/usr/local/lib/cmake/Logger/` | +| Type | Linux / macOS Path | Windows Default Path | +| ------------ | ------------------------------ | ----------------------------------- | +| Library | `/usr/local/lib/libLogger.a` | `/lib/Logger.lib` | +| Headers | `/usr/local/include/` | `/include/` | +| CMake Config | `/usr/local/lib/cmake/Logger/` | `/lib/cmake/Logger/` | ---