Skip to content

Commit

Permalink
Build: Add LTO/IPO support
Browse files Browse the repository at this point in the history
Enable Link Time Optimization, also known as Interprocedural Optimization
if the compiler supports it.

Added a CMake option (ENABLE_LTO), defaulted to ON only on Windows

Change-Id: Iea02b00aac12cc9a62595eeb8ff52382f1c4ddcd
Reviewed-on: https://code.wireshark.org/review/37573
Reviewed-by: Graham Bloice <graham.bloice@trihedral.com>
Petri-Dish: Graham Bloice <graham.bloice@trihedral.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
  • Loading branch information
Graham Bloice authored and AndersBroman committed Aug 4, 2020
1 parent 458623f commit e6b5bd0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions CMakeLists.txt
Expand Up @@ -13,6 +13,9 @@ if(WIN32)
else()
cmake_minimum_required(VERSION 3.5)
endif()
if(POLICY CMP0069)
cmake_policy(SET CMP0069 NEW)
endif()
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
Expand Down Expand Up @@ -56,6 +59,21 @@ message(STATUS "Generating build using CMake ${CMAKE_VERSION}")
#Where to find local cmake scripts
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)

# CMake >= 3.9.0 enables LTO/IPO
# Policy CMP0069 enables this behavior when we set the minimum CMake version < 3.9.0
if (ENABLE_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT lto_supported)
if(lto_supported)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
endif()
if (CMAKE_INTERPROCEDURAL_OPTIMIZATION)
message(STATUS "LTO/IPO is enabled")
else()
message(STATUS "LTO/LPO is not enabled")
endif()

# If our target platform is enforced by our generator, set
# WIRESHARK_TARGET_PLATFORM accordingly. Otherwise use
# %WIRESHARK_TARGET_PLATFORM%.
Expand Down
6 changes: 6 additions & 0 deletions CMakeOptions.txt
Expand Up @@ -49,6 +49,12 @@ option(ENABLE_FUZZER "Enable libFuzzer instrumentation for use with fuzzshark" O
option(ENABLE_CHECKHF_CONFLICT "Enable hf conflict check for debugging (start-up may be slower)" OFF)
option(ENABLE_CCACHE "Speed up compiling and linking using ccache if possible" OFF)

if (WIN32)
option(ENABLE_LTO "Improves performance using Link time Optimization" ON)
else()
option(ENABLE_LTO "Improves performance using Link time Optimization" OFF)
endif()

option(ENABLE_PCAP "Enable libpcap support (required for capturing)" ON)
#
# AirPcap support is available only on Windows. It might be nice to have it
Expand Down

0 comments on commit e6b5bd0

Please sign in to comment.