optimize libs' size

This commit is contained in:
shuxin   zheng 2019-09-19 09:00:59 +08:00
parent 5a741c439d
commit 09d7897e8a
3 changed files with 33 additions and 32 deletions

View File

@ -9,20 +9,25 @@ if (${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
message(FATAL_ERROR "Please into another dir to build!") message(FATAL_ERROR "Please into another dir to build!")
endif() endif()
#string(TOUPPER ${CMAKE_SYSTEM_NAME} CMAKE_SYSTEM_NAME)
if (CMAKE_SYSTEM_NAME MATCHES "Android") if (CMAKE_SYSTEM_NAME MATCHES "Android")
add_definitions("-flto")
add_definitions("-DANDROID") add_definitions("-DANDROID")
add_definitions("-Os") add_definitions("-DACL_CLIENT_ONLY")
add_definitions("-Wno-invalid-source-encoding")
add_definitions("-Wno-unused-command-line-argument")
string(APPEND CMAKE_C_FLAGS " -Qunused-arguments")
set(UNIX_OS true) set(UNIX_OS true)
elseif (CMAKE_SYSTEM_NAME MATCHES "Linux") elseif (CMAKE_SYSTEM_NAME MATCHES "Linux")
set(UNIX_OS true)
add_definitions("-O2") add_definitions("-O2")
add_definitions("-Wno-invalid-source-encoding")
set(UNIX_OS true)
elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin") elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
add_definitions("-O3")
add_definitions("-Wno-invalid-source-encoding")
set(UNIX_OS true) set(UNIX_OS true)
add_definitions("-Os")
elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD") elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
set(UNIX_OS true)
add_definitions("-O2") add_definitions("-O2")
set(UNIX_OS true)
elseif (CMAKE_SYSTEM_NAME MATCHES "Windows") elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
set(WIN_OS true) set(WIN_OS true)
else() else()
@ -122,10 +127,6 @@ if (${UNIX_OS})
endif() endif()
endif() endif()
if (!CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
add_definitions("-Wno-invalid-source-encoding")
endif()
if (!CMAKE_BUILD_TYPE STREQUAL "RELEASE") if (!CMAKE_BUILD_TYPE STREQUAL "RELEASE")
add_definitions("-g") add_definitions("-g")
endif() endif()
@ -143,9 +144,7 @@ if (ACL_CLIENT_ONLY MATCHES "YES")
endif() endif()
if (CMAKE_SYSTEM_NAME MATCHES "Android") if (CMAKE_SYSTEM_NAME MATCHES "Android")
set(CMAKE_SHARED_LINKER_FLAGS "-shared") set(CMAKE_SHARED_LINKER_FLAGS "-shared -flto")
add_definitions("-DACL_CLIENT_ONLY")
add_definitions("-Wno-invalid-source-encoding")
set(lib_output_path ${CMAKE_CURRENT_SOURCE_DIR}/../android/lib/${ANDROID_ABI}) set(lib_output_path ${CMAKE_CURRENT_SOURCE_DIR}/../android/lib/${ANDROID_ABI})
set(LIBRARY_OUTPUT_PATH ${lib_output_path}) set(LIBRARY_OUTPUT_PATH ${lib_output_path})

View File

@ -8,18 +8,24 @@ endif()
#string(TOUPPER ${CMAKE_SYSTEM_NAME} CMAKE_SYSTEM_NAME) #string(TOUPPER ${CMAKE_SYSTEM_NAME} CMAKE_SYSTEM_NAME)
if(CMAKE_SYSTEM_NAME MATCHES "Android") if(CMAKE_SYSTEM_NAME MATCHES "Android")
add_definitions("-flto")
add_definitions("-DANDROID") add_definitions("-DANDROID")
add_definitions("-Os") add_definitions("-DACL_CLIENT_ONLY")
add_definitions("-Wno-unused-command-line-argument")
add_definitions("-Wno-invalid-source-encoding")
string(APPEND CMAKE_CXX_FLAGS " -Qunused-arguments")
set(UNIX_OS true) set(UNIX_OS true)
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux") elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(UNIX_OS true) add_definitions("-Wno-invalid-source-encoding")
add_definitions("-O2") add_definitions("-O2")
set(UNIX_OS true)
elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
set(UNIX_OS true)
add_definitions("-O2") add_definitions("-O2")
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(UNIX_OS true) set(UNIX_OS true)
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
add_definitions("-Wno-invalid-source-encoding")
add_definitions("-Os") add_definitions("-Os")
set(UNIX_OS true)
elseif (CMAKE_SYSTEM_NAME MATCHES "Windows") elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
set(WIN_OS true) set(WIN_OS true)
else() else()
@ -105,8 +111,7 @@ if (${UNIX_OS})
) )
if (!CMAKE_SYSTEM_NAME MATCHES "FreeBSD") if (!CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
add_definitions("-Wno-invalid-source-encoding" add_definitions("-Wno-unused-private-field"
"-Wno-unused-private-field"
"-Wno-unused-const-variable" "-Wno-unused-const-variable"
) )
endif() endif()
@ -182,14 +187,11 @@ elseif (${WIN_OS})
endif() endif()
if (ACL_CLIENT_ONLY MATCHES "YES") if (ACL_CLIENT_ONLY MATCHES "YES")
add_definitions("-DACL_CLIENT_ONLY")
message(STATUS "acl_cpp: ACL_CLIENT_ONLY been set") message(STATUS "acl_cpp: ACL_CLIENT_ONLY been set")
endif() endif()
if (CMAKE_SYSTEM_NAME MATCHES "Android") if (CMAKE_SYSTEM_NAME MATCHES "Android")
set(CMAKE_SHARED_LINKER_FLAGS "-shared -lz") set(CMAKE_SHARED_LINKER_FLAGS "-shared -lz -flto")
add_definitions("-DACL_CLIENT_ONLY")
add_definitions("-Wno-invalid-source-encoding")
set(lib_output_path ${CMAKE_CURRENT_SOURCE_DIR}/../android/lib/${ANDROID_ABI}) set(lib_output_path ${CMAKE_CURRENT_SOURCE_DIR}/../android/lib/${ANDROID_ABI})
set(LIBRARY_OUTPUT_PATH ${lib_output_path}) set(LIBRARY_OUTPUT_PATH ${lib_output_path})

View File

@ -8,18 +8,23 @@ endif()
#string(TOUPPER ${CMAKE_SYSTEM_NAME} CMAKE_SYSTEM_NAME) #string(TOUPPER ${CMAKE_SYSTEM_NAME} CMAKE_SYSTEM_NAME)
if (CMAKE_SYSTEM_NAME MATCHES "Android") if (CMAKE_SYSTEM_NAME MATCHES "Android")
add_definitions("-flto")
add_definitions("-DANDROID") add_definitions("-DANDROID")
add_definitions("-Os") add_definitions("-Wno-invalid-source-encoding")
add_definitions("-Wno-unused-command-line-argument")
string(APPEND CMAKE_C_FLAGS " -Qunused-arguments")
set(UNIX_OS true) set(UNIX_OS true)
elseif (CMAKE_SYSTEM_NAME MATCHES "Linux") elseif (CMAKE_SYSTEM_NAME MATCHES "Linux")
set(UNIX_OS true) add_definitions("-Wno-invalid-source-encoding")
add_definitions("-O2") add_definitions("-O2")
set(UNIX_OS true)
elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD") elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
set(UNIX_OS true)
add_definitions("-O2") add_definitions("-O2")
elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(UNIX_OS true) set(UNIX_OS true)
elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
add_definitions("-Wno-invalid-source-encoding")
add_definitions("-Os") add_definitions("-Os")
set(UNIX_OS true)
elseif (CMAKE_SYSTEM_NAME MATCHES "Windows") elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
set(WIN_OS true) set(WIN_OS true)
else() else()
@ -72,10 +77,6 @@ if (${UNIX_OS})
"-fvisibility=hidden" "-fvisibility=hidden"
) )
if (!CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
add_definitions("-Wno-invalid-source-encoding")
endif()
# if (CMAKE_BUILD_TYPE STREQUAL "") # if (CMAKE_BUILD_TYPE STREQUAL "")
# set(CMAKE_BUILD_TYPE "DEBUG") # set(CMAKE_BUILD_TYPE "DEBUG")
# else() # else()
@ -95,8 +96,7 @@ elseif (${WIN_OS})
endif() endif()
if (CMAKE_SYSTEM_NAME MATCHES "Android") if (CMAKE_SYSTEM_NAME MATCHES "Android")
set(CMAKE_SHARED_LINKER_FLAGS "-shared") set(CMAKE_SHARED_LINKER_FLAGS "-shared -flto")
add_definitions("-Wno-invalid-source-encoding")
set(lib_output_path ${CMAKE_CURRENT_SOURCE_DIR}/../android/lib/${ANDROID_ABI}) set(lib_output_path ${CMAKE_CURRENT_SOURCE_DIR}/../android/lib/${ANDROID_ABI})
set(LIBRARY_OUTPUT_PATH ${lib_output_path}) set(LIBRARY_OUTPUT_PATH ${lib_output_path})