Author | Jakob Wakeling <[email protected]> |
Date | 2024-05-18 00:12:17 |
Commit | beca1867c56a8909ae94df3bde0f7c9ea80c4a38 |
Parent | 7f427d9a31853bc24017388e170854cdc9cd9c5d |
Replace build scripts with a Makefile
Diffstat
M | .gitignore | | | 1 | - |
D | BuildUNIX.sh | | | 10 | ---------- |
M | CMakeLists.txt | | | 9 | +++++++-- |
A | Makefile | | | 13 | +++++++++++++ |
M | README.md | | | 7 | ++++--- |
D | TestUNIX.sh | | | 2 | -- |
6 files changed, 24 insertions, 18 deletions
diff --git a/.gitignore b/.gitignore index f563e5a..9580025 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,4 @@ /.vscode/ /bin/ /build/ -/compile_commands.json /lib/ diff --git a/BuildUNIX.sh b/BuildUNIX.sh deleted file mode 100755 index d59505f..0000000 --- a/BuildUNIX.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env sh -dir="$(dirname $(realpath "$0"))" - -cmake -S "${dir}" -B "${dir}/build" \ - -DCMAKE_BUILD_TYPE:STRING=Release \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=1 - -cmake --build "${dir}/build" - -mv -f "${dir}/build/compile_commands.json" "${dir}/compile_commands.json" diff --git a/CMakeLists.txt b/CMakeLists.txt index 175d9f9..ea730b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,18 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.21 FATAL_ERROR) project(libutil LANGUAGES C) +set(CMAKE_C_STANDARD 23) +set(CMAKE_C_STANDARD_REQUIRED TRUE) +set(CMAKE_C_EXTENSIONS FALSE) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin) set(CMAKE_STATIC_LIBRARY_PREFIX "") set(CMAKE_SHARED_LIBRARY_PREFIX "") -file(GLOB SRC ${PROJECT_SOURCE_DIR}/src/*) +file(GLOB_RECURSE SRC CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/src/*.c) +list(FILTER SRC EXCLUDE REGEX "^.*/test_.*$") add_library(libutil_static STATIC ${SRC}) add_library(libutil_shared SHARED ${SRC}) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e994e06 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +.PHONY: all build test help +all: help + +build: ## Build the project + @cmake -S . -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=1 + @cmake --build ./build + +test: build ## Run unit tests + @(cd ./build && ctest) + +help: ## Display help information + @grep -E '^[a-zA-Z_-]+:.*?##.*$$' $(MAKEFILE_LIST) | \ + awk 'BEGIN {FS = ":.*?## *"}; {printf "\033[36m%-6s\033[0m %s\n", $$1, $$2}' diff --git a/README.md b/README.md index cdb7f1f..67832e8 100644 --- a/README.md +++ b/README.md @@ -33,18 +33,19 @@ than being compiled seperately and linked. ### Dependencies -- CMake >= 3.12, to build +- A C23 capable compiler, to build +- CMake >= 3.21, to build ### Building -To build **libutil** and its unit tests on UNIX, run `BuildUNIX.sh`. +To build **libutil**, from the project root, run `make build`. - Binaries will be located in the `bin` directory. - Libraries will be located in the `lib` directory. ### Testing -To run **libutil** unit tests on UNIX, run TestUNIX.sh once built. +To run **libutil** unit tests on UNIX, run `make test`. ## Meta diff --git a/TestUNIX.sh b/TestUNIX.sh deleted file mode 100755 index e2c621d..0000000 --- a/TestUNIX.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env sh -(cd "$(dirname $(realpath "$0"))/build"; ctest)