Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/build-freebsd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ jobs:
prepare: |
pkg install -y cmake
run: |
cmake -B build -S ${{github.workspace}} -DENABLE_TESTS=1
cmake -B build -S ${{github.workspace}} -DCWK_ENABLE_TESTS=1
cmake --build build
ctest --test-dir build
6 changes: 3 additions & 3 deletions .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ jobs:
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DENABLE_TESTS=1
-DENABLE_COVERAGE=1
-DENABLE_SANITIZER=${{ matrix.sanitizers }}
-DCWK_ENABLE_TESTS=1
-DCWK_ENABLE_COVERAGE=1
-DCWK_ENABLE_SANITIZER=${{ matrix.sanitizers }}
-S ${{ github.workspace }}
- name: Build
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DENABLE_TESTS=1
-DCWK_ENABLE_TESTS=1
-S ${{ github.workspace }}
- name: Build
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DCMAKE_C_FLAGS=/wd5105
-DENABLE_TESTS=1
-DCWK_ENABLE_TESTS=1
-S ${{ github.workspace }}
- name: Build
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
Expand Down
29 changes: 21 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.9.2)
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)

# set project name
project(cwalk
Expand All @@ -7,6 +7,19 @@ project(cwalk
HOMEPAGE_URL "https://likle.github.io/cwalk/"
LANGUAGES C)

# configure default options
option(CWK_BUILD_SHARED "Builds as a shared library" "${BUILD_SHARED_LIBS}")
option(CWK_ENABLE_COVERAGE "Enables runtime code coverage" "${ENABLE_COVERAGE}")
option(CWK_ENABLE_TESTS "Enables building test executables" "${ENABLE_TESTS}")
option(CWK_IGNORE_WARNINGS "Allows compilation to continue with compiler warnings" "${IGNORE_WARNINGS}")

set(CWK_ENABLE_SANITIZER "${ENABLE_SANITIZER}" CACHE STRING "Enables the specified sanitizer")

# set variables corresponding to options
if(CWK_BUILD_SHARED)
set(BUILD_SHARED_LIBS ON)
endif()

# include utilities
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(EnableWarnings)
Expand All @@ -24,20 +37,20 @@ set(SOURCE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src")
set(TEST_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/test")

# enable coverage if requested
if(ENABLE_COVERAGE)
if(CWK_ENABLE_COVERAGE)
message("-- Coverage enabled")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
endif()

# enable sanitizer
if(ENABLE_SANITIZER)
if(CWK_ENABLE_SANITIZER)
message("-- Sanitizer enabled")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=${ENABLE_SANITIZER}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=${ENABLE_SANITIZER}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=${CWK_ENABLE_SANITIZER}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=${CWK_ENABLE_SANITIZER}")
endif()

# add the main executable
# add the main library
add_library(cwalk
"${INCLUDE_DIRECTORY}/cwalk.h"
"${SOURCE_DIRECTORY}/cwalk.c")
Expand All @@ -50,12 +63,12 @@ set_target_properties(cwalk PROPERTIES PUBLIC_HEADER "${INCLUDE_DIRECTORY}/cwalk
set_target_properties(cwalk PROPERTIES DEFINE_SYMBOL CWK_EXPORTS)

# add shared library macro
if(BUILD_SHARED_LIBS)
if(CWK_BUILD_SHARED)
target_compile_definitions(cwalk PUBLIC CWK_SHARED)
endif()

# enable tests
if(ENABLE_TESTS)
if(CWK_ENABLE_TESTS)
message("-- Tests enabled")
enable_testing()

Expand Down
6 changes: 3 additions & 3 deletions cmake/EnableWarnings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ function(enable_warnings target)
if(MSVC)
target_compile_definitions(${target} PRIVATE _CRT_SECURE_NO_WARNINGS)
target_compile_options(${target} PRIVATE /W4)
if (NOT IGNORE_WARNINGS)
if (NOT CWK_IGNORE_WARNINGS)
target_compile_options(${target} PRIVATE /WX)
endif()
elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
target_compile_options(${target} PRIVATE -Wall)
target_compile_options(${target} PRIVATE -Wextra)
target_compile_options(${target} PRIVATE -Wpedantic)
target_compile_options(${target} PRIVATE -Wno-gnu-zero-variadic-macro-arguments)
if (NOT IGNORE_WARNINGS)
if (NOT CWK_IGNORE_WARNINGS)
target_compile_options(${target} PRIVATE -Werror)
endif()
elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
target_compile_options(${target} PRIVATE -Wall)
target_compile_options(${target} PRIVATE -Wextra)
target_compile_options(${target} PRIVATE -Wpedantic)
if (NOT IGNORE_WARNINGS)
if (NOT CWK_IGNORE_WARNINGS)
target_compile_options(${target} PRIVATE -Werror)
endif()
endif()
Expand Down
4 changes: 2 additions & 2 deletions docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ cmake ..
make
```
# Running Tests
In order to run tests, cwalk needs to be built with tests enabled. There is a ``ENABLE_TESTS`` flag for that. It can be passed to the cmake command like this:
In order to run tests, cwalk needs to be built with tests enabled. There is a ``CWK_ENABLE_TESTS`` flag for that. It can be passed to the cmake command like this:
```
cmake .. -DENABLE_TESTS=1
cmake .. -DCWK_ENABLE_TESTS=1
```

After building **cwalk** you can run tests to ensure everything is fine. In order to do that, make sure that you are in the build folder and then execute the test program:
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ install_headers('include/cwalk.h')

cwalk_dep = declare_dependency(include_directories: 'include', link_with: cwalk)

if get_option('ENABLE_TESTS')
if get_option('CWK_ENABLE_TESTS')
subdir('test')
endif

Expand Down
2 changes: 1 addition & 1 deletion meson_options.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
option('ENABLE_TESTS', type: 'boolean', value: false, description: 'Enables building test executables')
option('CWK_ENABLE_TESTS', type: 'boolean', value: false, description: 'Enables building test executables')