-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
CMakeLists.txt
49 lines (40 loc) · 2.14 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
cmake_minimum_required(VERSION 3.12)
set(CMAKE_CXX_STANDARD 17)
project(json-rpc-cxx VERSION 0.0.1 LANGUAGES CXX)
option(COMPILE_TESTS "Enable tests" ON)
option(COMPILE_EXAMPLES "Enable examples" ON)
option(CODE_COVERAGE "Enable coverage reporting" OFF)
include(GNUInstallDirs)
add_library(json-rpc-cxx INTERFACE)
target_include_directories(json-rpc-cxx INTERFACE include)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
add_library(coverage_config INTERFACE)
# Warning options for the compiler
string(
APPEND _warning_opts
"$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:-Wall;-Wextra;-Weffc++;-Werror;>"
"$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-Wthread-safety;-Wpedantic;>"
"$<$<CXX_COMPILER_ID:GNU>:-pedantic;-pedantic-errors;>"
)
if (COMPILE_TESTS)
if (CODE_COVERAGE)
message("Enabled coverage flags")
target_compile_options(coverage_config INTERFACE -O0 -g --coverage)
target_link_libraries(coverage_config INTERFACE --coverage)
endif ()
add_executable(jsonrpccpp-test test/main.cpp test/client.cpp test/typemapper.cpp test/dispatcher.cpp test/server.cpp test/batchclient.cpp test/testclientconnector.hpp examples/warehouse/warehouseapp.cpp test/warehouseapp.cpp test/common.cpp)
target_compile_options(jsonrpccpp-test PUBLIC "${_warning_opts}")
target_include_directories(jsonrpccpp-test PRIVATE vendor examples)
target_link_libraries(jsonrpccpp-test coverage_config json-rpc-cxx)
enable_testing()
add_test(NAME test COMMAND jsonrpccpp-test)
endif ()
if (COMPILE_EXAMPLES)
find_package(Threads)
add_executable(example-warehouse examples/warehouse/main.cpp examples/warehouse/warehouseapp.cpp examples/warehouse/types.h examples/inmemoryconnector.hpp)
target_compile_options(example-warehouse PUBLIC "${_warning_opts}")
target_link_libraries(example-warehouse json-rpc-cxx Threads::Threads)
target_include_directories(example-warehouse SYSTEM PRIVATE vendor)
target_include_directories(example-warehouse PRIVATE examples)
add_test(NAME example COMMAND example-warehouse)
endif ()