Skip to content

Commit

Permalink
cmake: wire up initial support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pks-t committed Sep 15, 2024
1 parent a0d5987 commit e3fb2fe
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build/
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.25.0)

project(clar LANGUAGES C)

option(BUILD_TESTS "Build test executable" ON)

add_library(clar INTERFACE)
target_sources(clar INTERFACE
clar.c
clar.h
clar/fixtures.h
clar/fs.h
clar/print.h
clar/sandbox.h
clar/summary.h
)
set_target_properties(clar PROPERTIES
C_STANDARD 90
C_STANDARD_REQUIRED ON
C_EXTENSIONS OFF
)

if(BUILD_TESTS)
add_subdirectory(test)
endif()
41 changes: 41 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
find_package(Python COMPONENTS Interpreter REQUIRED)

add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/clar.suite"
COMMAND "${Python_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/generate.py" --output "${CMAKE_CURRENT_BINARY_DIR}"
DEPENDS main.c sample.c
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)

add_executable(clar_test)
set_target_properties(clar_test PROPERTIES
C_STANDARD 90
C_STANDARD_REQUIRED ON
C_EXTENSIONS OFF
)

# MSVC generates all kinds of warnings. We may want to fix these in the future
# and then unconditionally treat warnings as errors.
if (NOT MSVC)
set_target_properties(clar_test PROPERTIES
COMPILE_WARNING_AS_ERROR ON
)
endif()

target_sources(clar_test PRIVATE
main.c
sample.c
"${CMAKE_CURRENT_BINARY_DIR}/clar.suite"
)
target_compile_definitions(clar_test PRIVATE
CLAR_FIXTURE_PATH="${CMAKE_CURRENT_SOURCE_DIR}/resources/"
_DARWIN_C_SOURCE
_POSIX_C_SOURCE=200809L
)
target_compile_options(clar_test PRIVATE
$<IF:$<CXX_COMPILER_ID:MSVC>,/W4,-Wall>
)
target_include_directories(clar_test PRIVATE
"${CMAKE_SOURCE_DIR}"
"${CMAKE_CURRENT_BINARY_DIR}"
)
target_link_libraries(clar_test clar)

0 comments on commit e3fb2fe

Please sign in to comment.