forked from etr/libhttpserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
77 lines (61 loc) · 2.3 KB
/
CMakeLists.txt
File metadata and controls
77 lines (61 loc) · 2.3 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
cmake_minimum_required(VERSION 3.10)
project(libhttpserver VERSION 0.19.0 LANGUAGES CXX)
# C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Options
option(ENABLE_DEBUG "Enable debug mode" OFF)
option(ENABLE_COVERAGE "Enable coverage reporting" ON)
option(ENABLE_EXAMPLES "Build examples" OFF)
option(ENABLE_FASTOPEN "Enable TCP_FASTOPEN support" ON)
option(ENABLE_STATIC "Enable static linking" ON)
option(WITH_TLS "Enable TLS support" ON)
option(ENABLE_TESTS "Build tests" ON) # Add option to control whether to build tests
# Compiler flags
if(ENABLE_DEBUG)
add_definitions(-DDEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -Werror -pedantic")
else()
add_definitions(-DNDEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif()
if(ENABLE_COVERAGE AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
endif()
# External libraries
find_package(Threads REQUIRED)
# Find libmicrohttpd
find_path(LIBMICROHTTPD_INCLUDE_DIR NAMES microhttpd.h)
find_library(LIBMICROHTTPD_LIBRARY NAMES microhttpd)
if(NOT LIBMICROHTTPD_INCLUDE_DIR OR NOT LIBMICROHTTPD_LIBRARY)
message(FATAL_ERROR "libmicrohttpd >= 0.9.64 not found")
endif()
# Include directories for src and headers
include_directories(${LIBMICROHTTPD_INCLUDE_DIR})
# Collect source files
file(GLOB_RECURSE LIBHTTPSERVER_SOURCES
${PROJECT_SOURCE_DIR}/src/*.cpp
)
# Create the libhttpserver library
add_library(libhttpserver SHARED ${LIBHTTPSERVER_SOURCES})
target_compile_definitions(libhttpserver PRIVATE HTTPSERVER_COMPILATION)
# Link libraries
target_link_libraries(libhttpserver PRIVATE ${LIBMICROHTTPD_LIBRARY} Threads::Threads)
# Install the library and headers
install(TARGETS libhttpserver DESTINATION lib)
install(FILES ${CMAKE_SOURCE_DIR}/src/httpserver.h DESTINATION include)
# Examples
if(ENABLE_EXAMPLES)
file(GLOB EXAMPLES_SOURCES ${PROJECT_SOURCE_DIR}/examples/*.cpp)
foreach(EXAMPLE_FILE ${EXAMPLES_SOURCES})
get_filename_component(EXAMPLE_NAME ${EXAMPLE_FILE} NAME_WE)
add_executable(${EXAMPLE_NAME} ${EXAMPLE_FILE})
target_link_libraries(${EXAMPLE_NAME} libhttpserver)
install(TARGETS ${EXAMPLE_NAME} DESTINATION bin)
endforeach()
endif()
# Tests
if(ENABLE_TESTS)
enable_testing()
add_subdirectory(test)
endif()