-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
110 lines (83 loc) · 3.71 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
cmake_minimum_required(VERSION 3.10) # Example minimum version
set(CMAKE_CXX_STANDARD 17)
project(SocketClusterClientCPP)
include(FetchContent)
# === JsonCPP ===
FetchContent_Declare(JsonCpp
GIT_REPOSITORY https://github.com/open-source-parsers/jsoncpp.git
GIT_TAG 1.9.5 # Or your desired version
)
FetchContent_MakeAvailable(JsonCpp)
# === ===
# set(BOOST_INCLUDE_LIBRARIES thread filesystem system program_options)
# set(BOOST_ENABLE_CMAKE ON)
# include(FetchContent)
# FetchContent_Declare(
# Boost
# GIT_REPOSITORY https://github.com/boostorg/boost.git
# GIT_TAG boost-1.74.0
# GIT_SHALLOW TRUE
# )
# FetchContent_MakeAvailable(Boost)
find_package(Boost 1.74.0 REQUIRED)
# Find source files
file(GLOB_RECURSE LIBRARY_SOURCES src/*.cpp)
add_library(SocketClusterClientCPP SHARED ${LIBRARY_SOURCES})
target_link_libraries(SocketClusterClientCPP PUBLIC jsoncpp_lib)
# Update include directories to find json-c headers
target_include_directories(SocketClusterClientCPP PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${jsoncpp_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${websocketpp_SOURCE_DIR}/include>
)
target_include_directories(SocketClusterClientCPP PUBLIC "${Boost_INCLUDE_DIRS}")
# Install targets and headers
install(TARGETS SocketClusterClientCPP
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
install(DIRECTORY src/
DESTINATION include)
add_executable(simple_example test/examples/client_classed.cpp)
target_link_libraries(simple_example PUBLIC SocketClusterClientCPP)
# Coverage
option(BUILD_TESTING "Builds only the test executable." OFF)
option(CODE_COVERAGE "Collect coverage from test library" OFF)
if(BUILD_TESTING)
enable_testing()
add_subdirectory(test)
add_test(NAME project_tests COMMAND ./bin/tests)
if(CODE_COVERAGE AND CMAKE_BUILD_TYPE MATCHES Debug)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage -O0")
set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -O0")
# Set the coverage report output directory
set(COVERAGE_DIR ${CMAKE_BINARY_DIR}/coverage)
# Clean the coverage directory
add_custom_target(coverage_clean
COMMAND ${CMAKE_COMMAND} -E rm -rf ${COVERAGE_DIR}
)
# Add a target to run the tests and collect coverage information
add_custom_target(coverage
COMMAND ${CMAKE_COMMAND} -E make_directory ${COVERAGE_DIR}
COMMAND ${CMAKE_COMMAND} -E env LCOV_OPTS="--rc lcov_branch_coverage=1 geninfo_unexecuted_blocks=1" $<TARGET_FILE:tests>
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS tests coverage_clean
COMMENT "Running tests and collecting coverage data..."
)
# Add a target to generate the coverage report
# Add a target to generate the coverage report
# Add a target to generate the coverage report
add_custom_target(coverage_report
COMMAND lcov --capture --directory . --output-file ${COVERAGE_DIR}/coverage.info --ignore-errors source,unused
# Remove coverage data for external libraries, including Catch2
COMMAND lcov --remove ${COVERAGE_DIR}/coverage.info "/usr/*" "${CMAKE_BINARY_DIR}/_deps/*" --output-file ${COVERAGE_DIR}/filtered.info --ignore-errors source,unused
# Optional: Add more --remove lines as needed to exclude other directories or files
COMMAND lcov --list ${COVERAGE_DIR}/filtered.info
COMMAND genhtml -o ${COVERAGE_DIR}/html ${COVERAGE_DIR}/filtered.info
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS coverage
COMMENT "Generating coverage report..."
)
endif()
endif()