summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: c0e8af0fdd124a49814adb79319154e621861f61 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
cmake_minimum_required(VERSION 3.25)

project(aplwc
	VERSION 0.0.1
	LANGUAGES C
)

set(CMAKE_C_STANDARD 90)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)

add_library(common INTERFACE)
target_include_directories(common INTERFACE
	"src/include"
)
target_compile_options(common INTERFACE
	$<$<CONFIG:Debug>:
		-O0
		-Wall
		-Wextra
		-Wpedantic
		-Werror
		-fsanitize=address,undefined
		-DAPLWC_BUILD_TYPE_DEBUG
	>

	$<$<CONFIG:Coverage>:
		-O0
		--coverage
		-fcondition-coverage
		-DAPLWC_BUILD_TYPE_COVERAGE
	>

	$<$<CONFIG:Release>:
		-DAPLWC_BUILD_TYPE_RELEASE
	>
)
target_link_options(common INTERFACE
	$<$<CONFIG:Debug>:
		-fsanitize=address,undefined
	>

	$<$<CONFIG:Coverage>:
		--coverage
		-fcondition-coverage
	>
)

add_library(aplwc
	src/lib/main.c
	src/lib/memory.c
)
target_link_libraries(aplwc PRIVATE common)

add_executable(aplwc-repl
	src/bin/main.c
)
target_link_libraries(aplwc-repl PRIVATE common aplwc)

enable_testing()
file(GLOB TEST_SOURCES CONFIGURE_DEPENDS "tests/*.c")
foreach(source ${TEST_SOURCES})
	get_filename_component(name "${source}" NAME_WE)
	set(test_bin "testbin-${name}")
	add_executable("${test_bin}" "${source}")
	target_link_libraries("${test_bin}" PRIVATE common aplwc)
	add_test(NAME "${name}" COMMAND "${test_bin}")
endforeach()

add_test(NAME "aplwc-repl" COMMAND "aplwc-repl")