-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
84 lines (66 loc) · 2.74 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
cmake_minimum_required(VERSION 3.1)
project(coap_server
VERSION 0.1
LANGUAGES CXX)
set(EXECUTABLE_NAME "coap_server")
# C++17 is required
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Enable warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -O2")
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
message(STATUS "Setting Clang-specific compiler flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-Weverything \
-Wno-unknown-warning-option \
-Wno-c++98-compat \
-Wno-reserved-identifier \
-Wno-reserved-macro-identifier \
-Wno-padded")
endif()
# Options
option(DEBUG "Enable debugging symbols" OFF)
# Required libraries
find_library(COAP_LIBRARY
NAMES coap-3-gnutls coap-3-openssl coap-3-tinydtls coap-3-mbedtls coap-3)
find_package(Boost 1.65.0 COMPONENTS program_options)
# Library checks
if(COAP_LIBRARY)
message(STATUS "Compiling with the following CoAP library: ${COAP_LIBRARY}")
else()
message(FATAL_ERROR "Could not find a compatible CoAP library!")
endif()
if(!BOOST_FOUND)
message(FATAL_ERROR "Could not find the required Boost libraries!")
endif()
if(DEBUG)
message(STATUS "Enabling debug symbols")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
endif()
# Enable pthread support
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
# Resource Formatters
add_library(ResourceFormatters
${CMAKE_CURRENT_LIST_DIR}/src/ResourceFormatter/ResourceFormatterHex.cpp
${CMAKE_CURRENT_LIST_DIR}/src/ResourceFormatter/ResourceFormatterText.cpp
${CMAKE_CURRENT_LIST_DIR}/src/ResourceFormatter/ResourceFormatterBase64.cpp)
configure_file(${CMAKE_CURRENT_LIST_DIR}/inc/config.h.in
${CMAKE_CURRENT_BINARY_DIR}/inc/config.h)
add_executable(${EXECUTABLE_NAME})
target_sources(${EXECUTABLE_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src/main.cpp
${CMAKE_CURRENT_LIST_DIR}/src/Config.cpp
${CMAKE_CURRENT_LIST_DIR}/src/CoAPServer.cpp
${CMAKE_CURRENT_LIST_DIR}/src/Resource.cpp
${CMAKE_CURRENT_LIST_DIR}/src/ResourceMethod.cpp
${CMAKE_CURRENT_LIST_DIR}/src/ResourceFormatter.cpp
${CMAKE_CURRENT_LIST_DIR}/src/RequestQueue.cpp)
include_directories(${EXECUTABLE_NAME}
${CMAKE_CURRENT_LIST_DIR}/inc/
${CMAKE_CURRENT_BINARY_DIR}/inc/
${Boost_INCLUDE_DIRS})
target_link_libraries(${EXECUTABLE_NAME}
ResourceFormatters
${COAP_LIBRARY}
${Boost_LIBRARIES}
stdc++fs)