From 32257877e0a6ce4561896f5ba009b08de4d93ad8 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Fri, 30 Sep 2022 03:27:54 +0400 Subject: [PATCH] Move more compiler options to DESKTOP_APP_SPECIAL_TARGET condition --- options_linux.cmake | 57 ++++++++++++++++++++++----------------------- options_mac.cmake | 25 ++++++++++---------- variables.cmake | 4 ++++ 3 files changed, 44 insertions(+), 42 deletions(-) diff --git a/options_linux.cmake b/options_linux.cmake index a9de719..c266a5a 100644 --- a/options_linux.cmake +++ b/options_linux.cmake @@ -6,28 +6,11 @@ target_compile_options_if_exists(common_options INTERFACE - -fstack-protector-all - -fstack-clash-protection - -fPIC - $,,-fno-strict-aliasing> - -pipe - -Wall - -Wextra - -Wno-unused-parameter - -Wno-switch - -Wno-maybe-uninitialized - -Wno-missing-field-initializers - -Wno-sign-compare + $<$>:-fno-strict-aliasing> -Wno-deprecated # implicit capture of 'this' via '[=]' is deprecated in C++20 -Wno-deprecated-declarations # TODO: Remove when there will be no Qt 5 support ) -target_compile_definitions(common_options -INTERFACE - $,,_FORTIFY_SOURCE=2> - _GLIBCXX_ASSERTIONS -) - target_link_options_if_exists(common_options INTERFACE -pthread @@ -35,19 +18,39 @@ INTERFACE ) if (DESKTOP_APP_SPECIAL_TARGET) - target_compile_options(common_options + target_compile_options_if_exists(common_options INTERFACE - $,,-Ofast> + $<$>:-Ofast> + $<$>:-g> + $<$>:-flto> + -fstack-protector-all + -fstack-clash-protection + -pipe + -Wall -Werror + -Wextra + -Wno-unused-parameter + -Wno-switch + -Wno-maybe-uninitialized + -Wno-missing-field-initializers + -Wno-sign-compare + ) + target_compile_definitions(common_options + INTERFACE + $<$>:_FORTIFY_SOURCE=2> + _GLIBCXX_ASSERTIONS ) - target_link_options(common_options INTERFACE - $,,-Ofast> + $<$>:-Ofast> + $<$>:-g> + $<$>:-flto> + $<$>:-fuse-linker-plugin> + $<$>:-fwhole-program> + -Wl,-z,relro + -Wl,-z,now + # -pie # https://gitlab.gnome.org/GNOME/nautilus/-/issues/1601 ) - - target_compile_options(common_options INTERFACE $,,-g -flto>) - target_link_options(common_options INTERFACE $,,-g -flto -fuse-linker-plugin>) endif() if (NOT DESKTOP_APP_USE_PACKAGED) @@ -71,10 +74,6 @@ if (NOT DESKTOP_APP_USE_PACKAGED) target_link_options(common_options INTERFACE -rdynamic - -fwhole-program - -Wl,-z,relro - -Wl,-z,now - # -pie # https://gitlab.gnome.org/GNOME/nautilus/-/issues/1601 ) endif() diff --git a/options_mac.cmake b/options_mac.cmake index 8da4ab4..3235878 100644 --- a/options_mac.cmake +++ b/options_mac.cmake @@ -20,30 +20,29 @@ endif() target_compile_options(common_options INTERFACE - -pipe - -Wall - -Wextra - -fPIE $<$:-fobjc-weak> -fvisibility-inlines-hidden -fvisibility=hidden -Wno-deprecated-declarations # temp for range-v3 - -Wno-unused-variable - -Wno-unused-parameter - -Wno-unused-function - -Wno-switch - -Wno-comment - -Wno-missing-field-initializers - -Wno-sign-compare - -Wno-unknown-attributes - -Wno-pragma-system-header-outside-header ) if (DESKTOP_APP_SPECIAL_TARGET) target_compile_options(common_options INTERFACE + -pipe -g + -Wall -Werror + -Wextra + -Wno-unused-variable + -Wno-unused-parameter + -Wno-unused-function + -Wno-switch + -Wno-comment + -Wno-missing-field-initializers + -Wno-sign-compare + -Wno-unknown-attributes + -Wno-pragma-system-header-outside-header ) endif() diff --git a/variables.cmake b/variables.cmake index 2740fec..3d317f4 100644 --- a/variables.cmake +++ b/variables.cmake @@ -34,6 +34,10 @@ cmake_dependent_option(DESKTOP_APP_USE_ENCHANT "Use Enchant instead of bundled H cmake_dependent_option(DESKTOP_APP_NO_PDB "Disable PDB file generation." OFF WIN32 OFF) cmake_dependent_option(DESKTOP_APP_DISABLE_JEMALLOC "Disable jemalloc, use system malloc." OFF LINUX OFF) +if (NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) +endif() + if (APPLE) if (DESKTOP_APP_USE_PACKAGED AND DEFINED CMAKE_OSX_ARCHITECTURES) set(DESKTOP_APP_MAC_ARCH "${CMAKE_OSX_ARCHITECTURES}" CACHE STRING "Target macOS arch.")