Skip to content

Instantly share code, notes, and snippets.

@headupinclouds
Created February 22, 2017 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save headupinclouds/513891775716e113b362cc3c3a5e9862 to your computer and use it in GitHub Desktop.
Save headupinclouds/513891775716e113b362cc3c3a5e9862 to your computer and use it in GitHub Desktop.
lto.cmake
# Copyright (c) 2014-2017, Ruslan Baratov
# Copyright (c) 2017, David Hirvonen
# All rights reserved.
if(DEFINED POLLY_FLAGS_LTO_CMAKE_)
return()
else()
set(POLLY_FLAGS_LTO_CMAKE_ 1)
endif()
include(polly_add_cache_flag)
string(COMPARE EQUAL "${ANDROID_NDK_VERSION}" "" _not_android)
# TODO: test other platfroms, CMAKE_CXX_FLAGS_INIT should work for all
if(_not_android)
polly_add_cache_flag(CMAKE_CXX_FLAGS "-flto")
polly_add_cache_flag(CMAKE_C_FLAGS "-flto")
else()
polly_add_cache_flag(CMAKE_CXX_FLAGS_INIT "-flto")
polly_add_cache_flag(CMAKE_C_FLAGS_INIT "-flto")
# SECTIONA
polly_add_cache_flag(CMAKE_EXE_LINKER_FLAGS_INIT "-fuse-ld=gold")
polly_add_cache_flag(CMAKE_SHARED_LINKER_FLAGS_INIT "-fuse-ld=gold")
polly_add_cache_flag(CMAKE_EXE_LINKER_FLAGS_INIT "-flto")
polly_add_cache_flag(CMAKE_SHARED_LINKER_FLAGS_INIT "-flto")
# SECTIONB
polly_add_cache_flag(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,-flto")
polly_add_cache_flag(CMAKE_SHARED_LINKER_FLAGS_INIT "-Wl,-flto")
polly_add_cache_flag(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,-fuse-ld=gold")
polly_add_cache_flag(CMAKE_SHARED_LINKER_FLAGS_INIT "-Wl,-fuse-ld=gold")
#polly_add_cache_flag(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,-fuse-linker-plugin")
#polly_add_cache_flag(CMAKE_SHARED_LINKER_FLAGS_INIT "-Wl,-fuse-linker-plugin")
endif()
# There is no macro to detect this flags on toolchain calculation so we must
# mark this toolchain explicitly.
list(APPEND HUNTER_TOOLCHAIN_UNDETECTABLE_ID "lto")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment