-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 586162c
Showing
39 changed files
with
5,852 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
build/ | ||
lib/ | ||
tools/vcpkg/ | ||
tools/webthing-tester/ | ||
.vscode/ | ||
todo.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
cmake_policy(SET CMP0091 NEW) | ||
project(Webthing-CPP VERSION 1.0 DESCRIPTION "Webthing implementation for C++" LANGUAGES CXX) | ||
set(CMAKE_CXX_STANDARD 17) | ||
|
||
IF(WIN32) | ||
ADD_DEFINITIONS(-DNOMINMAX) | ||
ENDIF(WIN32) | ||
|
||
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_path(UWEBSOCKETS_INCLUDE_DIRS "uwebsockets/App.h") | ||
message("µWebsockets include dir: ${UWEBSOCKETS_INCLUDE_DIRS}") | ||
IF (WIN32) | ||
find_library(LIBUSOCKETS_STATIC uSockets.lib) | ||
ELSE(WIN32) | ||
find_library(LIBUSOCKETS_STATIC libuSockets.a) | ||
ENDIF(WIN32) | ||
message(${LIBUSOCKETS_STATIC}) | ||
|
||
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) | ||
find_package(libuv REQUIRED NO_MODULE) | ||
find_package(ZLIB REQUIRED) | ||
|
||
IF(WT_WITH_SSL) | ||
find_package(OpenSSL REQUIRED) | ||
ENDIF(WT_WITH_SSL) | ||
|
||
add_subdirectory(examples) | ||
add_subdirectory(test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Webthing-CPP is licensed under the MIT License | ||
|
||
Copyright (c) 2023 Benno Waldhauer | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
@echo off | ||
|
||
set "script_path=%~f0" | ||
set "base_dir=%~dp0" | ||
set "build_dir=%base_dir%build" | ||
set "toolchain_file=%base_dir%tools\vcpkg\scripts\buildsystems\vcpkg.cmake" | ||
|
||
echo %* | find /i "clean" > nul | ||
if %errorlevel% equ 0 ( | ||
echo Cleaning project - removing %build_dir% | ||
rmdir /s /q %build_dir% | ||
) else ( | ||
echo Using cache for project build | ||
) | ||
|
||
echo %* | find /i "release" > nul | ||
if %errorlevel% equ 0 ( | ||
set "build_type=Release" | ||
) else ( | ||
set "build_type=Debug" | ||
) | ||
echo Project build type: %build_type% | ||
|
||
echo %* | find /i "Win32" > nul | ||
if %errorlevel% equ 0 ( | ||
set "build_arch=Win32" | ||
set "vcpkg_triplet=x86-windows-static" | ||
) else ( | ||
set "build_arch=x64" | ||
set "vcpkg_triplet=x64-windows-static" | ||
) | ||
echo Project architecture: %build_arch% | ||
|
||
|
||
echo %* | find /i "with_ssl" > nul | ||
if %errorlevel% equ 0 ( | ||
set "ssl_support=ON" | ||
set "vcpkg_file=vcpkg-with-ssl.json" | ||
) else ( | ||
set "ssl_support=OFF" | ||
set "vcpkg_file=vcpkg-no-ssl.json" | ||
) | ||
echo Project SSL support: %ssl_support% | ||
copy %vcpkg_file% vcpkg.json | ||
|
||
cmake -B "%build_dir%" -S . -DWT_WITH_SSL=%ssl_support% -DCMAKE_BUILD_TYPE=%build_type% -DCMAKE_TOOLCHAIN_FILE="%toolchain_file%" -DVCPKG_TARGET_TRIPLET="%vcpkg_triplet%" -G "Visual Studio 15 2017" -A "%build_arch%" | ||
cmake --build "%build_dir%" --config "%build_type%" | ||
|
||
ctest --test-dir "%build_dir%\test\" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env bash | ||
|
||
script_path=$(realpath "$0") | ||
base_dir="$( dirname "$script_path" )" | ||
build_dir="$base_dir/build" | ||
toolchain_file="$base_dir/tools/vcpkg/scripts/buildsystems/vcpkg.cmake" | ||
|
||
if [[ "${@#clean}" = "$@" ]] | ||
then | ||
echo "use cache for project build" | ||
else | ||
echo "clean project - remove $build_dir" | ||
rm -rf $build_dir | ||
fi | ||
|
||
if [[ "${@#release}" = "$@" ]] | ||
then | ||
build_type="Debug" | ||
else | ||
build_type="Release" | ||
rm -rf $build_dir | ||
fi | ||
echo "project build type: $build_type" | ||
|
||
if [[ "${@#with_ssl}" = "$@" ]] | ||
then | ||
ssl_support="OFF" | ||
vcpkg_file=vcpkg-no-ssl.json | ||
else | ||
ssl_support="ON" | ||
vcpkg_file=vcpkg-with-ssl.json | ||
fi | ||
echo "project SSL support: $ssl_support" | ||
cp $vcpkg_file vcpkg.json | ||
|
||
|
||
cmake -B build -S . -D"WT_WITH_SSL=$ssl_support" -D"CMAKE_BUILD_TYPE=$build_type" -D"CMAKE_TOOLCHAIN_FILE=$toolchain_file" -D"CMAKE_MAKE_PROGRAM:PATH=make" -D"CMAKE_CXX_COMPILER=g++" | ||
cmake --build build | ||
|
||
ctest --test-dir build/test/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
set(LIBS_FOR_EXAMPLES | ||
${LIBUSOCKETS_STATIC} | ||
nlohmann_json::nlohmann_json | ||
nlohmann_json_schema_validator | ||
ZLIB::ZLIB | ||
) | ||
|
||
set(INCLUDES_FOR_EXAMPLES ../include ${UWEBSOCKETS_INCLUDE_DIRS} ${MDNS_INCLUDE_DIRS}) | ||
|
||
|
||
function(create_example_binary cpp_file) | ||
cmake_path(GET cpp_file STEM target) | ||
message("configure example '${target}'") | ||
add_executable("${target}" ${cpp_file}) | ||
|
||
set_property(TARGET "${target}" PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") | ||
|
||
target_include_directories("${target}" PRIVATE ${INCLUDES_FOR_EXAMPLES}) | ||
target_link_libraries("${target}" PRIVATE ${LIBS_FOR_EXAMPLES}) | ||
|
||
IF(WIN32) | ||
target_link_libraries("${target}" PRIVATE uv_a) | ||
ENDIF(WIN32) | ||
|
||
IF(WT_WITH_SSL) | ||
target_link_libraries("${target}" PRIVATE OpenSSL::SSL OpenSSL::Crypto) | ||
ENDIF(WT_WITH_SSL) | ||
|
||
endfunction() | ||
|
||
create_example_binary(single-thing.cpp) | ||
create_example_binary(multiple-things.cpp) | ||
create_example_binary(gui-thing.cpp) |
Oops, something went wrong.