Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use o2 library from https://github.com/qgis/o2/ #59800

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 24 additions & 53 deletions cmake/FindO2.cmake
Original file line number Diff line number Diff line change
@@ -1,59 +1,30 @@
# Find O2
# ~~~~~~~~~
# Copyright (c) 2016, Monsanto Company, USA
# Author: Larry Shaffer, <lshaffer (at) boundlessgeo (dot) com>
# 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)
72 changes: 67 additions & 5 deletions external/o2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 )
Expand All @@ -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")

Expand All @@ -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()

Expand All @@ -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()
62 changes: 16 additions & 46 deletions external/o2/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
12 changes: 0 additions & 12 deletions external/o2/src/o2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,8 @@
#include <QTimer>
#include <QVariantMap>
#include <QUuid>

#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
#include <QUrlQuery>
#endif

#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
#include <QRegularExpression>
#else
#include <QRegExp>
#endif

#include "o2.h"
#include "o2pollserver.h"
Expand Down Expand Up @@ -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());
Expand Down
21 changes: 8 additions & 13 deletions src/auth/oauth2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions vcpkg/ports/o2/portfile.cmake
Original file line number Diff line number Diff line change
@@ -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)
18 changes: 18 additions & 0 deletions vcpkg/ports/o2/vcpkg.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
Loading
Loading