Merged PR 2475924: compiler switches to reduce binary size.
trying out a few compiler optimization switches to reduce binary size. (thanks to some tips from https://ptspts.blogspot.com/2013/12/how-to-make-smaller-c-and-c-binaries.html) On MacOs/ios, got gains of ~200K. Not much on android for some reason, could be that the android toolchain is interfering somehow. Related work items: #19337401
This commit is contained in:
Родитель
5913c2712c
Коммит
75b7bdd6ad
|
@ -9,8 +9,9 @@ set( TARGET_INCLUDE_DIRS ${OpenSLL_INCLUDE_PATH} )
|
|||
set( TARGET_INCLUDE_DIRS_PRIVATE "${TARGET_SOURCE_DIR_TRUE}" "${TARGET_SOURCE_DIR_TRUE}/asn1" "${TARGET_SOURCE_DIR_TRUE}/evp" "${TARGET_SOURCE_DIR_TRUE}/modes")
|
||||
set( TARGET_DEFINES "OPENSSL_THREADS" )
|
||||
set( TARGET_DEFINES_PRIVATE "${OpenSSL_COMPILER_DEFINES}" )
|
||||
set( TARGET_COMPILE_FLAGS "" )
|
||||
set( TARGET_COMPILE_FLAGS_PRIVATE "" )
|
||||
set( TARGET_COMPILE_FLAGS -fno-rtti -fno-stack-protector -O1 -fno-unwind-tables -fno-asynchronous-unwind-tables
|
||||
-fno-math-errno -fno-unroll-loops -fmerge-all-constants)
|
||||
set( TARGET_COMPILE_FLAGS_PRIVATE -ffunction-sections -fdata-sections)
|
||||
set( TARGET_LINK "" )
|
||||
set( TARGET_LINK_PRIVATE "" )
|
||||
set( TARGET_SOURCES "" )
|
||||
|
@ -94,9 +95,7 @@ add_library(crypto STATIC ${TARGET_SOURCES})
|
|||
|
||||
target_include_directories( crypto PRIVATE ${TARGET_INCLUDE_DIRS} ${TARGET_INCLUDE_DIRS_PRIVATE} )
|
||||
target_compile_definitions( crypto PRIVATE ${TARGET_DEFINES} ${TARGET_DEFINES_PRIVATE} )
|
||||
target_link_libraries ( crypto PRIVATE ${TARGET_LINK} ${TARGET_LINK_PRIVATE} )
|
||||
target_compile_options ( crypto PRIVATE ${TARGET_COMPILE_FLAGS} ${TARGET_COMPILE_FLAGS_PRIVATE} )
|
||||
target_compile_options ( crypto PRIVATE ${TARGET_COMPILE_FLAGS} ${TARGET_COMPILE_FLAGS_PRIVATE})
|
||||
target_include_directories( crypto PUBLIC ${TARGET_INCLUDE_DIRS} ${OpenSLL_INCLUDE_PATH} ${OpenSLL_INCLUDE_PATH}/openssl)
|
||||
target_compile_definitions( crypto PUBLIC ${TARGET_DEFINES} )
|
||||
target_link_libraries ( crypto PUBLIC ${TARGET_LINK} )
|
||||
target_compile_options ( crypto PUBLIC ${TARGET_COMPILE_FLAGS} )
|
||||
target_compile_options ( crypto PUBLIC ${TARGET_COMPILE_FLAGS})
|
|
@ -239,8 +239,9 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_PROJECT_ROOT}/src/inc
|
|||
|
||||
|
||||
if(WIN32)
|
||||
string(REPLACE "/GR" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
COMPILE_FLAGS "/source-charset:utf-8"
|
||||
COMPILE_FLAGS "/source-charset:utf-8 /Gw /GL /GR-"
|
||||
VS_WINRT_COMPONENT TRUE)
|
||||
# Using /DELAYLOAD as linker option will use a helper funtion provided by
|
||||
# Visual C++ that will load the dll at runtime by calling LoadLibrary and GetProcAddress.
|
||||
|
@ -252,7 +253,7 @@ if(WIN32)
|
|||
"/DELAYLOAD:api-ms-win-core-winrt-string-l1-1-0.dll"
|
||||
"/DELAYLOAD:api-ms-win-core-winrt-l1-1-0.dll")
|
||||
string(REPLACE ";" " " DELAYFLAGS "${DELAYFLAGS}")
|
||||
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS "${DELAYFLAGS}")
|
||||
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS "${DELAYFLAGS} /LTCG")
|
||||
if(USE_STATIC_MSVC)
|
||||
if(CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " /NODEFAULTLIB:MSVCRTD")
|
||||
|
@ -366,5 +367,9 @@ endif()
|
|||
if(OpenSSL_FOUND)
|
||||
# include the libraries needed to use OpenSSL
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${OpenSLL_INCLUDE_PATH})
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE crypto)
|
||||
endif()
|
||||
if((IOS) OR (MACOS))
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE crypto -Wl,-dead_strip)
|
||||
else()
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE crypto -Wl,--gc-sections)
|
||||
endif()
|
||||
endif()
|
Загрузка…
Ссылка в новой задаче