diff options
author | Derek Schuff <dschuff@chromium.org> | 2021-01-14 13:43:40 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-14 13:43:40 -0800 |
commit | d94982319a6904f81a7f615c6fc9ea4f88f3c820 (patch) | |
tree | 64fe7e106a5408943877f7f8f0ed09f49a8610d2 | |
parent | 01e0c98eb75ed389441ada253bcf02dbc8f1f6ef (diff) | |
download | binaryen-d94982319a6904f81a7f615c6fc9ea4f88f3c820.tar.gz binaryen-d94982319a6904f81a7f615c6fc9ea4f88f3c820.tar.bz2 binaryen-d94982319a6904f81a7f615c6fc9ea4f88f3c820.zip |
Add support for building with thinLTO (#3484)
Supports Clang, on win/mac/linux. Uses lld on Linux and Windows.
I haven't tested yet on Mac, but in theory it should work.
-rw-r--r-- | CMakeLists.txt | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index da9d69ef4..b9120d557 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1.3) +cmake_minimum_required(VERSION 3.13) project(binaryen LANGUAGES C CXX VERSION 99) include(GNUInstallDirs) @@ -68,7 +68,7 @@ endfunction() function(ADD_LINK_FLAG value) message(STATUS "Linking with ${value}") - FOREACH(variable CMAKE_EXE_LINKER_FLAGS) + FOREACH(variable CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) set(${variable} "${${variable}} ${value}" PARENT_SCOPE) ENDFOREACH(variable) endfunction() @@ -135,6 +135,17 @@ FOREACH(SUFFIX "_DEBUG" "_RELEASE" "_RELWITHDEBINFO" "_MINSIZEREL" "") set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY${SUFFIX} "${PROJECT_BINARY_DIR}/lib") ENDFOREACH() +option(BYN_ENABLE_LTO "Build with LTO" Off) +if(BYN_ENABLE_LTO) + if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + message(FATAL_ERROR "ThinLTO is only supported by clang") + endif() + if(NOT APPLE) + add_link_flag("-fuse-ld=lld") + endif() + add_compile_flag("-flto=thin") +endif() + if(MSVC) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "19.0") # VS2013 and older explicitly need /arch:sse2 set, VS2015 no longer has that option, but always enabled. add_compile_flag("/arch:sse2") |