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.
This commit is contained in:
ridiculousfish 2022-04-02 12:42:04 -07:00
parent 448dd18685
commit 793aff3891

View file

@ -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})