aboutsummaryrefslogtreecommitdiff
path: root/externals/cmake-modules/UseLTO.cmake
blob: b364ef22d828c11837777623d6c8ae150110dfce (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# SPDX-FileCopyrightText: Copyright 2025 crueter
# SPDX-License-Identifier: LGPL-3.0-or-later

## UseLTO ##

# Enable Interprocedural Optimization (IPO).
# Self-explanatory.

option(ENABLE_LTO "Enable Link-Time Optimization (LTO)" OFF)

if (ENABLE_LTO)
    include(CheckIPOSupported)
    check_ipo_supported(RESULT COMPILER_SUPPORTS_LTO)
    if(NOT COMPILER_SUPPORTS_LTO)
        message(FATAL_ERROR
        "Your compiler does not support interprocedural optimization"
        " (IPO). Disable ENABLE_LTO and try again.")
    endif()
    set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
    set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ${COMPILER_SUPPORTS_LTO})
endif()