Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BasedOnStyle: LLVM
ReflowComments: false
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[*]
end_of_line = lf

[*.{c,cpp,h,hpp}]
indent_style = space
indent_size = 4

6 changes: 6 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ jobs:
run: |
sudo apt install libgtest-dev cmake

- name: Format check
if: matrix.runner == 'ubuntu-latest'
run: |
sudo apt install clang-format
make format-check

- name: Test with CMake (-DSIMPLEINI_USE_SYSTEM_GTEST=OFF)
run: |
cmake -S . -B build -DSIMPLEINI_USE_SYSTEM_GTEST=OFF
Expand Down
51 changes: 51 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Convenience targets around CMake. The build system remains CMake; this Makefile
# only configures build/ and invokes cmake/ctest/clang-format from the tree root.

BUILD_DIR := build
CMAKE := cmake
CLANG_FORMAT ?= clang-format
FORMAT_FILES := SimpleIni.h $(wildcard tests/*.cpp)

CMAKE_FLAGS := -DCMAKE_BUILD_TYPE=Debug

JOBS := $(shell nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)

.PHONY: all help configure build test format format-check check clean

all: build

help:
@echo "SimpleIni developer targets:"
@echo " make configure Configure the CMake build in $(BUILD_DIR)/"
@echo " make build Build tests (warnings are errors)"
@echo " make test Run tests via ctest"
@echo " make format Apply clang-format to sources"
@echo " make format-check Verify formatting (no writes)"
@echo " make check format-check, build, and test"
@echo " make clean Remove $(BUILD_DIR)/"

configure: $(BUILD_DIR)/CMakeCache.txt

$(BUILD_DIR)/CMakeCache.txt:
$(CMAKE) -S . -B $(BUILD_DIR) $(CMAKE_FLAGS)

build: configure
$(CMAKE) --build $(BUILD_DIR) -j $(JOBS)

test: build
$(CMAKE) -E chdir $(BUILD_DIR) ctest --output-on-failure

format:
@command -v $(CLANG_FORMAT) >/dev/null 2>&1 \
|| { echo "error: $(CLANG_FORMAT) not found; install clang-format" >&2; exit 1; }
$(CLANG_FORMAT) -i $(FORMAT_FILES)

format-check:
@command -v $(CLANG_FORMAT) >/dev/null 2>&1 \
|| { echo "error: $(CLANG_FORMAT) not found; install clang-format" >&2; exit 1; }
$(CLANG_FORMAT) --dry-run --Werror $(FORMAT_FILES)

check: format-check test

clean:
rm -rf $(BUILD_DIR)
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,22 @@ That's it! The library is ready to use.

# Build and Test

While the library itself doesn't require building, you can build and run the test suite using CMake.
While the library itself doesn't require building, you can build and run the test suite using CMake. A top-level `Makefile` wraps the usual CMake workflow for local development:

```bash
make help # list targets
make check # format-check, build, and test
make format # apply clang-format
make format-check # verify formatting
make test # run ctest
make clean # remove build/
```

Requires `cmake`, a C++17 compiler, and `clang-format` for format targets. Test builds use `-Werror`. CMake remains the build system.

CI (`.github/workflows/build-and-test.yml`) runs `make format-check` on Linux only; tests run on Linux (x64 and arm64), Windows, and macOS.

Direct CMake usage:

```bash
# Configure the project
Expand Down
Loading
Loading