diff --git a/CMakeLists.txt b/CMakeLists.txt index 9424387a90c8d..110619e53efff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") add_compile_definitions(MAC_OSX) endif() +if(CMAKE_CROSSCOMPILING AND DEPENDS_ALLOW_HOST_PACKAGES) + list(APPEND CMAKE_FIND_ROOT_PATH "${CMAKE_SYSTEM_PREFIX_PATH}") +endif() + include(AddThreadsIfNeeded) add_threads_if_needed() @@ -127,6 +131,12 @@ message("=================") message("Executables:") message(" bitcoind ............................ ${BUILD_DAEMON}") message("") +if(CMAKE_CROSSCOMPILING) + set(cross_status "TRUE, for ${CMAKE_SYSTEM_NAME}, ${CMAKE_SYSTEM_PROCESSOR}") +else() + set(cross_status "FALSE") +endif() +message("Cross compiling ....................... ${cross_status}") get_directory_property(definitions COMPILE_DEFINITIONS) string(REPLACE ";" " " definitions "${definitions}") message("Preprocessor defined macros ........... ${definitions}") diff --git a/cmake/module/AddLibeventIfNeeded.cmake b/cmake/module/AddLibeventIfNeeded.cmake index 186095700b83a..d6e6ff1397ab7 100644 --- a/cmake/module/AddLibeventIfNeeded.cmake +++ b/cmake/module/AddLibeventIfNeeded.cmake @@ -37,8 +37,8 @@ function(add_libevent_if_needed) return() endif() - find_package(PkgConfig) - pkg_check_modules(libevent REQUIRED libevent>=${libevent_minimum_version} IMPORTED_TARGET GLOBAL) + include(CrossPkgConfig) + cross_pkg_check_modules(libevent REQUIRED libevent>=${libevent_minimum_version} IMPORTED_TARGET GLOBAL) check_evhttp_connection_get_peer(PkgConfig::libevent) target_link_libraries(PkgConfig::libevent INTERFACE $<$:iphlpapi;ws2_32> @@ -46,6 +46,6 @@ function(add_libevent_if_needed) add_library(libevent::libevent ALIAS PkgConfig::libevent) if(NOT WIN32) - pkg_check_modules(libevent_pthreads REQUIRED libevent_pthreads>=${libevent_minimum_version} IMPORTED_TARGET) + cross_pkg_check_modules(libevent_pthreads REQUIRED libevent_pthreads>=${libevent_minimum_version} IMPORTED_TARGET) endif() endfunction() diff --git a/cmake/module/CrossPkgConfig.cmake b/cmake/module/CrossPkgConfig.cmake new file mode 100644 index 0000000000000..4d845a60fe3e3 --- /dev/null +++ b/cmake/module/CrossPkgConfig.cmake @@ -0,0 +1,19 @@ +# Copyright (c) 2023 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +find_package(PkgConfig REQUIRED) + +macro(cross_pkg_check_modules) + if(CMAKE_CROSSCOMPILING) + set(pkg_config_path_saved "$ENV{PKG_CONFIG_PATH}") + set(pkg_config_libdir_saved "$ENV{PKG_CONFIG_LIBDIR}") + set(ENV{PKG_CONFIG_PATH} ${PKG_CONFIG_PATH}) + set(ENV{PKG_CONFIG_LIBDIR} ${PKG_CONFIG_LIBDIR}) + pkg_check_modules(${ARGV}) + set(ENV{PKG_CONFIG_PATH} ${pkg_config_path_saved}) + set(ENV{PKG_CONFIG_LIBDIR} ${pkg_config_libdir_saved}) + else() + pkg_check_modules(${ARGV}) + endif() +endmacro()