From d255d21eff718785b1146b4232b151eeff54e9e9 Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Tue, 10 Dec 2024 09:19:35 +0100 Subject: [PATCH 1/2] Use o2 library from https://github.com/qgis/o2/ --- cmake/FindO2.cmake | 77 +++++++++++----------------------- src/auth/oauth2/CMakeLists.txt | 21 ++++------ vcpkg/ports/o2/portfile.cmake | 22 ++++++++++ vcpkg/ports/o2/vcpkg.json | 18 ++++++++ vcpkg/vcpkg.json | 1 + 5 files changed, 73 insertions(+), 66 deletions(-) create mode 100644 vcpkg/ports/o2/portfile.cmake create mode 100644 vcpkg/ports/o2/vcpkg.json diff --git a/cmake/FindO2.cmake b/cmake/FindO2.cmake index 421d52af182a..800348cec9ba 100644 --- a/cmake/FindO2.cmake +++ b/cmake/FindO2.cmake @@ -1,59 +1,30 @@ -# Find O2 -# ~~~~~~~~~ -# Copyright (c) 2016, Monsanto Company, USA -# Author: Larry Shaffer, +# FindO2.cmake - Find the O2 library using pkg-config # -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. -# -# CMake module to search for O2 OAuth 1/2 library from: -# https://github.com/pipacs/o2 -# -# If it's found it sets O2_FOUND to TRUE -# and following variables are set: -# O2_INCLUDE_DIR -# O2_LIBRARY -# O2_LIBRARY_STATIC - -IF (O2_INCLUDE_DIR AND (O2_LIBRARY OR O2_LIBRARY_STATIC)) - SET(O2_FOUND TRUE) +# This module defines: +# - `O2_FOUND` - Set to TRUE if the library is found. +# - `O2_INCLUDE_DIRS` - Include directories for the library. +# - `O2_LIBRARIES` - Libraries to link against. +# - The alias target `o2::o2` if the library is found. -ELSE (O2_INCLUDE_DIR AND (O2_LIBRARY OR O2_LIBRARY_STATIC)) +find_package(PkgConfig REQUIRED) - FIND_PATH(O2_INCLUDE_DIR o2.h - PATHS - /usr/include - /usr/local/include - "$ENV{LIB_DIR}/include" - $ENV{INCLUDE} - PATH_SUFFIXES o2 - ) - FIND_LIBRARY(O2_LIBRARY NAMES o2 - PATHS - /usr/local/lib - /usr/lib - "$ENV{LIB_DIR}/lib" - "$ENV{LIB}" - ) - FIND_LIBRARY(O2_LIBRARY_STATIC NAMES libo2.a libo2_static.a o2_static - PATHS - /usr/local/lib - /usr/lib - "$ENV{LIB_DIR}/lib" - "$ENV{LIB}" - ) +pkg_search_module(PC_O2 IMPORTED_TARGET o2) - include(FindPackageHandleStandardArgs) - find_package_handle_standard_args(O2 DEFAULT_MSG O2_LIBRARY O2_INCLUDE_DIR) +if (PC_O2_FOUND) + set(O2_FOUND TRUE) + set(O2_INCLUDE_DIRS ${PC_O2_INCLUDE_DIRS}) + set(O2_LIBRARIES ${PC_O2_LIBRARIES}) -ENDIF (O2_INCLUDE_DIR AND (O2_LIBRARY OR O2_LIBRARY_STATIC)) + add_library(o2::o2 ALIAS PkgConfig::PC_O2) +else() + set(O2_FOUND FALSE) + if (NOT O2_FIND_QUIETLY) + message(WARNING "O2 library not found via pkg-config.") + endif() + if (O2_FIND_REQUIRED) + message(FATAL_ERROR "O2 library is required but was not found.") + endif() +endif() -IF (O2_FOUND) - IF (NOT O2_FIND_QUIETLY) - MESSAGE(STATUS "Found O2: ${O2_LIBRARY} ${O2_LIBRARY_STATIC}") - ENDIF (NOT O2_FIND_QUIETLY) -ELSE (O2_FOUND) - IF (O2_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Could not find O2") - ENDIF (O2_FIND_REQUIRED) -ENDIF (O2_FOUND) +# Mark results for cache +mark_as_advanced(O2_INCLUDE_DIRS O2_LIBRARIES) diff --git a/src/auth/oauth2/CMakeLists.txt b/src/auth/oauth2/CMakeLists.txt index 5f9931446376..a4348cf48f5d 100644 --- a/src/auth/oauth2/CMakeLists.txt +++ b/src/auth/oauth2/CMakeLists.txt @@ -3,7 +3,12 @@ ######################################################## # Packages -option(WITH_INTERNAL_O2 "Download and locally include source of o2 library" ON) +if(WITH_VGPKG) + set(WITH_INTERNAL_O2_DEFAULT OFF) +else() + set(WITH_INTERNAL_O2_DEFAULT ON) +endif() +option(WITH_INTERNAL_O2 "Download and locally include source of o2 library" ${WITH_INTERNAL_O2_DEFAULT}) if(WITH_INTERNAL_O2) set(O2_SOURCE_DIR ${CMAKE_SOURCE_DIR}/external/o2/src) @@ -113,12 +118,7 @@ target_link_libraries(authmethod_oauth2_a qgis_core) if(WITH_INTERNAL_O2) target_include_directories(authmethod_oauth2_a SYSTEM PUBLIC ${O2_INCLUDE_DIR}) else() - if(NOT "${O2_LIBRARY}" STREQUAL "") - # prefer dynamic linking - target_link_libraries(authmethod_oauth2_a ${O2_LIBRARY}) - else() - target_link_libraries(authmethod_oauth2_a ${O2_LIBRARY_STATIC}) - endif() + target_link_libraries(authmethod_oauth2_a o2::o2) endif() target_include_directories(authmethod_oauth2_a PRIVATE @@ -154,12 +154,7 @@ else() if(WITH_INTERNAL_O2) target_include_directories(authmethod_oauth2 SYSTEM PUBLIC ${O2_INCLUDE_DIR}) else() - if(NOT "${O2_LIBRARY}" STREQUAL "") - # prefer dynamic linking - target_link_libraries(authmethod_oauth2 ${O2_LIBRARY}) - else() - target_link_libraries(authmethod_oauth2 ${O2_LIBRARY_STATIC}) - endif() + target_link_libraries(authmethod_oauth2 o2::o2) endif() if(WIN32) diff --git a/vcpkg/ports/o2/portfile.cmake b/vcpkg/ports/o2/portfile.cmake new file mode 100644 index 000000000000..dc4edf73e942 --- /dev/null +++ b/vcpkg/ports/o2/portfile.cmake @@ -0,0 +1,22 @@ +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO qgis/o2 + REF "v${VERSION}" + SHA512 e0116a8f72e8c98ef4237e36598a8f246319a30bb5bfab629e3220e7b819b1e9028c2e6caa4c92f17c4b0548c94c242120c5b4750abce2441a2db5d88b2e22f5 + HEAD_REF master +) + +vcpkg_cmake_configure( + DISABLE_PARALLEL_CONFIGURE + SOURCE_PATH ${SOURCE_PATH} + OPTIONS + -Do2_WITH_QT6=ON + -Do2_WITH_KEYCHAIN=ON +) +vcpkg_cmake_install() +vcpkg_fixup_pkgconfig() + +vcpkg_copy_pdbs() + +# Handle copyright +file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright) diff --git a/vcpkg/ports/o2/vcpkg.json b/vcpkg/ports/o2/vcpkg.json new file mode 100644 index 000000000000..2f9f5e30a384 --- /dev/null +++ b/vcpkg/ports/o2/vcpkg.json @@ -0,0 +1,18 @@ +{ + "name": "o2", + "version": "1", + "description": "OAuth 2.0 for Qt", + "homepage": "https://github.com/qgis/o2", + "license": "BSD-2-Clause", + "dependencies": [ + "qtkeychain-qt6", + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ] +} diff --git a/vcpkg/vcpkg.json b/vcpkg/vcpkg.json index c84511c70188..0aaff0024023 100644 --- a/vcpkg/vcpkg.json +++ b/vcpkg/vcpkg.json @@ -61,6 +61,7 @@ "libzip", "meshoptimizer", "nlohmann-json", + "o2", "pdal", "proj", "protobuf", From 42e044ca4fed4e842f29637a37886bd0f2ead776 Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Tue, 10 Dec 2024 11:37:45 +0100 Subject: [PATCH 2/2] Sync o2 --- external/o2/CMakeLists.txt | 72 +++++++++++++++++++++++++++++++--- external/o2/src/CMakeLists.txt | 62 ++++++++--------------------- external/o2/src/o2.cpp | 12 ------ 3 files changed, 83 insertions(+), 63 deletions(-) diff --git a/external/o2/CMakeLists.txt b/external/o2/CMakeLists.txt index 45eeddddaa52..01fdd05aa2da 100644 --- a/external/o2/CMakeLists.txt +++ b/external/o2/CMakeLists.txt @@ -1,7 +1,7 @@ -cmake_minimum_required(VERSION 2.8.11) +cmake_minimum_required(VERSION 3.10.0) if(POLICY CMP0048) # in CMake >= 3.0.0 - cmake_policy(SET CMP0048 OLD) # keep project() from clearing VERSION variables + cmake_policy(SET CMP0048 NEW) endif(POLICY CMP0048) set( CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules ) @@ -16,9 +16,9 @@ set(CPACK_PACKAGE_VERSION_PATCH ${VER_PATCH}) set(PROJECT_VERSION ${VER_MAJOR}.${VER_MINOR}.${VER_PATCH}) set(API_VERSION ${VER_MAJOR}.${VER_MINOR}.${API_VER_PATCH}) -project(o2) +project(o2 VERSION ${PROJECT_VERSION}) -option(o2_WITH_QT5 "Use Qt5" ON) +option(o2_WITH_QT6 "Use Qt6" ON) set(o2_LIB_SUFFIX "" CACHE STRING "Suffix for install 'lib' directory, e.g. 64 for lib64") @@ -27,19 +27,76 @@ if(NOT o2_SHOW_TRACE) add_definitions(-DQT_NO_DEBUG_OUTPUT=1) endif() +option(o2_WITH_TESTS "Enable tests" OFF) option(o2_WITH_TWITTER "Authenticate with Twitter" OFF) option(o2_WITH_DROPBOX "Authenticate with Dropbox" OFF) option(o2_WITH_GOOGLE "Authenticate with Google" OFF) +option(o2_WITH_VIMEO "Authenticate with Vimeo" OFF) option(o2_WITH_FACEBOOK "Authenticate with Facebook" OFF) +option(o2_WITH_UBER "Authenticate with Uber" OFF) option(o2_WITH_SKYDRIVE "Authenticate with SkyDrive" OFF) option(o2_WITH_FLICKR "Authenticate with Flickr" OFF) option(o2_WITH_HUBIC "Authenticate with Hubic" OFF) option(o2_WITH_SPOTIFY "Authenticate with Spotify" OFF) option(o2_WITH_SURVEYMONKEY "Authenticate with SurveyMonkey" OFF) +option(o2_WITH_SMUGMUG "Authenticate with SmugMug" OFF) +option(o2_WITH_MSGRAPH "Authenticate with MSGraph" OFF) option(o2_WITH_KEYCHAIN "keychain store" ON) option(o2_WITH_OAUTH1 "Include OAuth1 authentication" OFF) -if(o2_WITH_TWITTER OR o2_WITH_DROPBOX OR o2_WITH_FLICKR) + +if (o2_WITH_TWITTER) + set(HAVE_TWITTER_SUPPORT 1) +endif() +if (o2_WITH_DROPBOX) + set(HAVE_DROPBOX_SUPPORT 1) +endif() +if (o2_WITH_GOOGLE) + set(HAVE_GOOGLE_SUPPORT 1) +endif() +if (o2_WITH_FACEBOOK) + set(HAVE_FACEBOOK_SUPPORT 1) +endif() +if (o2_WITH_UBER) + set(HAVE_UBER_SUPPORT 1) +endif() +if (o2_WITH_SKYDRIVE) + set(HAVE_SKYDRIVE_SUPPORT 1) +endif() +if (o2_WITH_FLICKR) + set(HAVE_FLICKR_SUPPORT 1) +endif() +if (o2_WITH_HUBIC) + set(HAVE_HUBIC_SUPPORT 1) +endif() +if (o2_WITH_SPOTIFY) + set(HAVE_SPOTIFY_SUPPORT 1) +endif() +if (o2_WITH_SURVEYMONKEY) + set(HAVE_SURVEYMONKEY_SUPPORT 1) +endif() +if (o2_WITH_SMUGMUG) + set(HAVE_SMUGMUG_SUPPORT 1) +endif() +if (o2_WITH_MSGRAPH) + set(HAVE_MSGRAPH_SUPPORT 1) +endif() +if (o2_WITH_KEYCHAIN) + set(HAVE_KEYCHAIN_SUPPORT 1) +endif() +if (o2_WITH_OAUTH1) + set(HAVE_OAUTH1_SUPPORT 1) +endif() + +if(o2_WITH_KEYCHAIN) + if(o2_WITH_QT6) + find_package(Qt6Keychain CONFIG REQUIRED) + else() + find_package(Qt5Keychain CONFIG REQUIRED) + endif() +endif(o2_WITH_KEYCHAIN) + +if(o2_WITH_TWITTER OR o2_WITH_DROPBOX OR o2_WITH_FLICKR OR o2_WITH_SMUGMUG) set(o2_WITH_OAUTH1 ON) endif() @@ -54,3 +111,8 @@ add_subdirectory(src) if(o2_BUILD_EXAMPLES) add_subdirectory(examples) endif(o2_BUILD_EXAMPLES) + +if(o2_WITH_TESTS) + enable_testing() + add_subdirectory(tests) +endif() diff --git a/external/o2/src/CMakeLists.txt b/external/o2/src/CMakeLists.txt index 39536cb71e52..7f144bcb79eb 100644 --- a/external/o2/src/CMakeLists.txt +++ b/external/o2/src/CMakeLists.txt @@ -1,22 +1,14 @@ -cmake_minimum_required(VERSION 2.8.11) +cmake_minimum_required(VERSION 3.10.0) set(CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") -if(o2_WITH_QT5) +if(o2_WITH_QT6) + find_package(Qt6 COMPONENTS Core Network REQUIRED) +else() find_package(Qt5 COMPONENTS Core Network REQUIRED) -else(o2_WITH_QT5) - set(QT_USE_QTNETWORK true) - set(QT_USE_QTSCRIPT true) - find_package(Qt4 REQUIRED) -endif(o2_WITH_QT5) -#find_package(QJson REQUIRED) - -if (NOT o2_WITH_QT5) - include( ${QT_USE_FILE} ) -endif(NOT o2_WITH_QT5) - +endif() set( o2_SRCS o2.cpp @@ -192,37 +184,19 @@ if(o2_WITH_MSGRAPH) endif(o2_WITH_MSGRAPH) if(o2_WITH_KEYCHAIN) - if (Qt5Core_DIR) - find_package(Qt5Keychain REQUIRED) - else() - find_package(QtKeychain REQUIRED) - endif() - if(QTKEYCHAIN_FOUND OR QT5KEYCHAIN_FOUND) - MESSAGE("Found QTKeychain") - list(APPEND LINK_TARGETS ${QTKEYCHAIN_LIBRARY}) - include_directories(${QTKEYCHAIN_INCLUDE_DIR}) - set( o2_SRCS - ${o2_SRCS} - o0keychainstore.cpp - ) - set( o2_HDRS - ${o2_HDRS} - o0keychainstore.h - ) - else() - MESSAGE("Qt5Keychain or QtKeychain is required") - endif() - + list(APPEND LINK_TARGETS ${QTKEYCHAIN_LIBRARIES}) + include_directories(SYSTEM ${QTKEYCHAIN_INCLUDE_DIRS}) + set( o2_SRCS + ${o2_SRCS} + o0keychainstore.cpp + ) + set( o2_HDRS + ${o2_HDRS} + o0keychainstore.h + ) endif(o2_WITH_KEYCHAIN) - - - -if(NOT o2_WITH_QT5) - add_definitions(${QT4_DEFINITIONS}) -endif(NOT o2_WITH_QT5) - if(BUILD_SHARED_LIBS AND APPLE AND POLICY CMP0042) # in CMake >= 2.8.12 cmake_policy(SET CMP0042 OLD) set(CMAKE_MACOSX_RPATH OFF) # don't embed @rpath in install name @@ -234,11 +208,7 @@ if(BUILD_SHARED_LIBS) add_definitions( -DO2_SHARED_LIB ) endif(BUILD_SHARED_LIBS) -if(o2_WITH_QT5) - target_link_libraries( o2 Qt5::Core Qt5::Network ${LINK_TARGETS}) -else(o2_WITH_QT5) - target_link_libraries( o2 ${QT_LIBRARIES} ${LINK_TARGETS}) -endif(o2_WITH_QT5) +target_link_libraries( o2 Qt::Core Qt::Network ${LINK_TARGETS}) if(BUILD_SHARED_LIBS) if(APPLE) diff --git a/external/o2/src/o2.cpp b/external/o2/src/o2.cpp index e63c830547b9..ebbb7b3838e1 100644 --- a/external/o2/src/o2.cpp +++ b/external/o2/src/o2.cpp @@ -10,16 +10,8 @@ #include #include #include - -#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) #include -#endif - -#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) #include -#else -#include -#endif #include "o2.h" #include "o2pollserver.h" @@ -197,12 +189,8 @@ void O2::link() { if (grantFlow_ == GrantFlowAuthorizationCode || grantFlow_ == GrantFlowImplicit || grantFlow_ == GrantFlowPkce) { -#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) const thread_local QRegularExpression rx("([^a-zA-Z0-9]|[-])"); QString uniqueState = QUuid::createUuid().toString().remove(rx); -#else - QString uniqueState = QUuid::createUuid().toString().remove(QRegExp("([^a-zA-Z0-9]|[-])")); -#endif if (useExternalWebInterceptor_) { // Save redirect URI, as we have to reuse it when requesting the access token redirectUri_ = localhostPolicy_.arg(localPort());