-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
89 lines (70 loc) · 2.96 KB
/
CMakeLists.txt
File metadata and controls
89 lines (70 loc) · 2.96 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
cmake_minimum_required(VERSION 3.1)
cmake_policy(SET CMP0091 NEW)
message(STATUS "Read contents from vcpkg.json")
file(READ "${CMAKE_SOURCE_DIR}/vcpkg.json" VCPKG_JSON_CONTENT)
message(STATUS "Extract version from vcpkg.json")
string(REGEX MATCH "\"version-string\"[ \t]*:[ \t]*\"([^\"]+)\"" VERSION_MATCH "${VCPKG_JSON_CONTENT}")
if (VERSION_MATCH)
string(REGEX REPLACE "\"version-string\"[ \t]*:[ \t]*\"([^\"]+)\"" "\\1" WEBTHING_CPP_VERSION "${VERSION_MATCH}")
message(STATUS "Extracted version from vcpkg.json: ${WEBTHING_CPP_VERSION}")
else()
message(FATAL_ERROR "Could not extract version from vcpkg.json")
endif()
message(STATUS "Generate version.hpp using version: ${WEBTHING_CPP_VERSION}")
configure_file(
"${CMAKE_SOURCE_DIR}/tools/templates/version.hpp.in"
"${CMAKE_SOURCE_DIR}/include/bw/webthing/version.hpp"
)
project(Webthing-CPP VERSION ${WEBTHING_CPP_VERSION} DESCRIPTION "Webthing-CPP a modern CPP implementation of the WebThings API." LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
if(WIN32)
add_definitions(-DNOMINMAX)
endif(WIN32)
option(WT_UNORDERED_JSON_OBJECT_LAYOUT "Enable unordered json object layout." OFF)
if(WT_UNORDERED_JSON_OBJECT_LAYOUT)
add_definitions(-DWT_UNORDERED_JSON_OBJECT_LAYOUT)
endif(WT_UNORDERED_JSON_OBJECT_LAYOUT)
message("WT_UNORDERED_JSON_OBJECT_LAYOUT: ${WT_UNORDERED_JSON_OBJECT_LAYOUT}")
option(WT_USE_JSON_SCHEMA_VALIDATION "Enable json schema validation of properties and actions." ON)
if(WT_USE_JSON_SCHEMA_VALIDATION)
add_definitions(-DWT_USE_JSON_SCHEMA_VALIDATION)
endif(WT_USE_JSON_SCHEMA_VALIDATION)
message("WT_USE_JSON_SCHEMA_VALIDATION: ${WT_USE_JSON_SCHEMA_VALIDATION}")
option(WT_WITH_SSL "Enable SSL support." ON)
if(WT_WITH_SSL)
add_definitions(-DWT_WITH_SSL)
endif(WT_WITH_SSL)
message("WT_WITH_SSL: ${WT_WITH_SSL}")
set(VCPKG_BUILD_TYPE ${CMAKE_BUILD_TYPE})
message("CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message("VCPKG_BUILD_TYPE: ${VCPKG_BUILD_TYPE}")
find_package(unofficial-uwebsockets CONFIG REQUIRED)
find_path(MDNS_INCLUDE_DIRS "mdns.h")
message("mdns include dir: ${MDNS_INCLUDE_DIRS}")
find_package(mdns REQUIRED)
find_package(nlohmann_json 3.11.2 REQUIRED)
find_package(nlohmann_json_schema_validator REQUIRED)
if(WT_WITH_SSL)
find_package(OpenSSL REQUIRED)
endif(WT_WITH_SSL)
option(WT_BUILD_EXAMPLES "build examples" ON)
message("WT_BUILD_EXAMPLES: ${WT_BUILD_EXAMPLES}")
if(WT_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
option(WT_BUILD_TESTS "build tests" ON)
message("WT_BUILD_TESTS: ${WT_BUILD_TESTS}")
if(WT_BUILD_TESTS)
add_subdirectory(test)
endif()
add_library(webthing-cpp INTERFACE)
target_link_libraries(webthing-cpp INTERFACE
nlohmann_json_schema_validator::validator
nlohmann_json::nlohmann_json
unofficial::uwebsockets::uwebsockets
)
target_include_directories(webthing-cpp INTERFACE
$<BUILD_INTERFACE:"${CMAKE_CURRENT_SOURCE_DIR}/include}">
$<INSTALL_INTERFACE:include>
)
install(DIRECTORY include/ DESTINATION "${CMAKE_INSTALL_PREFIX}/include")