diff --git a/cmake/modules/FindQREncode.cmake b/cmake/modules/FindQREncode.cmake new file mode 100644 --- /dev/null +++ b/cmake/modules/FindQREncode.cmake @@ -0,0 +1,31 @@ +# Try to find libqrencode +# QRENCODE_FOUND - system has libqrencode +# QRENCODE_INCLUDE_DIR - the libqrencode include directory +# QRENCODE_LIBRARY - Library needed to use libqrencode + +if (QRENCODE_INCLUDE_DIR AND QRENCODE_LIBRARY) + # Already in cache, be silent + set(QRENCODE_FIND_QUIETLY TRUE) +endif() + +find_path(QRENCODE_INCLUDE_DIR qrencode.h + HINTS $ENV{QRENCODE_INCLUDE_DIR} +) + +find_library(QRENCODE_LIBRARY NAMES qrencode libqrencode + HINTS $ENV{QRENCODE_LIBRARY} +) + +message(STATUS "QREncode lib: " ${QRENCODE_LIBRARY}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + QREncode DEFAULT_MSG + QRENCODE_INCLUDE_DIR + QRENCODE_LIBRARY +) + +mark_as_advanced(QRENCODE_INCLUDE_DIR QRENCODE_LIBRARY) + +set(QREncode_LIBRARIES ${QRENCODE_LIBRARY}) +set(QREncode_INCLUDE_DIRS ${QRENCODE_INCLUDE_DIR}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -17,6 +17,13 @@ option(BUILD_BITCOIN_QT "Build bitcoin-qt" ON) option(ENABLE_HARDENING "Harden the executables" ON) +# ENABLE_QRCODE is a tristate option: +# - AUTO (default): enable if libqrencode is installed, disable otherwise +# - ON: force enable, make libqrencode a requirement +# - OFF: force disable +set(ENABLE_QRCODE AUTO CACHE STRING "Enable QR code display") +set_property(CACHE ENABLE_QRCODE PROPERTY STRINGS AUTO ON OFF) + # Cmake uses the CMAKE_BUILD_TYPE variable to select the build configuration. # By default it supports more configurations that needed for Bitcoin ABC, and # all the releases types set NDEBUG which is unwanted as it disables the assert diff --git a/src/config/CMakeLists.txt b/src/config/CMakeLists.txt --- a/src/config/CMakeLists.txt +++ b/src/config/CMakeLists.txt @@ -154,5 +154,24 @@ # Activate ZeroMQ set(ENABLE_ZMQ ${BUILD_BITCOIN_ZMQ}) +# Try to find libqrencode +find_package(QREncode) + +if(NOT QRENCODE_FOUND) + # If the user explicitly enabled QREncode through -DENABLE_QRCODE=ON, ensure + # the qrencode library is present. + if(ENABLE_QRCODE AND NOT ENABLE_QRCODE STREQUAL "AUTO") + message(FATAL_ERROR + "QR support requested but cannot be built as it requires libqrencode to be installed. Use -DENABLE_QRCODE=OFF" + ) + endif() +else() + if(ENABLE_QRCODE) + # QREncode is enabled, whether implicitly (not set) or explicitly by + # passing -DENABLE_QRCODE=ON on the CMake command line. + set(USE_QRCODE 1 CACHE INTERNAL "QR code is enabled") + endif() +endif() + # Generate the config configure_file(bitcoin-config.h.cmake.in bitcoin-config.h ESCAPE_QUOTES) diff --git a/src/config/bitcoin-config.h.cmake.in b/src/config/bitcoin-config.h.cmake.in --- a/src/config/bitcoin-config.h.cmake.in +++ b/src/config/bitcoin-config.h.cmake.in @@ -61,4 +61,7 @@ #cmakedefine ENABLE_WALLET 1 #cmakedefine ENABLE_ZMQ 1 +/* Define if QR support should be compiled in */ +#cmakedefine USE_QRCODE 1 + #endif // BITCOIN_BITCOIN_CONFIG_H diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -181,6 +181,11 @@ set_property(TARGET bitcoin-qt-base PROPERTY AUTOMOC_MOC_OPTIONS "-DQ_OS_MAC") endif() +if(USE_QRCODE) + target_include_directories(bitcoin-qt-base PUBLIC ${QRENCODE_INCLUDE_DIR}) + target_link_libraries(bitcoin-qt-base ${QRENCODE_LIBRARY}) +endif() + # Wallet if(BUILD_BITCOIN_WALLET) # Automoc option.