Skip to content

Commit 45e2f8f

Browse files
committed
Merge bitcoin/bitcoin#31173: cmake: Add FindQRencode module and enable libqrencode package for MSVC
9e5089d build, msvc: Enable `libqrencode` vcpkg package (Hennadii Stepanov) 30089b0 cmake: Add `FindQRencode` module (Hennadii Stepanov) Pull request description: This PR introduces the `FindQRencode` CMake module, following the official CMake [guidelines](https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html#find-modules) for managing [upstream libraries](https://github.com/fukuchi/libqrencode) that lack a config file package. This module enhances flexibility in locating the `libqrencode` library by making the use of `pkg-config` optional. With this update, `libqrencode` can be detected on systems where either `pkg-config` or the `libqrencode.pc` file is unavailable, such as Windows environments using the vcpkg package manager. However, if `libqrencode.pc` is available, it remains beneficial as the only direct source of the library's version information. Additionally, the `libqrencode` vcpkg package is enabled for MSVC builds. Here is a diff for configuration output on Ubuntu 24.10: ```diff -- Detecting CXX compile features - done -- Found SQLite3: /usr/include (found suitable version "3.46.1", minimum required is "3.7.17") -- Found PkgConfig: /usr/bin/pkg-config (found version "1.8.1") --- Checking for module 'libqrencode' --- Found libqrencode, version 4.1.1 +-- Found QRencode: /usr/lib/x86_64-linux-gnu/libqrencode.so (found version "4.1.1") -- Found Qt: /usr/lib/x86_64-linux-gnu/cmake/Qt5 (found suitable version "5.15.15", minimum required is "5.11.3") -- Performing Test CXX_SUPPORTS__WERROR -- Performing Test CXX_SUPPORTS__WERROR - Success ``` ACKs for top commit: fanquake: ACK 9e5089d Tree-SHA512: bb9baca64386772f2f4752b1cbff1230792562ca6b2e37c56ad28580b55b1ae6ff65c2cf0d8ab026111d7b5a056d7ac672496a3cfd1a81e4fdd2b84c8cf75fff
2 parents 80cb630 + 9e5089d commit 45e2f8f

File tree

6 files changed

+78
-11
lines changed

6 files changed

+78
-11
lines changed

CMakeLists.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ cmake_dependent_option(ENABLE_EXTERNAL_SIGNER "Enable external signer support."
135135

136136
cmake_dependent_option(WITH_QRENCODE "Enable QR code support." ON "BUILD_GUI" OFF)
137137
if(WITH_QRENCODE)
138-
find_package(PkgConfig REQUIRED)
139-
pkg_check_modules(libqrencode REQUIRED IMPORTED_TARGET libqrencode)
138+
find_package(QRencode MODULE REQUIRED)
140139
set(USE_QRCODE TRUE)
141140
endif()
142141

CMakePresets.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
"toolchainFile": "$env{VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake",
1616
"cacheVariables": {
1717
"VCPKG_TARGET_TRIPLET": "x64-windows",
18-
"BUILD_GUI": "ON",
19-
"WITH_QRENCODE": "OFF"
18+
"BUILD_GUI": "ON"
2019
}
2120
},
2221
{
@@ -32,8 +31,7 @@
3231
"toolchainFile": "$env{VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake",
3332
"cacheVariables": {
3433
"VCPKG_TARGET_TRIPLET": "x64-windows-static",
35-
"BUILD_GUI": "ON",
36-
"WITH_QRENCODE": "OFF"
34+
"BUILD_GUI": "ON"
3735
}
3836
},
3937
{

cmake/module/FindQRencode.cmake

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Copyright (c) 2024-present The Bitcoin Core developers
2+
# Distributed under the MIT software license, see the accompanying
3+
# file COPYING or https://opensource.org/license/mit/.
4+
5+
#[=======================================================================[
6+
FindQRencode
7+
------------
8+
9+
Finds the QRencode header and library.
10+
11+
This is a wrapper around find_package()/pkg_check_modules() commands that:
12+
- facilitates searching in various build environments
13+
- prints a standard log message
14+
15+
#]=======================================================================]
16+
17+
find_package(PkgConfig QUIET)
18+
if(PKG_CONFIG_FOUND)
19+
pkg_check_modules(PC_QRencode QUIET libqrencode)
20+
endif()
21+
22+
find_path(QRencode_INCLUDE_DIR
23+
NAMES qrencode.h
24+
PATHS ${PC_QRencode_INCLUDE_DIRS}
25+
)
26+
27+
find_library(QRencode_LIBRARY_RELEASE
28+
NAMES qrencode
29+
PATHS ${PC_QRencode_LIBRARY_DIRS}
30+
)
31+
find_library(QRencode_LIBRARY_DEBUG
32+
NAMES qrencoded qrencode
33+
PATHS ${PC_QRencode_LIBRARY_DIRS}
34+
)
35+
include(SelectLibraryConfigurations)
36+
select_library_configurations(QRencode)
37+
38+
include(FindPackageHandleStandardArgs)
39+
find_package_handle_standard_args(QRencode
40+
REQUIRED_VARS QRencode_LIBRARY QRencode_INCLUDE_DIR
41+
VERSION_VAR PC_QRencode_VERSION
42+
)
43+
44+
if(QRencode_FOUND)
45+
if(NOT TARGET QRencode::QRencode)
46+
add_library(QRencode::QRencode UNKNOWN IMPORTED)
47+
endif()
48+
if(QRencode_LIBRARY_RELEASE)
49+
set_property(TARGET QRencode::QRencode APPEND PROPERTY
50+
IMPORTED_CONFIGURATIONS RELEASE
51+
)
52+
set_target_properties(QRencode::QRencode PROPERTIES
53+
IMPORTED_LOCATION_RELEASE "${QRencode_LIBRARY_RELEASE}"
54+
)
55+
endif()
56+
if(QRencode_LIBRARY_DEBUG)
57+
set_property(TARGET QRencode::QRencode APPEND PROPERTY
58+
IMPORTED_CONFIGURATIONS DEBUG
59+
)
60+
set_target_properties(QRencode::QRencode PROPERTIES
61+
IMPORTED_LOCATION_DEBUG "${QRencode_LIBRARY_DEBUG}"
62+
)
63+
endif()
64+
set_target_properties(QRencode::QRencode PROPERTIES
65+
INTERFACE_INCLUDE_DIRECTORIES "${QRencode_INCLUDE_DIR}"
66+
)
67+
endif()
68+
69+
mark_as_advanced(
70+
QRencode_INCLUDE_DIR
71+
)

doc/build-windows-msvc.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ Available presets can be listed as follows:
4242
cmake --list-presets
4343
```
4444

45-
By default, all presets:
46-
- Set `BUILD_GUI` to `ON`.
47-
- Set `WITH_QRENCODE` to `OFF`, due to known build issues when using vcpkg's `libqrencode` package.
45+
By default, all presets set `BUILD_GUI` to `ON`.
4846

4947
## Building
5048

src/qt/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ target_link_libraries(bitcoinqt
133133
bitcoin_cli
134134
leveldb
135135
Boost::headers
136-
$<TARGET_NAME_IF_EXISTS:PkgConfig::libqrencode>
136+
$<TARGET_NAME_IF_EXISTS:QRencode::QRencode>
137137
$<$<PLATFORM_ID:Darwin>:-framework\ AppKit>
138138
$<$<CXX_COMPILER_ID:MSVC>:shlwapi>
139139
)

vcpkg.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"description": "Build GUI, Qt 5",
2626
"dependencies": [
2727
"qt5-base",
28-
"qt5-tools"
28+
"qt5-tools",
29+
"libqrencode"
2930
]
3031
},
3132
"sqlite": {

0 commit comments

Comments
 (0)