From d30cbe4591bdc2726f1395f8fb4a853d44b36773 Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Wed, 24 Sep 2014 17:25:38 +0000 Subject: [PATCH] Minimize Releaase Executable Sizes. Use the data-sections and function-sections gcc/g++ compiler options to create sections for each function and data item then use gc-sections in the link to discard all unreferenced sections. This has most benefit if the hamlib library we statically link is also compiled with data-sections and function-sections. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@4351 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- CMakeLists.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 03ba28c73..f078c75e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -395,7 +395,13 @@ endif (APPLE) # C & C++ setup # set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") +set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fdata-sections -ffunction-sections") +set (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -fdata-sections -ffunction-sections") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -std=c++11 -fexceptions -frtti") +set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fdata-sections -ffunction-sections") +set (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -fdata-sections -ffunction-sections") + if (WIN32) set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-keep-inline-dllexport") endif (WIN32) @@ -436,6 +442,13 @@ else (Fortran_COMPILER_NAME MATCHES "gfortran.*") endif (Fortran_COMPILER_NAME MATCHES "gfortran.*") +# +# Linker setup +# +set (CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -Wl,--gc-sections") +set (CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL} -Wl,--gc-sections") + + # # setup and test Fortran C/C++ interaction #