Skip to content

Commit 0e2931a

Browse files
authored
Improve build (#10)
1 parent 1bbc2e1 commit 0e2931a

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

CMakeLists.txt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ cmake_minimum_required(VERSION 3.25)
22

33
project(tinyclib VERSION 0.1.2 LANGUAGES C)
44

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

8081
# Build tests
81-
if(BUILD_TESTS)
82+
if(TL_BUILD_TESTS)
8283
include(CTest)
8384
include(FetchContent)
8485
set(TEST_TARGETS
@@ -96,12 +97,6 @@ if(BUILD_TESTS)
9697
GIT_TAG v2.6.1
9798
)
9899
FetchContent_MakeAvailable(Unity)
99-
FetchContent_GetProperties(Unity)
100-
101-
if(NOT TARGET Unity)
102-
add_library(Unity STATIC ${unity_SOURCE_DIR}/src/unity.c)
103-
endif()
104-
target_include_directories(Unity PUBLIC ${unity_SOURCE_DIR}/src)
105100

106101
enable_testing()
107102
foreach(t IN LISTS TEST_TARGETS)

CMakePresets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"cacheVariables": {
1313
"CMAKE_BUILD_TYPE": "Debug",
1414
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
15-
"BUILD_TESTS": "ON"
15+
"TL_BUILD_TESTS": "ON"
1616
}
1717
}
1818
],

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ TEST_FILES := tests/unit/*.c
1111
EXAMPLE_FILES := $(wildcard examples/*/*.c)
1212
ALL_FILES := $(SRC_FILES) $(TEST_FILES) $(EXAMPLE_FILES)
1313

14+
PRESET ?= default
15+
1416
.PHONY: help install build clean clean-bin test format lint check check-all fix
1517

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

2224
configure: ## Configure cmake
23-
cmake --preset default
25+
cmake --preset $(PRESET)
2426

2527
build: ## Build the project
26-
@test -d "$(BUILD_DIR)" || cmake --preset default
27-
cmake --build --preset default
28+
@test -d "$(BUILD_DIR)" || cmake --preset $(PRESET)
29+
cmake --build --preset $(PRESET)
2830

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

0 commit comments

Comments
 (0)