Skip to content

Commit

Permalink
[FIXUP] cmake: Consider pkg-config --static output when cross-compi…
Browse files Browse the repository at this point in the history
…ling
  • Loading branch information
hebasto committed Mar 25, 2024
1 parent 3c0f5c9 commit e5f2f27
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 40 deletions.
23 changes: 14 additions & 9 deletions cmake/module/AddLibeventIfNeeded.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,28 @@ function(add_libevent_if_needed)
return()
endif()

include(CrossPkgConfig)
cross_pkg_check_modules(libevent
find_package(PkgConfig REQUIRED)
pkg_check_modules(libevent
REQUIRED IMPORTED_TARGET GLOBAL
libevent>=${libevent_minimum_version}
)
if(MINGW)
target_link_libraries(PkgConfig::libevent INTERFACE
iphlpapi
ws2_32
)
endif()
target_link_libraries(PkgConfig::libevent INTERFACE
# Due to a bug in the libevent build system, the required
# iphlpapi library is not listed in the libevent.pc file.
# See upstream:
# - https://github.com/libevent/libevent/issues/1110
# - https://github.com/libevent/libevent/pull/1111
# It is not clear which approach is preferable for the upstream
# maintainers: (1) remove iphlpapi dependency or (2) fix
# the libevent.pc file generation.
$<$<PLATFORM_ID:Windows>:iphlpapi>
)

check_evhttp_connection_get_peer(PkgConfig::libevent)
add_library(libevent::libevent ALIAS PkgConfig::libevent)

if(NOT WIN32)
cross_pkg_check_modules(libevent_pthreads
pkg_check_modules(libevent_pthreads
REQUIRED IMPORTED_TARGET GLOBAL
libevent_pthreads>=${libevent_minimum_version}
)
Expand Down
21 changes: 0 additions & 21 deletions cmake/module/CrossPkgConfig.cmake

This file was deleted.

4 changes: 2 additions & 2 deletions cmake/module/FindMiniUPnPc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

if(NOT MSVC)
include(CrossPkgConfig)
cross_pkg_check_modules(PC_MiniUPnPc QUIET miniupnpc)
find_package(PkgConfig REQUIRED)
pkg_check_modules(PC_MiniUPnPc QUIET miniupnpc)
endif()

find_path(MiniUPnPc_INCLUDE_DIR
Expand Down
10 changes: 4 additions & 6 deletions cmake/optional.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,12 @@ if(WITH_ZMQ)
else()
# The ZeroMQ project has provided config files since v4.2.2.
# TODO: Switch to find_package(ZeroMQ) at some point in the future.
include(CrossPkgConfig)
cross_pkg_check_modules(libzmq IMPORTED_TARGET libzmq>=4)
find_package(PkgConfig REQUIRED)
pkg_check_modules(libzmq IMPORTED_TARGET libzmq>=4)
if(libzmq_FOUND AND TARGET PkgConfig::libzmq)
target_compile_definitions(PkgConfig::libzmq INTERFACE
$<$<PLATFORM_ID:Windows>:ZMQ_STATIC>
)
target_link_libraries(PkgConfig::libzmq INTERFACE
$<$<PLATFORM_ID:Windows>:iphlpapi;ws2_32>
)
endif()
endif()
if(TARGET libzmq OR TARGET PkgConfig::libzmq)
Expand Down Expand Up @@ -194,7 +191,8 @@ if(WITH_GUI AND WITH_QRENCODE)
# the build error in its libiconv dependency.
# See: https://github.com/microsoft/vcpkg/issues/36924.
else()
cross_pkg_check_modules(libqrencode libqrencode IMPORTED_TARGET)
find_package(PkgConfig REQUIRED)
pkg_check_modules(libqrencode libqrencode IMPORTED_TARGET)
endif()
if(TARGET PkgConfig::libqrencode)
set_target_properties(PkgConfig::libqrencode PROPERTIES
Expand Down
11 changes: 9 additions & 2 deletions depends/toolchain.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(PKG_CONFIG_PATH "@depends_prefix@/lib/pkgconfig")
set(PKG_CONFIG_LIBDIR "${PKG_CONFIG_PATH}")
set(QT_TRANSLATIONS_DIR "@depends_prefix@/translations")

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT CMAKE_HOST_APPLE)
Expand All @@ -80,6 +78,15 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT CMAKE_HOST_APPLE)
set(CMAKE_FRAMEWORK_PATH "@OSX_SDK@/System/Library/Frameworks")
endif()


# Customize pkg-config behaviour.
cmake_path(APPEND CMAKE_FIND_ROOT_PATH "lib" "pkgconfig" OUTPUT_VARIABLE pkg_config_path)
set(ENV{PKG_CONFIG_PATH} ${pkg_config_path})
set(ENV{PKG_CONFIG_LIBDIR} ${pkg_config_path})
unset(pkg_config_path)
set(PKG_CONFIG_ARGN --static)


# Ensure that the docstrings in the following `set(... CACHE ...)`
# commands match those in the root CMakeLists.txt file.

Expand Down

0 comments on commit e5f2f27

Please sign in to comment.