Skip to content

Commit

Permalink
Use o2 library from https://github.com/qgis/o2/
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Dec 10, 2024
1 parent d1de257 commit 9609640
Show file tree
Hide file tree
Showing 6 changed files with 852 additions and 66 deletions.
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)
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
24 changes: 24 additions & 0 deletions vcpkg/ports/o2/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO qgis/o2
REF "v${VERSION}"
SHA512 69f5d61e257cae41d870f1353dc86b8334065a6a6bcab108c8ccfed3fd11297654e29f6e7838b3a65a519df51ec218bef1853a53a4f06c03e4592c8e21512d8a
HEAD_REF master
PATCHES
qt6.patch
)

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)
Loading

0 comments on commit 9609640

Please sign in to comment.