1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Experimenting with LTO.

This commit is contained in:
Sandu Liviu Catalin 2020-08-19 16:49:45 +03:00
parent 4e5aa5a292
commit 5eabcab3a5
13 changed files with 63 additions and 3 deletions

View File

@ -6,6 +6,7 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
# Several plugin options # Several plugin options
option(BUILTIN_RUNTIMES "Include the MinGW runtime into the binary itself." ON) 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(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_MYSQL "Enable the MySQL library." OFF)
option(ENABLE_API21 "Build for 2.1 API." OFF) option(ENABLE_API21 "Build for 2.1 API." OFF)
@ -35,6 +36,20 @@ if(GCC OR MINGW)
endif() endif()
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 # Enable position independent code
if(UNIX) if(UNIX)
set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON)

View File

@ -81,6 +81,10 @@ if(GCC OR MINGW)
endif() endif()
# Link to libraries # Link to libraries
target_link_libraries(SqModule SqModSDK SimpleINI HashLib B64Lib AES256Lib WhirlpoolLib TinyDir PUGIXML SQLite MaxmindDB SimpleSocket) 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 # Link to mysql client library
if(ENABLE_MYSQL) if(ENABLE_MYSQL)
# Include the implementation # Include the implementation

View File

@ -3,3 +3,7 @@ add_library(AES256Lib STATIC include/aes256.h aes256.cpp)
# Configure include folders # Configure include folders
target_include_directories(AES256Lib PRIVATE ${CMAKE_CURRENT_LIST_DIR}) target_include_directories(AES256Lib PRIVATE ${CMAKE_CURRENT_LIST_DIR})
target_include_directories(AES256Lib PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) target_include_directories(AES256Lib PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
# Enable LTO
if (LTO_ENABLED)
target_link_libraries(AES256Lib PRIVATE -flto)
endif()

View File

@ -3,3 +3,7 @@ add_library(B64Lib STATIC include/b64.h decode.c encode.c)
# Configure include folders # Configure include folders
target_include_directories(B64Lib PRIVATE ${CMAKE_CURRENT_LIST_DIR}) target_include_directories(B64Lib PRIVATE ${CMAKE_CURRENT_LIST_DIR})
target_include_directories(B64Lib PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) target_include_directories(B64Lib PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
# Enable LTO
if (LTO_ENABLED)
target_link_libraries(B64Lib PRIVATE -flto)
endif()

View File

@ -17,3 +17,7 @@ target_include_directories(HashLib PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
if (MINGW) if (MINGW)
target_include_directories(HashLib PRIVATE ${CMAKE_CURRENT_LIST_DIR}/mingwinc) target_include_directories(HashLib PRIVATE ${CMAKE_CURRENT_LIST_DIR}/mingwinc)
endif(MINGW) endif(MINGW)
# Enable LTO
if (LTO_ENABLED)
target_link_libraries(HashLib PRIVATE -flto)
endif()

View File

@ -44,3 +44,7 @@ target_include_directories(MaxmindDB PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
if(GCC OR MINGW) if(GCC OR MINGW)
target_compile_options(MaxmindDB PRIVATE -Wno-unused -Wno-incompatible-pointer-types) target_compile_options(MaxmindDB PRIVATE -Wno-unused -Wno-incompatible-pointer-types)
endif() endif()
# Enable LTO
if (LTO_ENABLED)
target_link_libraries(MaxmindDB PRIVATE -flto)
endif()

View File

@ -3,4 +3,9 @@ add_library(PUGIXML STATIC include/pugiconfig.hpp include/pugixml.hpp pugixml.cp
# Configure include folders # Configure include folders
target_include_directories(PUGIXML PRIVATE ${CMAKE_CURRENT_LIST_DIR}) target_include_directories(PUGIXML PRIVATE ${CMAKE_CURRENT_LIST_DIR})
target_include_directories(PUGIXML PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) 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()

View File

@ -5,3 +5,7 @@ target_include_directories(SQLite PRIVATE ${CMAKE_CURRENT_LIST_DIR})
target_include_directories(SQLite PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) target_include_directories(SQLite PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
# Configure macro options # 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) 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()

View File

@ -7,3 +7,7 @@ add_library(SimpleINI STATIC
# Configure include folders # Configure include folders
target_include_directories(SimpleINI PRIVATE ${CMAKE_CURRENT_LIST_DIR}) target_include_directories(SimpleINI PRIVATE ${CMAKE_CURRENT_LIST_DIR})
target_include_directories(SimpleINI PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) target_include_directories(SimpleINI PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
# Enable LTO
if (LTO_ENABLED)
target_link_libraries(SimpleINI PRIVATE -flto)
endif()

View File

@ -11,7 +11,11 @@ target_include_directories(SimpleSocket PRIVATE ${CMAKE_CURRENT_LIST_DIR})
target_include_directories(SimpleSocket PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) target_include_directories(SimpleSocket PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
# Configure macro options # Configure macro options
target_compile_definitions(SimpleSocket PRIVATE _WIN32_WINNT=0x0601) 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) if(WIN32)
target_link_libraries(SimpleSocket PUBLIC Ws2_32) target_link_libraries(SimpleSocket PUBLIC Ws2_32)
endif() endif()

View File

@ -3,3 +3,7 @@ add_library(TinyDir STATIC include/tinydir.h tinydir.c)
# Library includes # Library includes
target_include_directories(TinyDir PRIVATE ${CMAKE_CURRENT_LIST_DIR}) target_include_directories(TinyDir PRIVATE ${CMAKE_CURRENT_LIST_DIR})
target_include_directories(TinyDir PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) target_include_directories(TinyDir PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
# Enable LTO
if (LTO_ENABLED)
target_link_libraries(TinyDir PRIVATE -flto)
endif()

View File

@ -9,3 +9,7 @@ add_library(WhirlpoolLib STATIC
# Configure include folders # Configure include folders
target_include_directories(WhirlpoolLib PRIVATE ${CMAKE_CURRENT_LIST_DIR}) target_include_directories(WhirlpoolLib PRIVATE ${CMAKE_CURRENT_LIST_DIR})
target_include_directories(WhirlpoolLib PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) target_include_directories(WhirlpoolLib PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
# Enable LTO
if (LTO_ENABLED)
target_link_libraries(WhirlpoolLib PRIVATE -flto)
endif()

2
sdk

@ -1 +1 @@
Subproject commit 4d187b72b35b1ae1557772d25129d7ab6bcbd1aa Subproject commit dd04405ff22391aeb102d64176e8123c5d0f6cae