From 793aff38910216dc3c6b60df86268710a054b770 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 2 Apr 2022 12:42:04 -0700 Subject: [PATCH] Use -fno-c++-static-destructors Static destructors cause the destructor for a global object to run when the program exits. They are bad because: 1. Registering them takes time and memory at startup 2. Running them takes time at shutdown and also they may have weird interactions. This shaves about 12k off of the binary size. Unfortunately gcc does not support this flag. --- cmake/ConfigureChecks.cmake | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake index 291da3ee2..bc190de05 100644 --- a/cmake/ConfigureChecks.cmake +++ b/cmake/ConfigureChecks.cmake @@ -31,6 +31,13 @@ if (HAS_REDUNDANT_MOVE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wredundant-move") endif() +# Disable static destructors if we can. +check_cxx_compiler_flag("-fno-c++-static-destructors" DISABLE_STATIC_DESTRUCTORS) +if (DISABLE_STATIC_DESTRUCTORS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-c++-static-destructors") +endif() + + # Try using CMake's own logic to locate curses/ncurses find_package(Curses) if(NOT ${CURSES_FOUND})