-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
65 lines (52 loc) · 1.89 KB
/
CMakeLists.txt
File metadata and controls
65 lines (52 loc) · 1.89 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
cmake_minimum_required(VERSION 3.16)
project(MultithreadedWebServer VERSION 1.0.0 LANGUAGES CXX)
# Set C++17 standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Build type options
option(ENABLE_ASAN "Enable AddressSanitizer for debugging" OFF)
option(ENABLE_TSAN "Enable ThreadSanitizer for debugging" OFF)
option(DEBUG_BUILD "Enable debug build with symbols" OFF)
# Compiler-specific options
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(DEBUG_BUILD)
add_compile_options(-Wall -Wextra -Wpedantic -g -O1 -fno-omit-frame-pointer)
else()
add_compile_options(-Wall -Wextra -Wpedantic -O3 -march=native)
endif()
if(ENABLE_ASAN)
add_compile_options(-fsanitize=address -fsanitize=undefined)
add_link_options(-fsanitize=address -fsanitize=undefined)
set(CMAKE_BUILD_TYPE Debug)
endif()
if(ENABLE_TSAN)
add_compile_options(-fsanitize=thread)
add_link_options(-fsanitize=thread)
set(CMAKE_BUILD_TYPE Debug)
endif()
endif()
# Include directories
include_directories(include)
# Source files
file(GLOB_RECURSE SOURCES "src/*.cpp")
# Create executable
add_executable(webserver ${SOURCES})
# Link pthread library
find_package(Threads REQUIRED)
target_link_libraries(webserver Threads::Threads)
# Optional: Add GoogleTest for unit testing
option(BUILD_TESTS "Build unit tests" OFF)
if(BUILD_TESTS)
find_package(GTest REQUIRED)
enable_testing()
file(GLOB_RECURSE TEST_SOURCES "tests/*.cpp")
add_executable(webserver_tests ${TEST_SOURCES} ${SOURCES})
target_link_libraries(webserver_tests GTest::gtest_main Threads::Threads)
include(GoogleTest)
gtest_discover_tests(webserver_tests)
endif()
# Set output directory
set_target_properties(webserver PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)