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
11 changes: 3 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ cmake_minimum_required(VERSION 3.25)

project(tinyclib VERSION 0.1.2 LANGUAGES C)

# Settings
# Settings and options
option(TL_BUILD_TESTS "Build tinyclib tests" ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
Expand Down Expand Up @@ -78,7 +79,7 @@ add_library(tinyclib::tinyclib ALIAS tinyclib)
set_target_properties(tinyclib PROPERTIES POSITION_INDEPENDENT_CODE ON)

# Build tests
if(BUILD_TESTS)
if(TL_BUILD_TESTS)
include(CTest)
include(FetchContent)
set(TEST_TARGETS
Expand All @@ -96,12 +97,6 @@ if(BUILD_TESTS)
GIT_TAG v2.6.1
)
FetchContent_MakeAvailable(Unity)
FetchContent_GetProperties(Unity)

if(NOT TARGET Unity)
add_library(Unity STATIC ${unity_SOURCE_DIR}/src/unity.c)
endif()
target_include_directories(Unity PUBLIC ${unity_SOURCE_DIR}/src)

enable_testing()
foreach(t IN LISTS TEST_TARGETS)
Expand Down
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"BUILD_TESTS": "ON"
"TL_BUILD_TESTS": "ON"
}
}
],
Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ TEST_FILES := tests/unit/*.c
EXAMPLE_FILES := $(wildcard examples/*/*.c)
ALL_FILES := $(SRC_FILES) $(TEST_FILES) $(EXAMPLE_FILES)

PRESET ?= default

.PHONY: help install build clean clean-bin test format lint check check-all fix

help: ## Show available make targets
Expand All @@ -20,11 +22,11 @@ help: ## Show available make targets
@awk 'BEGIN {FS = ":.*## "} /^[a-zA-Z_-]+:.*## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST)

configure: ## Configure cmake
cmake --preset default
cmake --preset $(PRESET)

build: ## Build the project
@test -d "$(BUILD_DIR)" || cmake --preset default
cmake --build --preset default
@test -d "$(BUILD_DIR)" || cmake --preset $(PRESET)
cmake --build --preset $(PRESET)

clean: ## Remove build directory
@test -n "$(CURDIR)" && [ "$(CURDIR)" != "/" ]
Expand Down