-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
139 lines (123 loc) · 5.07 KB
/
CMakeLists.txt
File metadata and controls
139 lines (123 loc) · 5.07 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
cmake_minimum_required(VERSION 3.0)
project(scriptor)
cmake_policy(SET CMP0054 NEW)
option(scriptor_build_tests "Build scriptor tests." OFF)
option(scriptor_enable_asan "Build scriptor with address sanitizer." OFF)
option(scriptor_enable_tsan "Build scriptor with thread sanitizer." OFF)
option(scriptor_enable_coverage "Build scriptor with coverage reporting." OFF)
if(scriptor_enable_asan AND scriptor_enable_tsan)
message(FATAL_ERROR "scriptor_enable_asan and scriptor_enable_tsan cannot both be ON")
endif()
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
function(scriptor_add_flags target)
set_property(TARGET ${target} PROPERTY CXX_STANDARD 17)
set_property(TARGET ${target} PROPERTY CXX_EXTENSIONS OFF)
target_compile_definitions(${target} PRIVATE SPDLOG_FMT_EXTERNAL SPDLOG_NO_THREAD_ID)
if(MSVC)
target_compile_definitions(${target} PRIVATE SCRIPTOR_WINDOWS _CRT_SECURE_NO_WARNINGS)
target_compile_options(${target} PRIVATE /W4 /WX /bigobj /EHsc /wd4503 /wd4996 /wd4702 /wd4100 /wd4706)
if(${MSVC_VERSION} GREATER_EQUAL 1929)
if(scriptor_enable_asan)
target_compile_options(${target} PRIVATE /fsanitize=address)
endif()
endif()
else()
if(APPLE)
target_compile_definitions(${target} PRIVATE SCRIPTOR_APPLE)
else()
target_compile_definitions(${target} PRIVATE SCRIPTOR_LINUX)
endif()
target_compile_options(${target} PRIVATE -Wall -Wconversion -Wextra -Wpedantic -Werror)
target_link_libraries(${target} ${CMAKE_THREAD_LIBS_INIT})
if(CMAKE_COMPILER_IS_GNUCC)
target_compile_options(${target} PRIVATE -pthread)
endif()
if(scriptor_enable_asan)
if(APPLE)
target_compile_options(${target} PRIVATE -fsanitize=address,undefined)
set_target_properties(${target} PROPERTIES LINK_FLAGS "-fsanitize=address,undefined")
else()
target_compile_options(${target} PRIVATE -fsanitize=address,leak,undefined)
set_target_properties(${target} PROPERTIES LINK_FLAGS "-fsanitize=address,leak,undefined")
endif()
endif()
if(scriptor_enable_tsan)
target_compile_options(${target} PRIVATE -fsanitize=thread)
set_target_properties(${target} PROPERTIES LINK_FLAGS "-fsanitize=thread")
endif()
if(scriptor_enable_coverage)
target_compile_options(${target} PRIVATE --coverage)
set_target_properties(${target} PROPERTIES LINK_FLAGS "--coverage")
endif()
if(APPLE)
target_compile_options(${target} PRIVATE -Wno-unused-lambda-capture)
endif()
endif()
endfunction()
find_package(Threads)
include(conan.cmake)
conan_cmake_autodetect(settings)
conan_cmake_install(PATH_OR_REFERENCE ${PROJECT_SOURCE_DIR}
BUILD missing
REMOTE conancenter
SETTINGS ${settings}
OUTPUT_FOLDER ${CMAKE_BINARY_DIR})
find_package(asio REQUIRED)
find_package(GTest REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(spdlog REQUIRED)
set(scriptor_core_source_files
${PROJECT_SOURCE_DIR}/src/aio.h
${PROJECT_SOURCE_DIR}/src/acceptor.h
${PROJECT_SOURCE_DIR}/src/acceptor.cpp
${PROJECT_SOURCE_DIR}/src/element.h
${PROJECT_SOURCE_DIR}/src/element.cpp
${PROJECT_SOURCE_DIR}/src/logger.h
${PROJECT_SOURCE_DIR}/src/logger.cpp
${PROJECT_SOURCE_DIR}/src/scriptor.h
${PROJECT_SOURCE_DIR}/src/scriptor.cpp
${PROJECT_SOURCE_DIR}/src/server.h
${PROJECT_SOURCE_DIR}/src/server.cpp
${PROJECT_SOURCE_DIR}/src/session.h
${PROJECT_SOURCE_DIR}/src/session.cpp
${PROJECT_SOURCE_DIR}/src/socket.h
${PROJECT_SOURCE_DIR}/src/socket.cpp
)
add_library(scriptor_core ${scriptor_core_source_files})
scriptor_add_flags(scriptor_core)
target_link_libraries(scriptor_core asio::asio nlohmann_json::nlohmann_json spdlog::spdlog)
if(UNIX AND NOT APPLE)
target_link_libraries(scriptor_core systemd)
endif()
add_executable(scriptor src/main.cpp)
scriptor_add_flags(scriptor)
target_link_libraries(scriptor scriptor_core)
install(TARGETS scriptor RUNTIME DESTINATION bin)
set(scriptor_test_source_files
${PROJECT_SOURCE_DIR}/test/helper.h
${PROJECT_SOURCE_DIR}/test/helper.cpp
${PROJECT_SOURCE_DIR}/test/main.cpp
${PROJECT_SOURCE_DIR}/test/test_element.cpp
${PROJECT_SOURCE_DIR}/test/test_logger.cpp
${PROJECT_SOURCE_DIR}/test/test_processor.cpp
${PROJECT_SOURCE_DIR}/test/test_scriptor.cpp
)
if(scriptor_build_tests)
enable_testing()
add_executable(scriptor_test ${scriptor_test_source_files})
scriptor_add_flags(scriptor_test)
target_link_libraries(scriptor_test scriptor_core GTest::GTest)
add_test(scriptor_test scriptor_test)
endif()
set(scriptor_source_files
${PROJECT_SOURCE_DIR}/src/scriptor.cpp
${scriptor_core_source_files}
${scriptor_test_source_files})
add_custom_target(
scriptor_format
COMMAND clang-format
-style=file
-i
${scriptor_source_files}
)