You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
222 lines
7.9 KiB
222 lines
7.9 KiB
cmake_minimum_required(VERSION 3.13)
|
|
project(moneroservice)
|
|
|
|
message(STATUS "Initiating compile using CMake ${CMAKE_VERSION}")
|
|
|
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
|
set(VERSION_MAJOR "0")
|
|
set(VERSION_MINOR "1")
|
|
set(VERSION_REVISION "0")
|
|
set(VERSION "beta-3")
|
|
|
|
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_SOURCE_DIR}/cmake")
|
|
include(CheckCCompilerFlag)
|
|
include(CheckCXXCompilerFlag)
|
|
include(CheckLinkerFlag)
|
|
include(FetchContent)
|
|
include(FindCcache)
|
|
include(CheckIncludeFile)
|
|
include(CheckSymbolExists)
|
|
|
|
if(DEBUG)
|
|
set(CMAKE_VERBOSE_MAKEFILE ON)
|
|
endif()
|
|
|
|
set(ARCH "x86-64")
|
|
set(BUILD_64 ON)
|
|
set(USE_SINGLE_BUILDDIR ON)
|
|
|
|
check_include_file(sys/prctl.h HAVE_SYS_PRCTL_H)
|
|
check_symbol_exists(prctl "sys/prctl.h" HAVE_PRCTL)
|
|
|
|
function (add_c_flag_if_supported flag var)
|
|
string(REPLACE "-" "_" supported ${flag}_c)
|
|
check_c_compiler_flag(${flag} ${supported})
|
|
if(${${supported}})
|
|
set(${var} "${${var}} ${flag}" PARENT_SCOPE)
|
|
endif()
|
|
endfunction()
|
|
|
|
function (add_cxx_flag_if_supported flag var)
|
|
string(REPLACE "-" "_" supported ${flag}_cxx)
|
|
check_cxx_compiler_flag(${flag} ${supported})
|
|
if(${${supported}})
|
|
set(${var} "${${var}} ${flag}" PARENT_SCOPE)
|
|
endif()
|
|
endfunction()
|
|
|
|
function (add_linker_flag_if_supported flag var)
|
|
string(REPLACE "-" "_" supported ${flag}_ld)
|
|
string(REPLACE "," "_" supported ${flag}_ld)
|
|
check_linker_flag(${flag} ${supported})
|
|
if(${${supported}})
|
|
set(${var} "${${var}} ${flag}" PARENT_SCOPE)
|
|
endif()
|
|
endfunction()
|
|
|
|
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
if(UNIX AND NOT APPLE)
|
|
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
# https://github.com/monero-project/monero-gui/issues/3142#issuecomment-705940446
|
|
set(CMAKE_SKIP_RPATH ON)
|
|
endif()
|
|
|
|
find_package(X11 REQUIRED)
|
|
message(STATUS "X11_FOUND = ${X11_FOUND}")
|
|
message(STATUS "X11_INCLUDE_DIR = ${X11_INCLUDE_DIR}")
|
|
message(STATUS "X11_LIBRARIES = ${X11_LIBRARIES}")
|
|
include_directories(${X11_INCLUDE_DIR})
|
|
link_directories(${X11_LIBRARIES})
|
|
if(STATIC)
|
|
find_library(XCB_LIBRARY xcb)
|
|
message(STATUS "Found xcb library: ${XCB_LIBRARY}")
|
|
endif()
|
|
endif()
|
|
|
|
|
|
if(MINGW)
|
|
string(REGEX MATCH "^[^/]:/[^/]*" msys2_install_path "${CMAKE_C_COMPILER}")
|
|
message(STATUS "MSYS location: ${msys2_install_path}")
|
|
set(CMAKE_INCLUDE_PATH "${msys2_install_path}/mingw${ARCH_WIDTH}/include")
|
|
# This is necessary because otherwise CMake will make Boost libraries -lfoo
|
|
# rather than a full path. Unfortunately, this makes the shared libraries get
|
|
# linked due to a bug in CMake which misses putting -static flags around the
|
|
# -lfoo arguments.
|
|
set(DEFLIB ${msys2_install_path}/mingw${ARCH_WIDTH}/lib)
|
|
list(REMOVE_ITEM CMAKE_C_IMPLICIT_LINK_DIRECTORIES ${DEFLIB})
|
|
list(REMOVE_ITEM CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES ${DEFLIB})
|
|
endif()
|
|
|
|
|
|
if(MINGW)
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wa,-mbig-obj")
|
|
set(EXTRA_LIBRARIES mswsock;ws2_32;iphlpapi;crypt32;bcrypt)
|
|
if(DEPENDS)
|
|
set(ICU_LIBRARIES iconv)
|
|
else()
|
|
set(ICU_LIBRARIES icuio icuin icuuc icudt icutu iconv)
|
|
endif()
|
|
elseif(APPLE)
|
|
set(EXTRA_LIBRARIES "-framework AppKit")
|
|
elseif(OPENBSD)
|
|
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)
|
|
include_directories(SYSTEM /usr/include/malloc)
|
|
if(POLICY CMP0042)
|
|
cmake_policy(SET CMP0042 NEW)
|
|
endif()
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=x86-64 -fvisibility=default -std=c++11")
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default -DGTEST_HAS_TR1_TUPLE=0")
|
|
endif()
|
|
|
|
if (APPLE AND NOT IOS)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=x86-64 -fvisibility=default -std=c++11")
|
|
endif()
|
|
|
|
if(APPLE)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default -DGTEST_HAS_TR1_TUPLE=0")
|
|
endif()
|
|
|
|
# warnings
|
|
# @TODO: enable these 2 for migration to Qt 6
|
|
#add_c_flag_if_supported(-Werror C_SECURITY_FLAGS)
|
|
#add_cxx_flag_if_supported(-Werror CXX_SECURITY_FLAGS)
|
|
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)
|
|
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} -std=c++11 ${CXX_SECURITY_FLAGS}")
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LD_SECURITY_FLAGS} ${STATIC_FLAGS}")
|
|
|
|
add_subdirectory(src)
|