diff --git a/cmake/MultiFind.cmake b/cmake/MultiFind.cmake index b40a4677..3400a9bc 100644 --- a/cmake/MultiFind.cmake +++ b/cmake/MultiFind.cmake @@ -20,6 +20,7 @@ function(find_packages result) find_package(${pkg} ${pkg_version} REQUIRED) list(APPEND _res ${${pkg}_PKG_CONFIG_NAME}) list(APPEND _res_libs ${${pkg}_LIBRARIES}) + set(${pkg}_VERSION "${${pkg}_VERSION}" PARENT_SCOPE) endforeach(pkg) foreach(pkg ${ARGS_OPTIONAL}) string(REPLACE ">=" ";" pkg_ ${pkg}) @@ -38,6 +39,7 @@ function(find_packages result) if(${pkg}_FOUND) list(APPEND _res ${${pkg}_PKG_CONFIG_NAME}) list(APPEND _res_libs ${${pkg}_LIBRARIES}) + set(${pkg}_VERSION "${${pkg}_VERSION}" PARENT_SCOPE) endif() endforeach(pkg) set(${result} "${_res}" PARENT_SCOPE) diff --git a/cmake/SoupVersion.cmake b/cmake/SoupVersion.cmake new file mode 100644 index 00000000..625a1513 --- /dev/null +++ b/cmake/SoupVersion.cmake @@ -0,0 +1,33 @@ +find_package(Nice QUIET) +if (Nice_FOUND AND NOT SOUP_VERSION AND NOT USE_SOUP3) + file(GET_RUNTIME_DEPENDENCIES + RESOLVED_DEPENDENCIES_VAR Nice_DEPENDENCIES + UNRESOLVED_DEPENDENCIES_VAR Nice_UNRESOLVED_DEPENDENCIES + LIBRARIES ${Nice_LIBRARY} + PRE_INCLUDE_REGEXES "soup|gupnp" + PRE_EXCLUDE_REGEXES "." + ) + foreach (lib ${Nice_DEPENDENCIES}) + if (lib MATCHES ".*/libsoup-3.*") + set(SOUP_VERSION 3) + endif () + endforeach () + foreach (lib ${Nice_DEPENDENCIES}) + if (lib MATCHES ".*/libsoup-2.*") + set(SOUP_VERSION 2) + endif () + endforeach () + set(SOUP_VERSION ${SOUP_VERSION} CACHE STRING "Version of libsoup to use") + set_property(CACHE SOUP_VERSION PROPERTY STRINGS "2" "3") + message(STATUS "Using Soup${SOUP_VERSION} to provide Soup") +elseif (NOT SOUP_VERSION) + find_package(Soup2 QUIET) + find_package(Soup3 QUIET) + # Only use libsoup 3 if specifically requested or when libsoup 2 is not available + if (Soup3_FOUND AND NOT Soup2_FOUND OR USE_SOUP3) + set(SOUP_VERSION 3) + else () + set(SOUP_VERSION 2) + endif () +endif () +set(Soup "Soup${SOUP_VERSION}") \ No newline at end of file diff --git a/configure b/configure index 974a54df..30b0bed5 100755 --- a/configure +++ b/configure @@ -1,7 +1,7 @@ #!/bin/sh OPTS=`getopt -o "h" --long \ -help,fetch-only,no-debug,disable-fast-vapi,with-tests,release,with-libsignal-in-tree,\ +help,fetch-only,no-debug,disable-fast-vapi,with-tests,release,with-libsignal-in-tree,with-libsoup3,\ enable-plugin:,disable-plugin:,\ prefix:,program-prefix:,exec-prefix:,lib-suffix:,\ bindir:,libdir:,includedir:,datadir:,\ @@ -22,6 +22,7 @@ DISABLE_FAST_VAPI= LIB_SUFFIX= NO_DEBUG= FETCH_ONLY= +USE_SOUP3= EXEC_PREFIX= BINDIR= @@ -56,6 +57,7 @@ Configuration: --release Configure to build an optimized release version --with-libsignal-in-tree Build libsignal-protocol-c in tree and link it statically. + --with-libsoup3 Build with libsoup-3.0 --with-tests Also build tests. Plugin configuration: @@ -111,6 +113,7 @@ while true; do --valac-flags ) VALAC_FLAGS="$2"; shift; shift ;; --lib-suffix ) LIB_SUFFIX="$2"; shift; shift ;; --with-libsignal-in-tree ) BUILD_LIBSIGNAL_IN_TREE=yes; shift ;; + --with-libsoup3 ) USE_SOUP3=yes; shift ;; --disable-fast-vapi ) DISABLE_FAST_VAPI=yes; shift ;; --no-debug ) NO_DEBUG=yes; shift ;; --fetch-only ) FETCH_ONLY=yes; shift ;; @@ -256,6 +259,7 @@ cmake -G "$cmake_type" \ -DDISABLED_PLUGINS="$DISABLED_PLUGINS" \ -DBUILD_TESTS="$BUILD_TESTS" \ -DBUILD_LIBSIGNAL_IN_TREE="$BUILD_LIBSIGNAL_IN_TREE" \ + -DUSE_SOUP3="$USE_SOUP3" \ -DVALA_EXECUTABLE="$VALAC" \ -DCMAKE_VALA_FLAGS="$VALACFLAGS" \ -DDISABLE_FAST_VAPI="$DISABLE_FAST_VAPI" \ diff --git a/plugins/http-files/CMakeLists.txt b/plugins/http-files/CMakeLists.txt index b29cfda3..f9d1213b 100644 --- a/plugins/http-files/CMakeLists.txt +++ b/plugins/http-files/CMakeLists.txt @@ -1,11 +1,4 @@ -set(HTTP_FILES_DEFINITIONS) -if(USE_SOUP3) - set(Soup Soup3) - set(HTTP_FILES_DEFINITIONS ${HTTP_FILES_DEFINITIONS} SOUP_3) -else() - set(Soup Soup2) -endif() - +include(SoupVersion) find_packages(HTTP_FILES_PACKAGES REQUIRED Gee GLib @@ -15,6 +8,12 @@ find_packages(HTTP_FILES_PACKAGES REQUIRED ${Soup} ) +set(HTTP_FILES_DEFINITIONS) + +if(${Soup}_VERSION VERSION_GREATER_EQUAL "3.0") + set(HTTP_FILES_DEFINITIONS ${HTTP_FILES_DEFINITIONS} SOUP_3_0) +endif() + vala_precompile(HTTP_FILES_VALA_C SOURCES src/file_provider.vala diff --git a/plugins/http-files/src/file_provider.vala b/plugins/http-files/src/file_provider.vala index 3a3aeb94..7928dc81 100644 --- a/plugins/http-files/src/file_provider.vala +++ b/plugins/http-files/src/file_provider.vala @@ -101,7 +101,7 @@ public class FileProvider : Dino.FileProvider, Object { head_message.request_headers.append("Accept-Encoding", "identity"); try { -#if SOUP_3 +#if SOUP_3_0 yield session.send_async(head_message, GLib.Priority.LOW, null); #else yield session.send_async(head_message, null); @@ -136,7 +136,7 @@ public class FileProvider : Dino.FileProvider, Object { var get_message = new Soup.Message("GET", http_receive_data.url); try { -#if SOUP_3 +#if SOUP_3_0 InputStream stream = yield session.send_async(get_message, GLib.Priority.LOW, file_transfer.cancellable); #else InputStream stream = yield session.send_async(get_message, file_transfer.cancellable); diff --git a/plugins/http-files/src/file_sender.vala b/plugins/http-files/src/file_sender.vala index ab81ffce..a39d695b 100644 --- a/plugins/http-files/src/file_sender.vala +++ b/plugins/http-files/src/file_sender.vala @@ -73,7 +73,7 @@ public class HttpFileSender : FileSender, Object { } } -#if !SOUP_3 +#if !SOUP_3_0 private static void transfer_more_bytes(InputStream stream, Soup.MessageBody body) { uint8[] bytes = new uint8[4096]; ssize_t read = stream.read(bytes); @@ -93,7 +93,7 @@ public class HttpFileSender : FileSender, Object { var session = new Soup.Session(); session.user_agent = @"Dino/$(Dino.get_short_version()) "; var put_message = new Soup.Message("PUT", file_send_data.url_up); -#if SOUP_3 +#if SOUP_3_0 put_message.set_request_body(file_meta.mime_type, file_transfer.input_stream, (ssize_t) file_meta.size); #else put_message.request_headers.set_content_type(file_meta.mime_type, null); @@ -106,7 +106,7 @@ public class HttpFileSender : FileSender, Object { put_message.request_headers.append(entry.key, entry.value); } try { -#if SOUP_3 +#if SOUP_3_0 yield session.send_async(put_message, GLib.Priority.LOW, file_transfer.cancellable); #else yield session.send_async(put_message, file_transfer.cancellable);