mirror of
https://github.com/monero-project/monero-gui.git
synced 2026-12-04 00:38:09 +00:00
f9fa89b linux: use screenshot portal for Wayland QR scanning (Waozi)
ACKs: jpk68, selsta
408 lines
14 KiB
CMake
408 lines
14 KiB
CMake
cmake_minimum_required(VERSION 3.22)
|
|
project(monero-gui)
|
|
|
|
include(CMakeDependentOption)
|
|
|
|
message(STATUS "Initiating compile using CMake ${CMAKE_VERSION}")
|
|
|
|
set(VERSION_MAJOR "18")
|
|
set(VERSION_MINOR "5")
|
|
set(VERSION_REVISION "4")
|
|
set(VERSION "0.${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION}")
|
|
|
|
option(STATIC "Link libraries statically, requires static Qt")
|
|
|
|
option(USE_DEVICE_TREZOR "Trezor support compilation" ON)
|
|
option(WITH_SCANNER "Enable webcam QR scanner" OFF)
|
|
option(WITH_DESKTOP_ENTRY "Ask to install desktop entry on first startup" ON)
|
|
option(WITH_UPDATER "Regularly check for new updates" ON)
|
|
option(DEV_MODE "Checkout latest monero master on build" OFF)
|
|
cmake_dependent_option(QML_TESTS "Build QML tests" OFF "NOT STATIC;NOT ANDROID;NOT IOS" OFF)
|
|
option(SKIP_OPTIONAL_MONERO_BINARIES "Don't build optional monero binaries" ON)
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_SOURCE_DIR}/cmake")
|
|
include(CheckCCompilerFlag)
|
|
include(CheckCXXCompilerFlag)
|
|
include(CheckLinkerFlag)
|
|
|
|
set(BUILD_GUI_DEPS ON)
|
|
set(BUILD_64 ON CACHE BOOL "Build 64-bit binaries")
|
|
|
|
if(NOT MANUAL_SUBMODULES)
|
|
find_package(Git)
|
|
if(GIT_FOUND)
|
|
if(NOT DEV_MODE)
|
|
function (check_submodule relative_path)
|
|
execute_process(COMMAND git rev-parse "HEAD" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${relative_path} OUTPUT_VARIABLE localHead)
|
|
execute_process(COMMAND git rev-parse "HEAD:${relative_path}" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE checkedHead)
|
|
string(COMPARE EQUAL "${localHead}" "${checkedHead}" upToDate)
|
|
if (upToDate)
|
|
message(STATUS "Submodule '${relative_path}' is up-to-date")
|
|
else()
|
|
message(FATAL_ERROR "Submodule '${relative_path}' is not using the checked head. Please update all submodules with\ngit submodule update --init --force --recursive\nor run cmake with -DMANUAL_SUBMODULES=1,\n or if you want to build from latest master run cmake with -DDEV_MODE=ON,\n or run make devmode")
|
|
endif()
|
|
endfunction ()
|
|
message(STATUS "Checking submodules")
|
|
check_submodule(monero)
|
|
else()
|
|
execute_process(COMMAND ${GIT_EXECUTABLE} fetch WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/monero RESULT_VARIABLE GIT_FETCH_RESULT)
|
|
execute_process(COMMAND ${GIT_EXECUTABLE} checkout -f origin/master WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/monero RESULT_VARIABLE GIT_CHECKOUT_MASTER_RESULT)
|
|
execute_process(COMMAND ${GIT_EXECUTABLE} submodule sync --recursive WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/monero RESULT_VARIABLE GIT_SUBMODULE_SYNC_RESULT)
|
|
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --force --recursive WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/monero RESULT_VARIABLE GIT_SUBMODULE_UPDATE_RESULT)
|
|
if(NOT GIT_FETCH_RESULT EQUAL "0" OR NOT GIT_CHECKOUT_MASTER_RESULT EQUAL "0" OR NOT GIT_SUBMODULE_SYNC_RESULT EQUAL "0" OR NOT GIT_SUBMODULE_UPDATE_RESULT EQUAL "0")
|
|
message(FATAL_ERROR "Updating git submodule to master (-DDEV_MODE=ON) failed")
|
|
endif()
|
|
endif()
|
|
endif()
|
|
endif()
|
|
|
|
add_subdirectory(monero)
|
|
|
|
if(SKIP_OPTIONAL_MONERO_BINARIES)
|
|
foreach(_optional_monero_target
|
|
simplewallet
|
|
gen_multisig
|
|
gen_ssl_cert
|
|
wallet_rpc_server
|
|
blockchain_import
|
|
blockchain_export
|
|
blockchain_blackball
|
|
blockchain_usage
|
|
blockchain_ancestry
|
|
blockchain_depth
|
|
blockchain_stats
|
|
blockchain_prune_known_spent_data
|
|
blockchain_prune)
|
|
if(TARGET ${_optional_monero_target})
|
|
# Directory exclusion also skips install rules for unbuilt binaries.
|
|
get_target_property(_optional_monero_source_dir ${_optional_monero_target} SOURCE_DIR)
|
|
set_property(DIRECTORY "${_optional_monero_source_dir}" PROPERTY EXCLUDE_FROM_ALL TRUE)
|
|
endif()
|
|
endforeach()
|
|
endif()
|
|
|
|
add_subdirectory(external)
|
|
|
|
set(CMAKE_AUTOMOC ON)
|
|
set(CMAKE_AUTORCC ON)
|
|
set(CMAKE_AUTOUIC ON)
|
|
|
|
get_directory_property(ARCH_WIDTH DIRECTORY "monero" DEFINITION ARCH_WIDTH)
|
|
get_directory_property(Boost_VERSION_STRING DIRECTORY "monero" DEFINITION Boost_VERSION_STRING)
|
|
|
|
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
add_definitions(-DQT_NO_DEBUG)
|
|
endif()
|
|
|
|
if(STATIC)
|
|
message(STATUS "Initiating static build")
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
|
add_definitions(-DMONERO_GUI_STATIC)
|
|
endif()
|
|
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
include_directories(${EASYLOGGING_INCLUDE})
|
|
link_directories(${EASYLOGGING_LIBRARY_DIRS})
|
|
|
|
include(VersionGui)
|
|
|
|
message(STATUS "${CMAKE_MODULE_PATH}")
|
|
|
|
if(WITH_SCANNER)
|
|
add_definitions(-DWITH_SCANNER)
|
|
endif()
|
|
|
|
if(WITH_DESKTOP_ENTRY)
|
|
add_definitions(-DWITH_DESKTOP_ENTRY)
|
|
endif()
|
|
|
|
if(WITH_UPDATER)
|
|
add_definitions(-DWITH_UPDATER)
|
|
endif()
|
|
|
|
# Sodium
|
|
find_library(SODIUM_LIBRARY sodium)
|
|
message(STATUS "libsodium: libraries at ${SODIUM_LIBRARY}")
|
|
|
|
if(UNIX AND NOT APPLE AND NOT ANDROID)
|
|
set(CMAKE_SKIP_RPATH ON)
|
|
if(STATIC)
|
|
find_library(XCB_LIBRARY xcb)
|
|
message(STATUS "Found xcb library: ${XCB_LIBRARY}")
|
|
endif()
|
|
endif()
|
|
|
|
if(UNIX)
|
|
if(NOT CMAKE_PREFIX_PATH AND DEFINED ENV{CMAKE_PREFIX_PATH})
|
|
message(STATUS "Using CMAKE_PREFIX_PATH environment variable: '$ENV{CMAKE_PREFIX_PATH}'")
|
|
set(CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
|
|
endif()
|
|
if(APPLE AND NOT CMAKE_PREFIX_PATH)
|
|
execute_process(COMMAND brew --prefix qt OUTPUT_VARIABLE QT6_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
list(APPEND CMAKE_PREFIX_PATH ${QT6_DIR})
|
|
endif()
|
|
endif()
|
|
|
|
set(QT_MIN_VERSION "6.8")
|
|
|
|
set(QT_COMPONENTS
|
|
Core
|
|
Concurrent
|
|
Gui
|
|
Qml
|
|
QmlModels
|
|
Quick
|
|
QuickControls2
|
|
Svg
|
|
Widgets
|
|
Xml
|
|
)
|
|
if(UNIX AND NOT APPLE AND NOT ANDROID)
|
|
list(APPEND QT_COMPONENTS DBus)
|
|
endif()
|
|
if(QML_TESTS)
|
|
list(APPEND QT_COMPONENTS QuickTest Test)
|
|
endif()
|
|
if(WITH_SCANNER)
|
|
list(APPEND QT_COMPONENTS Multimedia)
|
|
endif()
|
|
find_package(Qt6 ${QT_MIN_VERSION} REQUIRED COMPONENTS ${QT_COMPONENTS})
|
|
|
|
list(TRANSFORM QT_COMPONENTS PREPEND "Qt6::" OUTPUT_VARIABLE QT_LIBRARIES)
|
|
|
|
# Optional. Lets the "System" theme setting read the desktop colour-scheme preference
|
|
# from xdg-desktop-portal on desktops where Qt's platform theme does not report one.
|
|
if(UNIX AND NOT APPLE AND NOT ANDROID)
|
|
find_package(Qt6 ${QT_MIN_VERSION} QUIET OPTIONAL_COMPONENTS DBus)
|
|
if(TARGET Qt6::DBus)
|
|
message(STATUS "Found Qt6DBus, system colour-scheme detection will use xdg-desktop-portal")
|
|
list(APPEND QT_LIBRARIES Qt6::DBus)
|
|
add_definitions(-DHAVE_QT_DBUS)
|
|
else()
|
|
message(STATUS "Qt6DBus not found, system colour-scheme detection will use QStyleHints and the palette")
|
|
endif()
|
|
endif()
|
|
|
|
get_target_property(QMAKE_IMPORTED_LOCATION Qt6::qmake IMPORTED_LOCATION)
|
|
get_filename_component(QT_INSTALL_PREFIX "${QMAKE_IMPORTED_LOCATION}/../.." ABSOLUTE)
|
|
|
|
if(APPLE AND NOT STATIC)
|
|
set(CMAKE_BUILD_RPATH "${QT_INSTALL_PREFIX}/lib")
|
|
endif()
|
|
|
|
if(MINGW)
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wa,-mbig-obj")
|
|
# QtCore uses the Windows version-information APIs, but Qt 6.8 does not
|
|
# propagate version.lib to consumers.
|
|
set(EXTRA_LIBRARIES mswsock ws2_32 iphlpapi crypt32 bcrypt -lversion)
|
|
if(DEPENDS)
|
|
set(ICU_LIBRARIES icuio icui18n icuuc icudata icutu iconv)
|
|
else()
|
|
set(ICU_LIBRARIES icuio icuin icuuc icudt icutu iconv)
|
|
endif()
|
|
elseif(APPLE)
|
|
set(EXTRA_LIBRARIES "-framework AppKit")
|
|
elseif(OPENBSD OR ANDROID)
|
|
set(EXTRA_LIBRARIES "")
|
|
elseif(FREEBSD)
|
|
set(EXTRA_LIBRARIES execinfo)
|
|
elseif(DRAGONFLY)
|
|
find_library(COMPAT compat)
|
|
set(EXTRA_LIBRARIES execinfo ${COMPAT})
|
|
elseif(CMAKE_SYSTEM_NAME MATCHES "(SunOS|Solaris)")
|
|
set(EXTRA_LIBRARIES socket nsl resolv)
|
|
elseif(NOT MSVC AND NOT DEPENDS)
|
|
find_library(RT rt)
|
|
set(EXTRA_LIBRARIES ${RT})
|
|
endif()
|
|
|
|
list(APPEND EXTRA_LIBRARIES ${CMAKE_DL_LIBS})
|
|
|
|
if(APPLE)
|
|
cmake_policy(SET CMP0042 NEW)
|
|
endif()
|
|
|
|
if (APPLE AND NOT IOS)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default")
|
|
endif()
|
|
|
|
if(APPLE)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default -DGTEST_HAS_TR1_TUPLE=0")
|
|
endif()
|
|
|
|
# warnings
|
|
add_c_flag_if_supported(-Wformat C_SECURITY_FLAGS)
|
|
add_cxx_flag_if_supported(-Wformat CXX_SECURITY_FLAGS)
|
|
add_c_flag_if_supported(-Wformat-security C_SECURITY_FLAGS)
|
|
add_cxx_flag_if_supported(-Wformat-security CXX_SECURITY_FLAGS)
|
|
|
|
# -fstack-protector
|
|
if (NOT OPENBSD AND NOT (WIN32 AND (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 9.1)))
|
|
add_c_flag_if_supported(-fstack-protector C_SECURITY_FLAGS)
|
|
add_cxx_flag_if_supported(-fstack-protector CXX_SECURITY_FLAGS)
|
|
add_c_flag_if_supported(-fstack-protector-strong C_SECURITY_FLAGS)
|
|
add_cxx_flag_if_supported(-fstack-protector-strong CXX_SECURITY_FLAGS)
|
|
endif()
|
|
|
|
# New in GCC 8.2
|
|
if (NOT OPENBSD AND NOT (WIN32 AND (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 9.1)))
|
|
add_c_flag_if_supported(-fcf-protection=full C_SECURITY_FLAGS)
|
|
add_cxx_flag_if_supported(-fcf-protection=full CXX_SECURITY_FLAGS)
|
|
endif()
|
|
if (NOT WIN32 AND NOT OPENBSD AND NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
|
add_c_flag_if_supported(-fstack-clash-protection C_SECURITY_FLAGS)
|
|
add_cxx_flag_if_supported(-fstack-clash-protection CXX_SECURITY_FLAGS)
|
|
endif()
|
|
|
|
# Removed in GCC 9.1 (or before ?), but still accepted, so spams the output
|
|
if (NOT (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 9.1))
|
|
add_c_flag_if_supported(-mmitigate-rop C_SECURITY_FLAGS)
|
|
add_cxx_flag_if_supported(-mmitigate-rop CXX_SECURITY_FLAGS)
|
|
endif()
|
|
|
|
# linker
|
|
if (APPLE)
|
|
add_linker_flag_if_supported(-Wl,-bind_at_load LD_SECURITY_FLAGS)
|
|
add_linker_flag_if_supported(-Wl,-dead_strip LD_SECURITY_FLAGS)
|
|
add_linker_flag_if_supported(-Wl,-dead_strip_dylibs LD_SECURITY_FLAGS)
|
|
endif()
|
|
if (NOT APPLE AND NOT (WIN32 AND CMAKE_C_COMPILER_ID STREQUAL "GNU"))
|
|
# Windows binaries die on startup with PIE when compiled with GCC
|
|
add_linker_flag_if_supported(-pie LD_SECURITY_FLAGS)
|
|
endif()
|
|
add_linker_flag_if_supported(-Wl,-z,relro LD_SECURITY_FLAGS)
|
|
add_linker_flag_if_supported(-Wl,-z,now LD_SECURITY_FLAGS)
|
|
add_linker_flag_if_supported(-Wl,-z,noexecstack noexecstack_SUPPORTED)
|
|
if (noexecstack_SUPPORTED)
|
|
set(LD_SECURITY_FLAGS "${LD_SECURITY_FLAGS} -Wl,-z,noexecstack")
|
|
endif()
|
|
add_linker_flag_if_supported(-Wl,-z,noexecheap noexecheap_SUPPORTED)
|
|
if (noexecheap_SUPPORTED)
|
|
set(LD_SECURITY_FLAGS "${LD_SECURITY_FLAGS} -Wl,-z,noexecheap")
|
|
endif()
|
|
|
|
# some windows linker bits
|
|
if (WIN32)
|
|
add_linker_flag_if_supported(-Wl,--dynamicbase LD_SECURITY_FLAGS)
|
|
add_linker_flag_if_supported(-Wl,--nxcompat LD_SECURITY_FLAGS)
|
|
add_linker_flag_if_supported(-Wl,--high-entropy-va LD_SECURITY_FLAGS)
|
|
endif()
|
|
|
|
if(STATIC)
|
|
add_linker_flag_if_supported(-static-libgcc STATIC_FLAGS)
|
|
add_linker_flag_if_supported(-static-libstdc++ STATIC_FLAGS)
|
|
if(MINGW)
|
|
add_linker_flag_if_supported(-static STATIC_FLAGS)
|
|
endif()
|
|
endif()
|
|
|
|
# With GCC 6.1.1 the compiled binary malfunctions due to aliasing. Until that
|
|
# is fixed in the code (Issue #847), force compiler to be conservative.
|
|
add_c_flag_if_supported(-fno-strict-aliasing C_SECURITY_FLAGS)
|
|
add_cxx_flag_if_supported(-fno-strict-aliasing CXX_SECURITY_FLAGS)
|
|
|
|
add_c_flag_if_supported(-fPIC C_SECURITY_FLAGS)
|
|
add_cxx_flag_if_supported(-fPIC CXX_SECURITY_FLAGS)
|
|
|
|
message(STATUS "Using C security hardening flags: ${C_SECURITY_FLAGS}")
|
|
message(STATUS "Using C++ security hardening flags: ${CXX_SECURITY_FLAGS}")
|
|
message(STATUS "Using linker security hardening flags: ${LD_SECURITY_FLAGS}")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 ${C_SECURITY_FLAGS}")
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_SECURITY_FLAGS}")
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LD_SECURITY_FLAGS} ${STATIC_FLAGS}")
|
|
|
|
add_subdirectory(translations)
|
|
|
|
set(EXECUTABLE_FLAG)
|
|
if(MINGW)
|
|
set(EXECUTABLE_FLAG WIN32)
|
|
set(ICON "${PROJECT_SOURCE_DIR}/images/appicon.ico")
|
|
set(ICON_RC "${CMAKE_CURRENT_BINARY_DIR}/icon.rc")
|
|
set(ICON_RES "${CMAKE_CURRENT_BINARY_DIR}/icon.o")
|
|
file(WRITE "${ICON_RC}" "IDI_ICON1 ICON DISCARDABLE \"${ICON}\"")
|
|
find_program(WINDRES_EXECUTABLE
|
|
NAMES windres x86_64-w64-mingw32-windres
|
|
REQUIRED
|
|
CMAKE_FIND_ROOT_PATH_BOTH
|
|
)
|
|
add_custom_command(
|
|
OUTPUT "${ICON_RES}"
|
|
COMMAND "${WINDRES_EXECUTABLE}" "${ICON_RC}" "${ICON_RES}"
|
|
MAIN_DEPENDENCY "${ICON_RC}"
|
|
)
|
|
endif()
|
|
|
|
if(APPLE)
|
|
set(MACOSX_BUNDLE_MINIMUM_SYSTEM_VERSION "12.0") # Qt 6.8 requirement
|
|
if(CMAKE_OSX_DEPLOYMENT_TARGET)
|
|
set(MACOSX_BUNDLE_MINIMUM_SYSTEM_VERSION "${CMAKE_OSX_DEPLOYMENT_TARGET}")
|
|
endif()
|
|
|
|
set(ICON "${PROJECT_SOURCE_DIR}/images/appicon.icns")
|
|
set_source_files_properties("${ICON}" PROPERTIES
|
|
MACOSX_PACKAGE_LOCATION "Resources"
|
|
)
|
|
endif()
|
|
|
|
if(NOT ANDROID)
|
|
add_executable(monero-wallet-gui ${EXECUTABLE_FLAG} ${ICON} ${ICON_RES})
|
|
else()
|
|
set(QT_ANDROID_MIN_SDK_VERSION 28 CACHE STRING "Minimum Android API level")
|
|
set(QT_ANDROID_TARGET_SDK_VERSION 35 CACHE STRING "Target Android API level")
|
|
qt_add_executable(monero-wallet-gui)
|
|
set_target_properties(monero-wallet-gui PROPERTIES
|
|
QT_ANDROID_MIN_SDK_VERSION "${QT_ANDROID_MIN_SDK_VERSION}"
|
|
QT_ANDROID_TARGET_SDK_VERSION "${QT_ANDROID_TARGET_SDK_VERSION}"
|
|
)
|
|
target_compile_definitions(monero-wallet-gui PRIVATE ANDROID)
|
|
endif()
|
|
|
|
add_subdirectory(src)
|
|
|
|
include(src/qml-resources.cmake)
|
|
|
|
qt_policy(SET QTP0004 NEW)
|
|
|
|
set(QML_MODULE_OPTIONS)
|
|
if(MINGW AND NOT CMAKE_GENERATOR MATCHES "Ninja")
|
|
message(STATUS "Disabling QML cache generation: MinGW requires the Ninja generator")
|
|
list(APPEND QML_MODULE_OPTIONS NO_CACHEGEN)
|
|
endif()
|
|
|
|
qt_add_qml_module(monero-wallet-gui
|
|
${QML_MODULE_OPTIONS}
|
|
URI MoneroGUI
|
|
VERSION 1.0
|
|
RESOURCE_PREFIX /
|
|
NO_RESOURCE_TARGET_PATH
|
|
NO_GENERATE_EXTRA_QMLDIRS
|
|
IMPORT_PATH
|
|
"${CMAKE_SOURCE_DIR}/fonts"
|
|
QML_FILES
|
|
${GUI_QML_FILES}
|
|
RESOURCES
|
|
${GUI_ASSET_FILES}
|
|
)
|
|
|
|
if(STATIC)
|
|
qt_import_qml_plugins(monero-wallet-gui)
|
|
endif()
|
|
|
|
if(APPLE AND WITH_SCANNER)
|
|
qt_import_plugins(monero-wallet-gui INCLUDE Qt6::QDarwinCameraPermissionPlugin)
|
|
target_link_options(monero-wallet-gui PRIVATE "-Wl,-u,_QDarwinCameraPermissionRequest")
|
|
endif()
|
|
|
|
add_custom_command(TARGET monero-wallet-gui POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
$<TARGET_FILE:daemon>
|
|
$<TARGET_FILE_DIR:monero-wallet-gui>
|
|
)
|
|
|
|
install(TARGETS monero-wallet-gui DESTINATION bin)
|