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!")
endif()
#string(TOUPPER ${CMAKE_SYSTEM_NAME} CMAKE_SYSTEM_NAME)
if (CMAKE_SYSTEM_NAME MATCHES "Android")
add_definitions("-flto")
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)
elseif (CMAKE_SYSTEM_NAME MATCHES "Linux")
set(UNIX_OS true)
add_definitions("-O2")
add_definitions("-Wno-invalid-source-encoding")
set(UNIX_OS true)
elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
add_definitions("-O3")
add_definitions("-Wno-invalid-source-encoding")
set(UNIX_OS true)
add_definitions("-Os")
elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
set(UNIX_OS true)
add_definitions("-O2")
set(UNIX_OS true)
elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
set(WIN_OS true)
else()
@ -122,10 +127,6 @@ if (${UNIX_OS})
endif()
endif()
if (!CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
add_definitions("-Wno-invalid-source-encoding")
endif()
if (!CMAKE_BUILD_TYPE STREQUAL "RELEASE")
add_definitions("-g")
endif()
@ -143,9 +144,7 @@ if (ACL_CLIENT_ONLY MATCHES "YES")
endif()
if (CMAKE_SYSTEM_NAME MATCHES "Android")
set(CMAKE_SHARED_LINKER_FLAGS "-shared")
add_definitions("-DACL_CLIENT_ONLY")
add_definitions("-Wno-invalid-source-encoding")
set(CMAKE_SHARED_LINKER_FLAGS "-shared -flto")
set(lib_output_path ${CMAKE_CURRENT_SOURCE_DIR}/../android/lib/${ANDROID_ABI})
set(LIBRARY_OUTPUT_PATH ${lib_output_path})

View File

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

View File

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