Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
feat: config.toml V2
Browse files Browse the repository at this point in the history
 - Added automatic encoder selection
 - Added `run_gid` and `run_uid`
 - Added boolean start_virtual_compositor
  • Loading branch information
ABeltramo committed Mar 16, 2023
1 parent 7135150 commit 15e8a16
Show file tree
Hide file tree
Showing 22 changed files with 919 additions and 472 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ if (LINK_RUST_WAYLAND AND UNIX AND NOT APPLE)
add_subdirectory(src/rust/gst-wayland-display)
endif ()


include(TargetLinkLibrariesSystem)
add_subdirectory(src/helpers)
add_subdirectory(src/crypto)
add_subdirectory(src/moonlight)
Expand Down
31 changes: 31 additions & 0 deletions cmake/TargetLinkLibrariesSystem.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Taken from: https://stackoverflow.com/a/52136398
# The main point for this is that it'll allow to import libraries as SYSTEM
# So that warnings from libraries will be suppressed
function(target_link_libraries_system target)
set(options PRIVATE PUBLIC INTERFACE)
cmake_parse_arguments(TLLS "${options}" "" "" ${ARGN})
foreach (op ${options})
if (TLLS_${op})
set(scope ${op})
endif ()
endforeach (op)
set(libs ${TLLS_UNPARSED_ARGUMENTS})

foreach (lib ${libs})
get_target_property(lib_include_dirs ${lib} INTERFACE_INCLUDE_DIRECTORIES)
if (lib_include_dirs)
if (scope)
target_include_directories(${target} SYSTEM ${scope} ${lib_include_dirs})
else ()
target_include_directories(${target} SYSTEM PRIVATE ${lib_include_dirs})
endif ()
else ()
message("Warning: ${lib} doesn't set INTERFACE_INCLUDE_DIRECTORIES. No include_directories set.")
endif ()
if (scope)
target_link_libraries(${target} ${scope} ${lib})
else ()
target_link_libraries(${target} ${lib})
endif ()
endforeach ()
endfunction(target_link_libraries_system)
2 changes: 1 addition & 1 deletion src/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ add_library(wolf::audio ALIAS wolf_audio)

