From ccbc16f3a9aaf9d0739e8267cca6c527a5cb6e60 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Fri, 15 Mar 2019 18:54:08 +0300 Subject: [PATCH] cmake: clean unreferenced functions from OpenCV modules too --- cmake/OpenCVCompilerOptions.cmake | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake index 4b9eb90837..67d9d028e3 100644 --- a/cmake/OpenCVCompilerOptions.cmake +++ b/cmake/OpenCVCompilerOptions.cmake @@ -179,12 +179,24 @@ if(CV_GCC OR CV_CLANG) string(REPLACE "-ffunction-sections" "" ${flags} "${${flags}}") string(REPLACE "-fdata-sections" "" ${flags} "${${flags}}") endforeach() - elseif(NOT ((IOS OR ANDROID) AND NOT BUILD_SHARED_LIBS) AND NOT MSVC) - # Remove unreferenced functions: function level linking - add_extra_compiler_option(-ffunction-sections) - add_extra_compiler_option(-fdata-sections) - if(NOT APPLE AND NOT OPENCV_SKIP_GC_SECTIONS) - set(OPENCV_EXTRA_EXE_LINKER_FLAGS "${OPENCV_EXTRA_EXE_LINKER_FLAGS} -Wl,--gc-sections") + else() + if(MSVC) + # TODO: Clang/C2 is not supported + elseif(((IOS OR ANDROID) AND NOT BUILD_SHARED_LIBS) AND NOT OPENCV_FORCE_FUNCTIONS_SECTIONS) + # don't create separate sections for functions/data, reduce package size + else() + # Remove unreferenced functions: function level linking + add_extra_compiler_option(-ffunction-sections) + add_extra_compiler_option(-fdata-sections) + if(NOT OPENCV_SKIP_GC_SECTIONS) + if(APPLE) + set(OPENCV_EXTRA_EXE_LINKER_FLAGS "${OPENCV_EXTRA_EXE_LINKER_FLAGS} -Wl,-dead_strip") + set(OPENCV_EXTRA_SHARED_LINKER_FLAGS "${OPENCV_EXTRA_SHARED_LINKER_FLAGS} -Wl,-dead_strip") + else() + set(OPENCV_EXTRA_EXE_LINKER_FLAGS "${OPENCV_EXTRA_EXE_LINKER_FLAGS} -Wl,--gc-sections") + set(OPENCV_EXTRA_SHARED_LINKER_FLAGS "${OPENCV_EXTRA_SHARED_LINKER_FLAGS} -Wl,--gc-sections") + endif() + endif() endif() endif()