Skip to content

Commit 9c8a2cf

Browse files
committed
build: use cmake and ninja
This change begins the transition to cmake and ninja instead of make for building. There is some work to be done in terms of generating coverage data though, as 'ninja cov' fails for some reason. Fixes #285 Signed-off-by: Christopher Friedt <[email protected]>
1 parent aa6c474 commit 9c8a2cf

File tree

5 files changed

+492
-2
lines changed

5 files changed

+492
-2
lines changed

.codecov.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
ignore:
22
- "util/"
33
- "*-test.cpp"
4-

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
4646
- name: Setup C++ CEnvironment
4747
run: |
48-
sudo apt install -y cmake clang clang-tidy gcovr
48+
sudo apt install -y cmake gcovr
4949
sudo sh .scripts/build-and-install-libgtest-libraries.sh
5050
5151
- name: Build C++

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,15 @@
66
.*project
77
.settings/
88
__pycache__/
9+
CMakeFiles/
10+
CMakeCache.txt
11+
cmake_install.cmake
12+
.ninja_deps
13+
.ninja_log
14+
CTestTestfile.cmake
15+
build.ninja
16+
rules.ninja
17+
*.capture
18+
*.info
19+
*.total
20+
Testing/

CMakeLists.txt

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright (c) 2021 Christopher Friedt
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
project(leetcode)
6+
cmake_minimum_required(VERSION 3.13.0)
7+
set(CMAKE_CXX_STANDARD 14)
8+
9+
enable_testing()
10+
11+
find_package(PkgConfig)
12+
pkg_search_module(GTEST REQUIRED gtest)
13+
14+
include_directories(util)
15+
16+
# all warnings as errors
17+
add_compile_options(-Wall -Wextra -Werror)
18+
19+
# code coverage
20+
if(CMAKE_COMPILER_IS_GNUCXX)
21+
set(CMAKE_BUILD_TYPE "Debug")
22+
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
23+
include(CodeCoverage)
24+
set(COVERAGE_EXCLUDES "util/*")
25+
append_coverage_compiler_flags()
26+
add_custom_target(cov)
27+
endif()
28+
29+
file(GLOB APP_SOURCES *-test.cpp)
30+
foreach(src ${APP_SOURCES})
31+
get_filename_component(exe ${src} NAME_WLE)
32+
string(REPLACE "-test" "" unit ${exe})
33+
34+
add_executable(${exe} ${src})
35+
target_compile_options(${exe} PUBLIC ${GTEST_CFLAGS})
36+
target_link_libraries(${exe} ${GTEST_LDFLAGS} -lgtest_main)
37+
add_test(NAME ${unit} COMMAND ${exe})
38+
39+
if(CMAKE_COMPILER_IS_GNUCXX)
40+
string(REPLACE "-test" "-cov" cov ${exe})
41+
setup_target_for_coverage_gcovr_html(NAME ${cov} EXECUTABLE ${exe})
42+
add_dependencies(cov ${cov})
43+
endif()
44+
endforeach(src ${APP_SOURCES})

0 commit comments

Comments
 (0)