From 39561f8ead36f5f176698a41222445ffa782dce6 Mon Sep 17 00:00:00 2001 From: xiphon Date: Wed, 27 May 2020 00:12:40 +0000 Subject: [PATCH] cmake: workflows: implement 'release' Linux build target + CI --- .github/workflows/build.yml | 19 ++++++++++--- CMakeLists.txt | 25 ++++++++++------- Makefile | 3 ++ cmake/FindCcache.cmake | 56 +++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 10 +++++-- 5 files changed, 97 insertions(+), 16 deletions(-) create mode 100644 cmake/FindCcache.cmake diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5f58f66e..6f0fe67c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,7 @@ jobs: build-macos: runs-on: macOS-latest - + steps: - uses: actions/checkout@v1 - name: update brew and install dependencies @@ -17,11 +17,22 @@ jobs: run: build/release/bin/monero-wallet-gui.app/Contents/MacOS/monero-wallet-gui --test-qml build-ubuntu: - + runs-on: ubuntu-latest - + strategy: + fail-fast: false + matrix: + toolchain: + - name: "qmake" + cmd: "./build.sh" + - name: "cmake" + cmd: "USE_SINGLE_BUILDDIR=ON DEV_MODE=ON make release" + name: build-ubuntu-${{ matrix.toolchain.name }} + steps: - uses: actions/checkout@v1 + with: + submodules: recursive - name: remove bundled boost run: sudo rm -rf /usr/local/share/boost - name: set apt conf @@ -36,7 +47,7 @@ jobs: - name: install monero gui dependencies run: sudo apt -y install qtbase5-dev qt5-default qtdeclarative5-dev qml-module-qtquick-controls qml-module-qtquick-controls2 qml-module-qtquick-dialogs qml-module-qtquick-xmllistmodel qml-module-qt-labs-settings qml-module-qt-labs-folderlistmodel qttools5-dev-tools qml-module-qtquick-templates2 libqt5svg5-dev libgcrypt20-dev xvfb - name: build - run: ./build.sh + run: ${{ matrix.toolchain.cmd }} - name: test qml run: xvfb-run -a build/release/bin/monero-wallet-gui --test-qml diff --git a/CMakeLists.txt b/CMakeLists.txt index dd0e4fcf..5fd37d60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,11 @@ option(WITH_SCANNER "Enable webcam QR scanner" OFF) option(DEV_MODE "Checkout latest monero master on build" OFF) list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_SOURCE_DIR}/cmake") +include(CheckCCompilerFlag) +include(CheckCXXCompilerFlag) +include(CheckLinkerFlag) +include(FindCcache) + set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) @@ -26,7 +31,7 @@ endif() set(BUILD_GUI_DEPS ON) set(ARCH "x86-64") set(BUILD_64 ON) -set(INSTALL_VENDORED_LIBUNBOUND=ON) +set(INSTALL_VENDORED_LIBUNBOUND ${STATIC}) function (add_c_flag_if_supported flag var) string(REPLACE "-" "_" supported ${flag}_c) @@ -74,10 +79,7 @@ if(GIT_FOUND) endif() endif() -set(STATIC_OLD ${STATIC}) -set(STATIC ON CACHE BOOL "Link libraries statically" FORCE) add_subdirectory(monero) -set(STATIC ${STATIC_OLD} CACHE BOOL "Link libraries statically" FORCE) set_property(TARGET wallet_merged PROPERTY FOLDER "monero") get_directory_property(ARCH_WIDTH DIRECTORY "monero" DEFINITION ARCH_WIDTH) @@ -223,17 +225,17 @@ endif() set(QT5_LIBRARIES Qt5Core Qt5Quick - Qt5QuickControls2 Qt5Widgets Qt5Gui Qt5Network Qt5Qml - Qt5Multimedia - Qt5Xml - Qt5XmlPatterns Qt5Svg ) +if(WITH_SCANNER) + list(APPEND QT5_LIBRARIES Qt5Multimedia) +endif() + # TODO: drop this once we switch to Qt 5.14+ find_package(Qt5QmlModels QUIET) if(Qt5QmlModels_FOUND) @@ -399,9 +401,9 @@ if (WIN32) add_linker_flag_if_supported(-Wl,--high-entropy-va LD_SECURITY_FLAGS) endif() -add_linker_flag_if_supported(-static-libgcc STATIC_FLAGS) -add_linker_flag_if_supported(-static-libstdc++ STATIC_FLAGS) 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() @@ -412,6 +414,9 @@ endif() 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}") diff --git a/Makefile b/Makefile index 117b3e7e..f5f2b865 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,9 @@ clean: scanner: mkdir -p build && cd build && cmake -D ARCH="x86-64" -D DEV_MODE=$(or ${DEV_MODE},ON) -D WITH_SCANNER=ON -D BUILD_64=ON -D CMAKE_BUILD_TYPE=Release .. && $(MAKE) +release: + mkdir -p $(builddir)/release && cd $(builddir)/release && cmake -D DEV_MODE=$(or ${DEV_MODE},OFF) -D ARCH="x86-64" -D CMAKE_BUILD_TYPE=Release $(topdir) && $(MAKE) + debug-static-win64: mkdir -p $(builddir)/debug && cd $(builddir)/debug && cmake -D STATIC=ON -G "MSYS Makefiles" -D DEV_MODE=$(or ${DEV_MODE},ON) -D ARCH="x86-64" -D BUILD_64=ON -D CMAKE_BUILD_TYPE=Debug -D BUILD_TAG="win-x64" -D CMAKE_TOOLCHAIN_FILE=$(topdir)/cmake/64-bit-toolchain.cmake -D MSYS2_FOLDER=$(shell cd ${MINGW_PREFIX}/.. && pwd -W) -D MINGW=ON $(topdir) && $(MAKE) diff --git a/cmake/FindCcache.cmake b/cmake/FindCcache.cmake new file mode 100644 index 00000000..29e2d244 --- /dev/null +++ b/cmake/FindCcache.cmake @@ -0,0 +1,56 @@ +# Copyright (c) 2014-2020, The Monero Project +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are +# permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other +# materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be +# used to endorse or promote products derived from this software without specific +# prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# - Try to find readline include dirs and libraries +# +# Automatically finds ccache build accelerator, if it's found in PATH. +# +# Usage of this module as follows: +# +# project(monero) +# include(FindCcache) # Include AFTER the project() macro to be able to reach the CMAKE_CXX_COMPILER variable +# +# Properties modified by this module: +# +# GLOBAL PROPERTY RULE_LAUNCH_COMPILE set to ccache, when ccache found +# GLOBAL PROPERTY RULE_LAUNCH_LINK set to ccache, when ccache found + +find_program(CCACHE_FOUND ccache) +if (CCACHE_FOUND) + set(TEMP_CPP_FILE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/test-program.cpp") + file(WRITE "${TEMP_CPP_FILE}" "int main() { return 0; }") + execute_process(COMMAND "${CCACHE_FOUND}" "${CMAKE_CXX_COMPILER}" "${TEMP_CPP_FILE}" RESULT_VARIABLE RET) + if (${RET} EQUAL 0) + message("found usable ccache: ${CCACHE_FOUND}") + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_FOUND}") + set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE_FOUND}") + else() + message("found ccache ${CCACHE_FOUND}, but is UNUSABLE! Return code: ${RET}") + endif() +else() + message("ccache NOT found!") +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c55aaefd..eb83cb0c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -127,18 +127,24 @@ target_compile_definitions(monero-wallet-gui set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}") if(X11_FOUND) - target_link_libraries(monero-wallet-gui ${X11_LIBRARIES} pthread dl Xt xcb X11) + target_link_libraries(monero-wallet-gui ${X11_LIBRARIES} pthread dl xcb X11) endif() if(DEVICE_TREZOR_READY) target_link_libraries(monero-wallet-gui ${TREZOR_DEP_LIBS}) endif() +if(INSTALL_VENDORED_LIBUNBOUND) + set(UNBOUND_LIBRARY ${CMAKE_BINARY_DIR}/monero/external/unbound/libunbound.a) +else() + set(UNBOUND_LIBRARY unbound) +endif() + target_link_libraries(monero-wallet-gui ${CMAKE_BINARY_DIR}/lib/libwallet_merged.a ${LMDB_LIBRARY} ${CMAKE_BINARY_DIR}/monero/contrib/epee/src/libepee.a - ${CMAKE_BINARY_DIR}/monero/external/unbound/libunbound.a + ${UNBOUND_LIBRARY} ${SODIUM_LIBRARY} ${CMAKE_BINARY_DIR}/monero/external/easylogging++/libeasylogging.a ${CMAKE_BINARY_DIR}/monero/src/blockchain_db/libblockchain_db.a