Skip to content

Commit e3fb2fe

Browse files
committed
cmake: wire up initial support
The project uses a Makefile as the build system for the test executable. This makes it hard to build and test on Windows via MSVC. Introduce support for CMake.
1 parent a0d5987 commit e3fb2fe

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build/

CMakeLists.txt

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
cmake_minimum_required(VERSION 3.25.0)
2+
3+
project(clar LANGUAGES C)
4+
5+
option(BUILD_TESTS "Build test executable" ON)
6+
7+
add_library(clar INTERFACE)
8+
target_sources(clar INTERFACE
9+
clar.c
10+
clar.h
11+
clar/fixtures.h
12+
clar/fs.h
13+
clar/print.h
14+
clar/sandbox.h
15+
clar/summary.h
16+
)
17+
set_target_properties(clar PROPERTIES
18+
C_STANDARD 90
19+
C_STANDARD_REQUIRED ON
20+
C_EXTENSIONS OFF
21+
)
22+
23+
if(BUILD_TESTS)
24+
add_subdirectory(test)
25+
endif()

test/CMakeLists.txt

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
find_package(Python COMPONENTS Interpreter REQUIRED)
2+
3+
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/clar.suite"
4+
COMMAND "${Python_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/generate.py" --output "${CMAKE_CURRENT_BINARY_DIR}"
5+
DEPENDS main.c sample.c
6+
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
7+
)
8+
9+
add_executable(clar_test)
10+
set_target_properties(clar_test PROPERTIES
11+
C_STANDARD 90
12+
C_STANDARD_REQUIRED ON
13+
C_EXTENSIONS OFF
14+
)
15+
16+
# MSVC generates all kinds of warnings. We may want to fix these in the future
17+
# and then unconditionally treat warnings as errors.
18+
if (NOT MSVC)
19+
set_target_properties(clar_test PROPERTIES
20+
COMPILE_WARNING_AS_ERROR ON
21+
)
22+
endif()
23+
24+
target_sources(clar_test PRIVATE
25+
main.c
26+
sample.c
27+
"${CMAKE_CURRENT_BINARY_DIR}/clar.suite"
28+
)
29+
target_compile_definitions(clar_test PRIVATE
30+
CLAR_FIXTURE_PATH="${CMAKE_CURRENT_SOURCE_DIR}/resources/"
31+
_DARWIN_C_SOURCE
32+
_POSIX_C_SOURCE=200809L
33+
)
34+
target_compile_options(clar_test PRIVATE
35+
$<IF:$<CXX_COMPILER_ID:MSVC>,/W4,-Wall>
36+
)
37+
target_include_directories(clar_test PRIVATE
38+
"${CMAKE_SOURCE_DIR}"
39+
"${CMAKE_CURRENT_BINARY_DIR}"
40+
)
41+
target_link_libraries(clar_test clar)

0 commit comments

Comments
 (0)