-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
112 lines (88 loc) · 4.4 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
cmake_minimum_required (VERSION 3.14)
project (httpp)
set (httpp_VERSION_MAJOR 0)
set (httpp_VERSION_MINOR 1)
enable_language(CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Werror -fexceptions -Wfatal-errors")
find_package (Threads)
# For use by YouCompleteMe
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# configure a header file to pass some of the CMake settings
# to the source code
configure_file (
"${PROJECT_SOURCE_DIR}/httppConfig.h.in"
"${PROJECT_BINARY_DIR}/httppConfig.h"
)
include_directories(AFTER "cpp/src")
# Whenever this glob's value changes, cmake will rerun and update the build with
# the new/removed files.
file(GLOB_RECURSE sources CONFIGURE_DEPENDS "cpp/src/**.cpp")
# add the libraries
add_library("${CMAKE_PROJECT_NAME}_STATIC" ${sources} ${includes})
set_target_properties("${CMAKE_PROJECT_NAME}_STATIC" PROPERTIES OUTPUT_NAME ${CMAKE_PROJECT_NAME})
target_link_libraries("${CMAKE_PROJECT_NAME}_STATIC" ${CMAKE_THREAD_LIBS_INIT})
add_library("${CMAKE_PROJECT_NAME}_SHARED" SHARED ${sources} ${includes})
set_target_properties("${CMAKE_PROJECT_NAME}_SHARED" PROPERTIES OUTPUT_NAME ${CMAKE_PROJECT_NAME})
target_link_libraries("${CMAKE_PROJECT_NAME}_SHARED" ${CMAKE_THREAD_LIBS_INIT})
################################
# Examples
################################
# echo server
file(GLOB_RECURSE example_echo CONFIGURE_DEPENDS "cpp/examples/httpp/*.cpp")
add_executable("${CMAKE_PROJECT_NAME}_EXAMPLE_ECHO" EXCLUDE_FROM_ALL ${example_echo} ${includes})
set_target_properties("${CMAKE_PROJECT_NAME}_EXAMPLE_ECHO" PROPERTIES OUTPUT_NAME "${CMAKE_PROJECT_NAME}_echo")
target_link_libraries("${CMAKE_PROJECT_NAME}_EXAMPLE_ECHO" "${CMAKE_PROJECT_NAME}_STATIC")
add_custom_target(example_echo DEPENDS ${CMAKE_PROJECT_NAME}_EXAMPLE_ECHO)
target_compile_options("${CMAKE_PROJECT_NAME}_EXAMPLE_ECHO" PRIVATE -Og -ggdb3)
target_link_options("${CMAKE_PROJECT_NAME}_EXAMPLE_ECHO" PRIVATE -ggdb3)
# index.html server
file(GLOB_RECURSE example_server CONFIGURE_DEPENDS "cpp/examples/server/*.cpp")
add_executable("${CMAKE_PROJECT_NAME}_EXAMPLE_SERVER" EXCLUDE_FROM_ALL ${example_server} ${includes})
set_target_properties("${CMAKE_PROJECT_NAME}_EXAMPLE_SERVER" PROPERTIES OUTPUT_NAME "${CMAKE_PROJECT_NAME}_server")
target_link_libraries("${CMAKE_PROJECT_NAME}_EXAMPLE_SERVER" "${CMAKE_PROJECT_NAME}_STATIC")
add_custom_target(example_server DEPENDS ${CMAKE_PROJECT_NAME}_EXAMPLE_SERVER)
target_compile_options("${CMAKE_PROJECT_NAME}_EXAMPLE_SERVER" PRIVATE -Og -ggdb3)
target_link_options("${CMAKE_PROJECT_NAME}_EXAMPLE_SERVER" PRIVATE -ggdb3)
add_custom_target(examples)
add_dependencies(examples example_echo example_server)
################################
# GTest
################################
option(BUILD_GMOCK "Builds Google Mock" OFF)
add_subdirectory (googletest EXCLUDE_FROM_ALL)
mark_as_advanced(BUILD_GMOCK)
# Unit Tests
file(GLOB_RECURSE tests CONFIGURE_DEPENDS "cpp/test/*.cpp")
add_executable(unit EXCLUDE_FROM_ALL ${tests} ${sources} ${includes})
# Link test executable against gtest & gtest_main
target_link_libraries(unit gtest)
# generate code coverage data
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# using llvm
set(GCOV_BIN "llvm-cov gcov")
else ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# using GCC
set(GCOV_BIN "gcov")
endif()
target_compile_options(unit PRIVATE -Og -ggdb3 -fprofile-arcs -ftest-coverage -fstandalone-debug
-DTESTING -DPROJECT_ROOT="${PROJECT_SOURCE_DIR}")
target_link_options(unit PRIVATE -ggdb3 -fprofile-arcs -ftest-coverage -fstandalone-debug)
add_custom_target(test-unit
COMMAND find ${PROJECT_BINARY_DIR} -name '*.gcda'
-exec rm {} +
COMMAND unit
COMMAND gcovr -r ${PROJECT_SOURCE_DIR} -sp
--gcov-executable "${GCOV_BIN}"
--exclude-directories 'googletest|build'
--filter ${PROJECT_SOURCE_DIR}/cpp/src
--exclude '\.\./.*/test_.*|\.\./.*_prod\..*'
DEPENDS unit)
add_custom_target(test-debug
COMMAND find ${PROJECT_BINARY_DIR} -name '*.gcda'
-exec rm {} +
COMMAND lldb "${PROJECT_BINARY_DIR}/unit"
DEPENDS unit)
add_custom_target(test DEPENDS test-unit)