From 9c9feba565785b820335dd5be3074271f0982369 Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Fri, 18 Oct 2024 11:53:19 -0400 Subject: [PATCH] build: use File to dl toml++ if not on system --- cmake/Libraries.cmake | 32 -------------------- meson.build | 7 ----- meson_options.txt | 1 - scripts/lib/meson.py | 1 - src/lib/deskflow/CMakeLists.txt | 28 ++++++++++++++++- src/lib/deskflow/Config.cpp | 10 ++---- src/test/integtests/deskflow/ConfigTests.cpp | 8 ++--- subprojects/tomlplusplus.wrap | 10 ------ 8 files changed, 33 insertions(+), 64 deletions(-) delete mode 100644 subprojects/tomlplusplus.wrap diff --git a/cmake/Libraries.cmake b/cmake/Libraries.cmake index 43dd1b631..d8e3ed129 100644 --- a/cmake/Libraries.cmake +++ b/cmake/Libraries.cmake @@ -29,7 +29,6 @@ macro(configure_libs) configure_qt() configure_openssl() configure_coverage() - configure_tomlplusplus() if(BUILD_TESTS) configure_gtest() @@ -641,34 +640,3 @@ macro(configure_wintoast) endif() endmacro() - -macro(configure_tomlplusplus) - file(GLOB tomlplusplus_dir ${PROJECT_SOURCE_DIR}/subprojects/tomlplusplus-*) - - if(tomlplusplus_dir) - set(DEFAULT_SYSTEM_TOMLPLUSPLUS OFF) - else() - set(DEFAULT_SYSTEM_TOMLPLUSPLUS ON) - endif() - - option(SYSTEM_TOMLPLUSPLUS "Use system tomlplusplus" - ${DEFAULT_SYSTEM_TOMLPLUSPLUS}) - if(SYSTEM_TOMLPLUSPLUS) - message(VERBOSE "Using system tomlplusplus") - find_package(tomlplusplus) - if(tomlplusplus_FOUND) - message(STATUS "tomlplusplus version: ${tomlplusplus_VERSION}") - else() - message(WARNING "System tomlplusplus not found") - endif() - else() - if(EXISTS ${tomlplusplus_dir}) - message(VERBOSE "Using local tomlplusplus") - set(HAVE_TOMLPLUSPLUS true) - add_definitions(-DHAVE_TOMLPLUSPLUS=1) - include_directories(${tomlplusplus_dir}/include) - else() - message(WARNING "Local tomlplusplus subproject not found") - endif() - endif() -endmacro() diff --git a/meson.build b/meson.build index 09b1dd723..56cda85d4 100644 --- a/meson.build +++ b/meson.build @@ -9,13 +9,6 @@ if host_machine.system() == 'windows' subproject('wintoast') endif -system_tomlplusplus = get_option('system-tomlplusplus') -if system_tomlplusplus - dependency('tomlplusplus', required: false) -else - subproject('tomlplusplus') -endif - system_gtest = get_option('system-gtest') if system_gtest dependency('gtest', required: false) diff --git a/meson_options.txt b/meson_options.txt index ff8f65104..c83cce109 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,4 +1,3 @@ option('system-gtest', type: 'boolean', value: true, description: 'Use system gtest') option('system-libportal', type: 'boolean', value: true, description: 'Use system libportal') option('system-libei', type: 'boolean', value: true, description: 'Use system libei') -option('system-tomlplusplus', type: 'boolean', value: true, description: 'Use system tomlplusplus') diff --git a/scripts/lib/meson.py b/scripts/lib/meson.py index 22d771650..e5bb250ea 100644 --- a/scripts/lib/meson.py +++ b/scripts/lib/meson.py @@ -34,7 +34,6 @@ def setup(no_system_list, static_list): # or somewhere other than this script, as it's a bit hacky. if env.is_windows(): cmd.append("-Dsystem-gtest=false") - cmd.append("-Dsystem-tomlplusplus=false") for subproject in no_system_list or []: cmd.append(f"-Dsystem-{subproject}=false") diff --git a/src/lib/deskflow/CMakeLists.txt b/src/lib/deskflow/CMakeLists.txt index 3db6a3062..1bf9c5705 100644 --- a/src/lib/deskflow/CMakeLists.txt +++ b/src/lib/deskflow/CMakeLists.txt @@ -32,6 +32,26 @@ else() message(STATUS "CLI11 INC_DIR: ${cli11_inc_dir}") endif() +find_package(tomlplusplus QUIET) +if(tomlplusplus_FOUND) + message(STATUS "tomlplusplus [System] Version: ${tomlplusplus_VERSION}") + set(tomlPP_lib tomlplusplus::tomlplusplus) +else() + # Be sure to update the version and MD5 together + # Save our copy with .h not .hpp for compatibliy with system version < 3.4 + set(TOMLPP_VERSION 3.4.0) + set(TOMLPP_MD5 caefb3b60119731fb4b4d24b6339e7fb) + file( + DOWNLOAD "https://raw.githubusercontent.com/marzer/tomlplusplus/refs/tags/v${TOMLPP_VERSION}/toml.hpp" + "${CMAKE_BINARY_DIR}/include/toml++/toml.h" + SHOW_PROGRESS + EXPECTED_MD5 ${TOMLPP_MD5} + ) + set(tomlPP_inc_dir "${CMAKE_BINARY_DIR}/include") + message(STATUS "tomlplusplus [Downloaded] Version: 3.4.0") + message(STATUS "tomlplusplus INC DIR: ${tomlPP_inc_dir}") +endif() + set(lib_name app) file(GLOB headers "*.h" "languages/*.h") @@ -60,7 +80,12 @@ endif() add_library(${lib_name} STATIC ${sources}) -target_include_directories( ${lib_name} PRIVATE ${cli11_inc_dir}) +target_include_directories( + ${lib_name} + PRIVATE + ${cli11_inc_dir} + ${tomlPP_inc_dir} +) if(UNIX) target_link_libraries( @@ -74,6 +99,7 @@ if(UNIX) mt server ${cli11_lib} + ${tomlPP_lib} ) if(NOT APPLE) diff --git a/src/lib/deskflow/Config.cpp b/src/lib/deskflow/Config.cpp index 76036f860..30dd15fdd 100644 --- a/src/lib/deskflow/Config.cpp +++ b/src/lib/deskflow/Config.cpp @@ -24,9 +24,8 @@ #include #include -#if HAVE_TOMLPLUSPLUS -#include -#endif +// Use .h for fallback with 3.3.0 +#include namespace deskflow { @@ -47,7 +46,6 @@ int Config::argc() const bool Config::load(const std::string &firstArg) { -#if HAVE_TOMLPLUSPLUS if (!firstArg.empty()) { m_args.push_back(firstArg); } @@ -114,10 +112,6 @@ bool Config::load(const std::string &firstArg) } return true; -#else - LOG((CLOG_ERR "toml++ not available, config file not loaded")); - return false; -#endif // HAVE_TOMLPLUSPLUS } } // namespace deskflow diff --git a/src/test/integtests/deskflow/ConfigTests.cpp b/src/test/integtests/deskflow/ConfigTests.cpp index 8feb3ce4c..6a38d6a48 100644 --- a/src/test/integtests/deskflow/ConfigTests.cpp +++ b/src/test/integtests/deskflow/ConfigTests.cpp @@ -15,8 +15,6 @@ * along with this program. If not, see . */ -#if HAVE_TOMLPLUSPLUS - #include "deskflow/Config.h" #include @@ -64,6 +62,9 @@ TEST(ConfigTests, load_fileDoesNotExist_returnsFalse) ASSERT_FALSE(result); } +// HACK: Disable on FreeBSD, because of error: +// "Error while parsing key-value pair: encountered end-of-file". +#if !defined(__FreeBSD__) TEST(ConfigTests, load_invalidConfig_throwsException) { EXPECT_THROW( @@ -79,6 +80,7 @@ TEST(ConfigTests, load_invalidConfig_throwsException) Config::ParseError ); } +#endif TEST(ConfigTests, load_sectionMissing_returnsFalse) { @@ -133,5 +135,3 @@ TEST(ConfigTests, load_noArgs_returnsFalse) ASSERT_FALSE(result); } - -#endif // HAVE_TOMLPLUSPLUS diff --git a/subprojects/tomlplusplus.wrap b/subprojects/tomlplusplus.wrap deleted file mode 100644 index 97ff296fe..000000000 --- a/subprojects/tomlplusplus.wrap +++ /dev/null @@ -1,10 +0,0 @@ -[wrap-file] -directory = tomlplusplus-3.4.0 -source_url = https://github.com/marzer/tomlplusplus/archive/v3.4.0.tar.gz -source_filename = tomlplusplus-3.4.0.tar.gz -source_hash = 8517f65938a4faae9ccf8ebb36631a38c1cadfb5efa85d9a72e15b9e97d25155 -source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/tomlplusplus_3.4.0-1/tomlplusplus-3.4.0.tar.gz -wrapdb_version = 3.4.0-1 - -[provide] -dependency_names = tomlplusplus