target_include_directories(wolf_audio PUBLIC .)
find_package(Boost REQUIRED)
target_link_libraries(wolf_audio
target_link_libraries_system(wolf_audio
PUBLIC
Boost::boost
wolf::helpers)
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ target_include_directories(wolf_crypto PUBLIC .)
find_package(OpenSSL REQUIRED)

# This depends on OpenSSL
target_link_libraries(
target_link_libraries_system(
wolf_crypto PUBLIC
OpenSSL::SSL
OpenSSL::Crypto)
Expand Down
4 changes: 2 additions & 2 deletions src/docker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ if (NOT boost_json_POPULATED)

add_library(boost_json INTERFACE)
target_include_directories(boost_json INTERFACE ${boost_json_SOURCE_DIR}/include)
target_link_libraries(wolf_docker PRIVATE boost_json)
target_link_libraries_system(wolf_docker PRIVATE boost_json)
endif ()

find_package(CURL) # REQUIRED UnixSockets removed because it doesn't work in Github Actions
target_link_libraries(wolf_docker
target_link_libraries_system(wolf_docker
PRIVATE
CURL::libcurl
wolf::helpers)
Expand Down
8 changes: 3 additions & 5 deletions src/helpers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,20 @@ FetchContent_Declare(
GIT_REPOSITORY https://github.com/ericniebler/range-v3.git
GIT_TAG 0.12.0)
FetchContent_MakeAvailable(range)
target_link_libraries_system(wolf_helpers INTERFACE range-v3::range-v3)

# Formatting library
FetchContent_Declare(
fmtlib
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 9.1.0)
FetchContent_MakeAvailable(fmtlib)
target_link_libraries_system(wolf_helpers INTERFACE fmt::fmt-header-only)

# Boost for logging
find_package(Boost REQUIRED COMPONENTS log_setup log)
include_directories(${Boost_INCLUDE_DIRS})

target_link_libraries(wolf_helpers INTERFACE
${Boost_LIBRARIES}
fmt::fmt-header-only
range-v3::range-v3)
target_link_libraries(wolf_helpers INTERFACE ${Boost_LIBRARIES})

# All users of this library will need at least C++17
target_compile_features(wolf_helpers INTERFACE cxx_std_17)
6 changes: 3 additions & 3 deletions src/input/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if (UNIX AND NOT APPLE)
"platforms/linux/uinput.hpp")

find_package(ICU 61.0 COMPONENTS uc REQUIRED)
target_link_libraries(wolf_input PRIVATE ICU::uc)
target_link_libraries_system(wolf_input PRIVATE ICU::uc)
else () # TODO: other platforms??
message(WARNING "Missing virtual input implementation for the current platform")
list(APPEND PRIVATE_LIST "platforms/unknown/input.cpp")
Expand All @@ -44,6 +44,7 @@ FetchContent_Declare(
)
set(EVENTBUS_BUILD_TESTS OFF)
FetchContent_MakeAvailable(eventbus)
target_link_libraries_system(wolf_input PUBLIC dp::eventbus)

# We need this directory, and users of our library will need it too
target_include_directories(wolf_input PUBLIC .)
Expand All @@ -57,8 +58,7 @@ include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(wolf_input PUBLIC
${Boost_LIBRARIES}
wolf::helpers
wolf::moonlight
dp::eventbus)
wolf::moonlight)

# All users of this library will need at least C++17
target_compile_features(wolf_input PUBLIC cxx_std_17)
Expand Down
8 changes: 4 additions & 4 deletions src/moonlight/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ set(immer_BUILD_EXTRAS OFF)

set(FPHSA_NAME_MISMATCHED on) # see: https://github.com/arximboldi/immer/issues/204
FetchContent_MakeAvailable(immer)
target_link_libraries(moonlight PUBLIC immer)
target_link_libraries_system(moonlight PUBLIC immer)
unset(FPHSA_NAME_MISMATCHED)

# FEC implementation
Expand All @@ -54,7 +54,7 @@ if (NOT nanors_POPULATED)
set_source_files_properties(${nanors_SOURCE_DIR}/rs.c
PROPERTIES COMPILE_FLAGS "-include deps/obl/autoshim.h -ftree-vectorize")

target_link_libraries(moonlight PUBLIC nanors::nanors)
target_link_libraries_system(moonlight PUBLIC nanors::nanors)
endif ()

# Additional algorithms for dealing with containers
Expand All @@ -63,7 +63,7 @@ FetchContent_Declare(
GIT_REPOSITORY https://github.com/ericniebler/range-v3.git
GIT_TAG 0.12.0)
FetchContent_MakeAvailable(range)
target_link_libraries(moonlight PUBLIC range-v3::range-v3)
target_link_libraries_system(moonlight PUBLIC range-v3::range-v3)

# Custom parser
FetchContent_Declare(
Expand All @@ -77,7 +77,7 @@ if (NOT peglib_POPULATED)

add_library(peglib INTERFACE)
target_include_directories(peglib INTERFACE ${peglib_SOURCE_DIR})
target_link_libraries(moonlight PUBLIC peglib)
target_link_libraries_system(moonlight PUBLIC peglib)
endif ()

# We need this directory, and users of our library will need it too
Expand Down
17 changes: 9 additions & 8 deletions src/streaming/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ FetchContent_Declare(
fmtlib
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 9.1.0)

FetchContent_MakeAvailable(fmtlib)
target_link_libraries_system(streaming PUBLIC fmt::fmt-header-only)

FetchContent_Declare(
eventbus
Expand All @@ -25,6 +25,7 @@ FetchContent_Declare(
)
set(EVENTBUS_BUILD_TESTS OFF)
FetchContent_MakeAvailable(eventbus)
target_link_libraries_system(streaming PUBLIC dp::eventbus)

find_package(PkgConfig)
pkg_check_modules(GSTREAMER REQUIRED gstreamer-1.0 gstreamer-base-1.0 gstreamer-app-1.0)
Expand All @@ -35,7 +36,7 @@ if (NOT (GSTREAMER_FOUND))
endif ()

if (LINK_RUST_WAYLAND AND UNIX AND NOT APPLE)
target_link_libraries(streaming PUBLIC gstwaylanddisplay)
target_link_libraries_system(streaming PUBLIC gstwaylanddisplay)
list(APPEND HEADER_LIST streaming/wayland-display.hpp)
list(APPEND SRC_LIST streaming/wayland-display.cpp)
endif ()
Expand All @@ -50,12 +51,7 @@ target_sources(streaming
PUBLIC
${HEADER_LIST})

target_link_libraries(streaming PUBLIC
wolf::moonlight
wolf::helpers
wolf::input
fmt::fmt-header-only
dp::eventbus
target_link_libraries(streaming INTERFACE
${GOBJECT_LIBRARIES}
${GLIB2_LIBRARIES}
${GSTREAMER_LIBRARIES}
Expand All @@ -67,6 +63,11 @@ target_include_directories(streaming PUBLIC
${GSTREAMER_INCLUDE_DIRS}
${GSTREAMER_BASE_INCLUDE_DIRS})

target_link_libraries(streaming PUBLIC
wolf::moonlight
wolf::helpers
wolf::input)


# All users of this library will need at least C++17
target_compile_features(streaming PUBLIC cxx_std_17)
17 changes: 10 additions & 7 deletions src/wolf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ FetchContent_Declare(
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 9.1.0)
FetchContent_MakeAvailable(fmtlib) # Download and build
target_link_libraries_system(wolf_runner PUBLIC fmt::fmt-header-only)

FetchContent_Declare(
eventbus
Expand All @@ -19,23 +20,25 @@ FetchContent_Declare(
)
set(EVENTBUS_BUILD_TESTS OFF)
FetchContent_MakeAvailable(eventbus)
target_link_libraries_system(wolf_runner PUBLIC dp::eventbus)

# HTTP server library
FetchContent_Declare(
simplewebserver
GIT_REPOSITORY https://gitlab.com/eidheim/Simple-Web-Server.git
GIT_TAG bdb1057)
FetchContent_MakeAvailable(simplewebserver)
target_link_libraries(wolf_runner PUBLIC simple-web-server)
target_link_libraries_system(wolf_runner PUBLIC simple-web-server)

# TOML parser (config file)
FetchContent_Declare(
toml
GIT_REPOSITORY https://github.com/ToruNiina/toml11.git
GIT_TAG v3.7.1)
set(TOML11_COLORIZE_ERROR_MESSAGE, ON)
set(TOML11_PRESERVE_COMMENTS_BY_DEFAULT, ON)
FetchContent_MakeAvailable(toml)
target_link_libraries(wolf_runner PUBLIC toml11::toml11)
target_link_libraries_system(wolf_runner PUBLIC toml11::toml11)

# Enet
set(CMAKE_PROJECT_INCLUDE_BEFORE "${PROJECT_SOURCE_DIR}/cmake/EnableCMP0048.cmake")
Expand All @@ -44,7 +47,7 @@ FetchContent_Declare(
GIT_REPOSITORY https://github.com/cgutman/enet
GIT_TAG 4cde9cc3dcc5c30775a80da1de87f39f98672a31)
FetchContent_MakeAvailable(enet)
target_link_libraries(wolf_runner PUBLIC enet)
target_link_libraries_system(wolf_runner PUBLIC enet)
unset(CMAKE_PROJECT_INCLUDE_BEFORE)

##############################
Expand Down Expand Up @@ -86,9 +89,7 @@ target_link_libraries(
wolf::docker
${Boost_LIBRARIES}
${CMAKE_DL_LIBS}
${CMAKE_THREAD_LIBS_INIT}
fmt::fmt-header-only
dp::eventbus)
${CMAKE_THREAD_LIBS_INIT})

target_include_directories(wolf_runner PUBLIC .)

Expand All @@ -102,15 +103,17 @@ target_sources(wolf_runner
PUBLIC
${HEADER_LIST})

## Add pin.html
## Make files includable
function(make_includable input_file output_file)
file(READ ${input_file} content)
set(delim "for_c++_include")
set(content "R\"${delim}(\n${content})${delim}\"")
file(WRITE ${output_file} "${content}")
message(STATUS "Generating file: ${output_file}")
endfunction(make_includable)

make_includable(rest/html/pin.html rest/html/pin.include.html)
make_includable(state/default/config.v2.toml state/default/config.include.toml)

# All users of this library will need at least C++17
target_compile_features(wolf_runner PUBLIC cxx_std_17)
Expand Down
5 changes: 2 additions & 3 deletions src/wolf/rest/endpoints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ void pair(const std::shared_ptr<typename SimpleWeb::Server<T>::Response> &respon
auto client_cert_parsed = crypto::hex_to_str(client_cert_str.value(), true);

state->pairing_cache->update([&](const immer::map<std::string, state::PairCache> &pairing_cache) {
return pairing_cache.set(cache_key,
{client_id.value(), client_cert_parsed, result.second, std::nullopt, std::nullopt});
return pairing_cache.set(cache_key, {.client_cert = client_cert_parsed, .aes_key = result.second});
});

send_xml<T>(response, SimpleWeb::StatusCode::success_ok, result.first);
Expand Down Expand Up @@ -168,7 +167,7 @@ void pair(const std::shared_ptr<typename SimpleWeb::Server<T>::Response> &respon

auto is_paired = xml.template get<int>("root.paired");
if (is_paired == 1) {
state::pair(state->config, {client_id.value(), client_cache.client_cert});
state::pair(state->config, state::PairedClient{.client_cert = client_cache.client_cert});
logs::log(logs::info, "Succesfully paired {}", client_ip);
} else {
logs::log(logs::warning, "Failed pairing with {}", client_ip);
Expand Down
3 changes: 2 additions & 1 deletion src/wolf/rest/servers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ void startServer(HttpServer *server, const immer::box<state::AppState> state, in
auto cache_key = client_id.value() + "@" + client_ip;

logs::log(logs::info, "Unpairing: {}", cache_key);
state::unpair(state->config, state->pairing_cache->load()->at(cache_key));
auto client = state->pairing_cache->load()->at(cache_key);
state::unpair(state->config, state::PairedClient{.client_cert = client.client_cert});

XML xml;
xml.put("root.<xmlattr>.status_code", 200);
Expand Down
2 changes: 1 addition & 1 deletion src/wolf/rtp/udp-ping.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <boost/bind.hpp>
#include <boost/bind/bind.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <rtp/udp-ping.hpp>

Expand Down
Loading

0 comments on commit 15e8a16

Please sign in to comment.