Skip to content

Commit 4e4674e

Browse files
committed
Add project boilerplate (code coverage don't work with clang)
1 parent 071f896 commit 4e4674e

File tree

13 files changed

+493
-0
lines changed

13 files changed

+493
-0
lines changed

.gitignore

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
*.dll
18+
19+
# Fortran module files
20+
*.mod
21+
*.smod
22+
23+
# Compiled Static libraries
24+
*.lai
25+
*.la
26+
*.a
27+
*.lib
28+
29+
# Executables
30+
*.exe
31+
*.out
32+
*.app
33+
34+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
35+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
36+
37+
.idea/
38+
39+
# CMake
40+
cmake-build-debug/
41+
cmake-build-release/
42+
43+
## File-based project format:
44+
*.iws
45+
46+
## Plugin-specific files:
47+
48+
# IntelliJ
49+
out/
50+
51+
# mpeltonen/sbt-idea plugin
52+
.idea_modules/
53+
54+
# JIRA plugin
55+
atlassian-ide-plugin.xml
56+
57+
# Cursive Clojure plugin
58+
.idea/replstate.xml
59+
60+
# Crashlytics plugin (for Android Studio and IntelliJ)
61+
com_crashlytics_export_strings.xml
62+
crashlytics.properties
63+
crashlytics-build.properties
64+
fabric.properties

CMakeLists.txt

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
cmake_minimum_required(VERSION 3.8.2)
2+
project(CPP-Stream)
3+
4+
set(CMAKE_CXX_STANDARD 17)
5+
6+
include_directories(include)
7+
8+
find_package(Threads)
9+
10+
if (CMAKE_VERSION VERSION_LESS 3.2)
11+
set(UPDATE_DISCONNECTED_IF_AVAILABLE "")
12+
else()
13+
set(UPDATE_DISCONNECTED_IF_AVAILABLE "UPDATE_DISCONNECTED 1")
14+
endif()
15+
include(third-party/DownloadProject/DownloadProject.cmake)
16+
17+
# =============================== CMAKE MODULES =========================================
18+
download_project(PROJ cmake-modules
19+
GIT_REPOSITORY https://github.com/NikitkoCent/cmake-modules
20+
GIT_TAG changes
21+
${UPDATE_DISCONNECTED_IF_AVAILABLE}
22+
)
23+
# =============================== END CMAKE MODULES =====================================
24+
25+
# ================================ SETUP WARNINGS =======================================
26+
include(${cmake-modules_SOURCE_DIR}/EnableExtraCompilerWarnings.cmake)
27+
globally_enable_extra_compiler_warnings()
28+
# ============================== END SETUP WARNINGS =====================================
29+
30+
# ================================== GOOGLETEST =========================================
31+
enable_testing()
32+
33+
download_project(PROJ googletest
34+
GIT_REPOSITORY https://github.com/google/googletest.git
35+
GIT_TAG master
36+
${UPDATE_DISCONNECTED_IF_AVAILABLE}
37+
)
38+
39+
# Prevent GoogleTest from overriding our compiler/linker options
40+
# when building with Visual Studio
41+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
42+
43+
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
44+
45+
# When using CMake 2.8.11 or later, header path dependencies
46+
# are automatically added to the gtest and gmock targets.
47+
# For earlier CMake versions, we have to explicitly add the
48+
# required directories to the header search path ourselves.
49+
if (CMAKE_VERSION VERSION_LESS 2.8.11)
50+
include_directories("${gtest_SOURCE_DIR}/include"
51+
"${gmock_SOURCE_DIR}/include")
52+
endif()
53+
# ================================ GOOGLETEST END =======================================
54+
55+
add_executable(unittesting tests/empty.cpp)
56+
target_link_libraries(unittesting gtest gmock_main Threads::Threads)
57+
58+
add_test(NAME do_unittests COMMAND unittesting)
59+
60+
# ================================= TEST COVERAGE =======================================
61+
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
62+
include(${cmake-modules_SOURCE_DIR}/CodeCoverage.cmake)
63+
64+
if (CMAKE_CXX_FLAGS_COVERAGE)
65+
APPEND_COVERAGE_COMPILER_FLAGS()
66+
SETUP_TARGET_FOR_COVERAGE(NAME collect_coverage
67+
EXECUTABLE ctest
68+
DEPENDENCIES unittesting)
69+
endif()
70+
endif()
71+
# =============================== END TEST COVERAGE ====================================
72+
73+
MESSAGE("Build type : ${CMAKE_BUILD_TYPE}")
74+
MESSAGE("Used compiler : ${CMAKE_CXX_COMPILER}")
75+
if (CMAKE_BUILD_TYPE EQUAL "Debug")
76+
MESSAGE("Compiler flags : ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")
77+
elseif (CMAKE_BUILD_TYPE EQUAL "Release")
78+
MESSAGE("Compiler flags : ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}")
79+
elseif (CMAKE_BUILD_TYPE EQUAL "RelWithDebInfo")
80+
MESSAGE("Compiler flags : ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
81+
elseif (CMAKE_BUILD_TYPE EQUAL "MinSizeRel")
82+
MESSAGE("Compiler flags : ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_MINSIZEREL}")
83+
else()
84+
MESSAGE("Compiler flags : ${CMAKE_CXX_FLAGS}")
85+
endif()

Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
all: invoke_tests
2+
3+
invoke_tests: invoke_make
4+
cd build && ./unittesting
5+
6+
invoke_make: invoke_cmake
7+
$(MAKE) -C build/
8+
9+
invoke_cmake: CMakeLists.txt
10+
cd build && cmake ${CMAKE_ARGS} ../
11+
12+
collect_coverage: invoke_make
13+
$(MAKE) -C build/ collect_coverage
14+
15+
clean:
16+
rm -rf build/*

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,20 @@
11
# CPP-Stream
22
C++ imitation of Java 8 Stream API
3+
4+
## Setting up
5+
### Unix:
6+
Variable CMAKE_ARGS is for passing arguments to cmake invocation
7+
8+
* Simple run : `make`
9+
* Make **DEBUG** build and run tests: `make CMAKE_ARGS="-DCMAKE_BUILD_TYPE=Debug"`
10+
* Make **RELEASE** build and run tests: `make CMAKE_ARGS="-DCMAKE_BUILD_TYPE=Release"`
11+
* Testing coverage (**DEBUG** build only): `make CMAKE_ARGS="-DCMAKE_BUILD_TYPE=Debug" collect_coverage`
12+
13+
### Windows:
14+
Use [cmake](https://cmake.org/download/) for generating MSVS solution / smth else : `cd build && cmake.exe ../`
15+
16+
### Testing coverage (Unix only)
17+
Testing coverage has the next dependencies:
18+
* [gcov](https://gcc.gnu.org/onlinedocs/gcc/Gcov.html)
19+
* [lcov](https://wiki.documentfoundation.org/Development/Lcov) (install using apt : `apt-get install lcov`)
20+
* [genhtml](https://linux.die.net/man/1/genhtml)

build/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

tests/empty.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include <gtest/gtest.h>
2+
#include <gmock/gmock.h>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
CMakeLists.txt.user
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Need these for a more recent CMake on Linux
2+
sudo: required
3+
dist: trusty
4+
5+
os:
6+
- linux
7+
- osx
8+
9+
language: cpp
10+
11+
before_script:
12+
- mkdir build
13+
- cd build
14+
- cmake ..
15+
16+
script:
17+
- cmake --build .
18+
19+
after_script:
20+
- cmake --build . --target test
21+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
cmake_minimum_required(VERSION 2.8.2)
2+
3+
project(DP_Example)
4+
5+
include(CTest)
6+
7+
if (CMAKE_VERSION VERSION_LESS 3.2)
8+
set(UPDATE_DISCONNECTED_IF_AVAILABLE "")
9+
else()
10+
set(UPDATE_DISCONNECTED_IF_AVAILABLE "UPDATE_DISCONNECTED 1")
11+
endif()
12+
13+
include(DownloadProject.cmake)
14+
download_project(PROJ googletest
15+
GIT_REPOSITORY https://github.com/google/googletest.git
16+
GIT_TAG master
17+
${UPDATE_DISCONNECTED_IF_AVAILABLE}
18+
)
19+
20+
# Prevent GoogleTest from overriding our compiler/linker options
21+
# when building with Visual Studio
22+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
23+
24+
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
25+
26+
# When using CMake 2.8.11 or later, header path dependencies
27+
# are automatically added to the gtest and gmock targets.
28+
# For earlier CMake versions, we have to explicitly add the
29+
# required directories to the header search path ourselves.
30+
if (CMAKE_VERSION VERSION_LESS 2.8.11)
31+
include_directories("${gtest_SOURCE_DIR}/include"
32+
"${gmock_SOURCE_DIR}/include")
33+
endif()
34+
35+
# Trivial example using gtest and gmock
36+
add_executable(example example.cpp)
37+
target_link_libraries(example gtest gmock_main)
38+
add_test(NAME example_test COMMAND example)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Distributed under the OSI-approved MIT License. See accompanying
2+
# file LICENSE or https://github.com/Crascit/DownloadProject for details.
3+
4+
cmake_minimum_required(VERSION 2.8.2)
5+
6+
project(${DL_ARGS_PROJ}-download NONE)
7+
8+
include(ExternalProject)
9+
ExternalProject_Add(${DL_ARGS_PROJ}-download
10+
${DL_ARGS_UNPARSED_ARGUMENTS}
11+
SOURCE_DIR "${DL_ARGS_SOURCE_DIR}"
12+
BINARY_DIR "${DL_ARGS_BINARY_DIR}"
13+
CONFIGURE_COMMAND ""
14+
BUILD_COMMAND ""
15+
INSTALL_COMMAND ""
16+
TEST_COMMAND ""
17+
)

0 commit comments

Comments
 (0)