From 5eabcab3a5ac9ebe9174c6ee545c323e7db11d44 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Wed, 19 Aug 2020 16:49:45 +0300 Subject: [PATCH] Experimenting with LTO. --- CMakeLists.txt | 15 +++++++++++++++ module/CMakeLists.txt | 4 ++++ module/Vendor/AES256/CMakeLists.txt | 4 ++++ module/Vendor/B64/CMakeLists.txt | 4 ++++ module/Vendor/Hash/CMakeLists.txt | 4 ++++ module/Vendor/MaxmindDB/CMakeLists.txt | 4 ++++ module/Vendor/PUGIXML/CMakeLists.txt | 7 ++++++- module/Vendor/SQLite/CMakeLists.txt | 4 ++++ module/Vendor/SimpleIni/CMakeLists.txt | 4 ++++ module/Vendor/SimpleSocket/CMakeLists.txt | 6 +++++- module/Vendor/TinyDir/CMakeLists.txt | 4 ++++ module/Vendor/Whirlpool/CMakeLists.txt | 4 ++++ sdk | 2 +- 13 files changed, 63 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a6688cea..23d416b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) # Several plugin options option(BUILTIN_RUNTIMES "Include the MinGW runtime into the binary itself." ON) +option(LTO_ENABLED "Enable link time optimizations (takes a long time to compile!)." ON) option(FORCE_32BIT_BIN "Create a 32-bit executable binary if the compiler defaults to 64-bit." OFF) option(ENABLE_MYSQL "Enable the MySQL library." OFF) option(ENABLE_API21 "Build for 2.1 API." OFF) @@ -35,6 +36,20 @@ if(GCC OR MINGW) endif() endif() +# Enable LTO +if (NOT LTO_ENABLED) + message("Link time optimizations are disabled") +elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "MINGW") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto") +elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto") + endif() +else() + set(LTO_ENABLED OFF) + message("Link time optimizations not supported") +endif () + # Enable position independent code if(UNIX) set(CMAKE_POSITION_INDEPENDENT_CODE ON) diff --git a/module/CMakeLists.txt b/module/CMakeLists.txt index 819f7f62..c90fbb43 100644 --- a/module/CMakeLists.txt +++ b/module/CMakeLists.txt @@ -81,6 +81,10 @@ if(GCC OR MINGW) endif() # Link to libraries target_link_libraries(SqModule SqModSDK SimpleINI HashLib B64Lib AES256Lib WhirlpoolLib TinyDir PUGIXML SQLite MaxmindDB SimpleSocket) +# Enable LTO +if (LTO_ENABLED) + target_link_libraries(SqModule -flto) +endif() # Link to mysql client library if(ENABLE_MYSQL) # Include the implementation diff --git a/module/Vendor/AES256/CMakeLists.txt b/module/Vendor/AES256/CMakeLists.txt index 77b87da1..eff987f2 100644 --- a/module/Vendor/AES256/CMakeLists.txt +++ b/module/Vendor/AES256/CMakeLists.txt @@ -3,3 +3,7 @@ add_library(AES256Lib STATIC include/aes256.h aes256.cpp) # Configure include folders target_include_directories(AES256Lib PRIVATE ${CMAKE_CURRENT_LIST_DIR}) target_include_directories(AES256Lib PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) +# Enable LTO +if (LTO_ENABLED) + target_link_libraries(AES256Lib PRIVATE -flto) +endif() \ No newline at end of file diff --git a/module/Vendor/B64/CMakeLists.txt b/module/Vendor/B64/CMakeLists.txt index e92919f6..c9b9d84b 100644 --- a/module/Vendor/B64/CMakeLists.txt +++ b/module/Vendor/B64/CMakeLists.txt @@ -3,3 +3,7 @@ add_library(B64Lib STATIC include/b64.h decode.c encode.c) # Configure include folders target_include_directories(B64Lib PRIVATE ${CMAKE_CURRENT_LIST_DIR}) target_include_directories(B64Lib PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) +# Enable LTO +if (LTO_ENABLED) + target_link_libraries(B64Lib PRIVATE -flto) +endif() \ No newline at end of file diff --git a/module/Vendor/Hash/CMakeLists.txt b/module/Vendor/Hash/CMakeLists.txt index 81a855c7..1483f59c 100644 --- a/module/Vendor/Hash/CMakeLists.txt +++ b/module/Vendor/Hash/CMakeLists.txt @@ -17,3 +17,7 @@ target_include_directories(HashLib PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) if (MINGW) target_include_directories(HashLib PRIVATE ${CMAKE_CURRENT_LIST_DIR}/mingwinc) endif(MINGW) +# Enable LTO +if (LTO_ENABLED) + target_link_libraries(HashLib PRIVATE -flto) +endif() \ No newline at end of file diff --git a/module/Vendor/MaxmindDB/CMakeLists.txt b/module/Vendor/MaxmindDB/CMakeLists.txt index c2fa9109..3e309815 100644 --- a/module/Vendor/MaxmindDB/CMakeLists.txt +++ b/module/Vendor/MaxmindDB/CMakeLists.txt @@ -44,3 +44,7 @@ target_include_directories(MaxmindDB PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) if(GCC OR MINGW) target_compile_options(MaxmindDB PRIVATE -Wno-unused -Wno-incompatible-pointer-types) endif() +# Enable LTO +if (LTO_ENABLED) + target_link_libraries(MaxmindDB PRIVATE -flto) +endif() \ No newline at end of file diff --git a/module/Vendor/PUGIXML/CMakeLists.txt b/module/Vendor/PUGIXML/CMakeLists.txt index 9f6c8981..81dd6f1b 100644 --- a/module/Vendor/PUGIXML/CMakeLists.txt +++ b/module/Vendor/PUGIXML/CMakeLists.txt @@ -3,4 +3,9 @@ add_library(PUGIXML STATIC include/pugiconfig.hpp include/pugixml.hpp pugixml.cp # Configure include folders target_include_directories(PUGIXML PRIVATE ${CMAKE_CURRENT_LIST_DIR}) target_include_directories(PUGIXML PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) - +# Configure macro options +target_compile_definitions(PUGIXML PRIVATE PUGIXML_NO_EXCEPTIONS=1) +# Enable LTO +if (LTO_ENABLED) + target_link_libraries(PUGIXML PRIVATE -flto) +endif() \ No newline at end of file diff --git a/module/Vendor/SQLite/CMakeLists.txt b/module/Vendor/SQLite/CMakeLists.txt index 6b239eb8..7cc3fec3 100644 --- a/module/Vendor/SQLite/CMakeLists.txt +++ b/module/Vendor/SQLite/CMakeLists.txt @@ -5,3 +5,7 @@ target_include_directories(SQLite PRIVATE ${CMAKE_CURRENT_LIST_DIR}) target_include_directories(SQLite PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) # Configure macro options target_compile_definitions(SQLite PRIVATE _WIN32_WINNT=0x0601 SQLITE_ENABLE_FTS3=1 SQLITE_ENABLE_FTS4=1 SQLITE_ENABLE_FTS5=1 SQLITE_ENABLE_JSON1=1 SQLITE_ENABLE_RTREE=1 SQLITE_ENABLE_GEOPOLY=1) +# Enable LTO +if (LTO_ENABLED) + target_link_libraries(SQLite PRIVATE -flto) +endif() diff --git a/module/Vendor/SimpleIni/CMakeLists.txt b/module/Vendor/SimpleIni/CMakeLists.txt index 1ea2f850..f9ed24b1 100644 --- a/module/Vendor/SimpleIni/CMakeLists.txt +++ b/module/Vendor/SimpleIni/CMakeLists.txt @@ -7,3 +7,7 @@ add_library(SimpleINI STATIC # Configure include folders target_include_directories(SimpleINI PRIVATE ${CMAKE_CURRENT_LIST_DIR}) target_include_directories(SimpleINI PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) +# Enable LTO +if (LTO_ENABLED) + target_link_libraries(SimpleINI PRIVATE -flto) +endif() \ No newline at end of file diff --git a/module/Vendor/SimpleSocket/CMakeLists.txt b/module/Vendor/SimpleSocket/CMakeLists.txt index 43ad0e9d..d29201cf 100644 --- a/module/Vendor/SimpleSocket/CMakeLists.txt +++ b/module/Vendor/SimpleSocket/CMakeLists.txt @@ -11,7 +11,11 @@ target_include_directories(SimpleSocket PRIVATE ${CMAKE_CURRENT_LIST_DIR}) target_include_directories(SimpleSocket PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) # Configure macro options target_compile_definitions(SimpleSocket PRIVATE _WIN32_WINNT=0x0601) -# OS and compiler checks. +# Enable LTO +if (LTO_ENABLED) + target_link_libraries(SimpleSocket PRIVATE -flto) +endif() +# OS and compiler checks. if(WIN32) target_link_libraries(SimpleSocket PUBLIC Ws2_32) endif() diff --git a/module/Vendor/TinyDir/CMakeLists.txt b/module/Vendor/TinyDir/CMakeLists.txt index 64bd5e64..03f40623 100644 --- a/module/Vendor/TinyDir/CMakeLists.txt +++ b/module/Vendor/TinyDir/CMakeLists.txt @@ -3,3 +3,7 @@ add_library(TinyDir STATIC include/tinydir.h tinydir.c) # Library includes target_include_directories(TinyDir PRIVATE ${CMAKE_CURRENT_LIST_DIR}) target_include_directories(TinyDir PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) +# Enable LTO +if (LTO_ENABLED) + target_link_libraries(TinyDir PRIVATE -flto) +endif() \ No newline at end of file diff --git a/module/Vendor/Whirlpool/CMakeLists.txt b/module/Vendor/Whirlpool/CMakeLists.txt index 72ce76f9..e844dd69 100644 --- a/module/Vendor/Whirlpool/CMakeLists.txt +++ b/module/Vendor/Whirlpool/CMakeLists.txt @@ -9,3 +9,7 @@ add_library(WhirlpoolLib STATIC # Configure include folders target_include_directories(WhirlpoolLib PRIVATE ${CMAKE_CURRENT_LIST_DIR}) target_include_directories(WhirlpoolLib PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) +# Enable LTO +if (LTO_ENABLED) + target_link_libraries(WhirlpoolLib PRIVATE -flto) +endif() diff --git a/sdk b/sdk index 4d187b72..dd04405f 160000 --- a/sdk +++ b/sdk @@ -1 +1 @@ -Subproject commit 4d187b72b35b1ae1557772d25129d7ab6bcbd1aa +Subproject commit dd04405ff22391aeb102d64176e8123c5d0f6cae