Skip to content

Commit

Permalink
Make LTO optional in CMake
Browse files Browse the repository at this point in the history
Currently, there is a verbose warning if LTO is not supported by
the compiler. This change makes LTO optional, such that users
can prevent the warning. The default behavior (enabled) is
preserved.
  • Loading branch information
tobodner authored and marcomagdy committed Jan 31, 2020
1 parent 80bfd5d commit c93cfe6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ project(aws-lambda-runtime
VERSION 0.2.6
LANGUAGES CXX)

option(ENABLE_LTO "Enables link-time optimization, requires compiler support." ON)
option(ENABLE_TESTS "Enables building the test project, requires AWS C++ SDK." OFF)

include(CheckIPOSupported)

add_library(${PROJECT_NAME}
"src/logging.cpp"
"src/runtime.cpp"
Expand All @@ -23,11 +22,14 @@ target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

check_ipo_supported(RESULT has_lto OUTPUT lto_check_output)
if(has_lto)
set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(WARNING "Link-time optimization (LTO) is not supported: ${lto_check_output}")
if (ENABLE_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT has_lto OUTPUT lto_check_output)
if(has_lto)
set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(WARNING "Link-time optimization (LTO) is not supported: ${lto_check_output}")
endif()
endif()

find_package(CURL REQUIRED)
Expand Down

0 comments on commit c93cfe6

Please sign in to comment.