@@ -31,11 +31,12 @@ option(ENABLE_ASSERTIONS "Use assertions in release mode" OFF)
3131option (ENABLE_DEBUG_LOGGING "Use debug logging in release mode" OFF )
3232option (ENABLE_COVERAGE "Build with coverage instrumentalisation" OFF )
3333option (ENABLE_SANITIZER "Use memory sanitizer for Debug build" OFF )
34- option (ENABLE_LTO "Use LTO if available" OFF )
34+ option (ENABLE_LTO "Use Link Time Optimisation" ON )
3535option (ENABLE_FUZZING "Fuzz testing using LLVM's libFuzzer" OFF )
3636option (ENABLE_NODE_BINDINGS "Build NodeJs bindings" OFF )
3737option (ENABLE_CLANG_TIDY "Enables clang-tidy checks" OFF )
3838
39+
3940if (ENABLE_CLANG_TIDY)
4041 find_program (CLANG_TIDY_COMMAND NAMES clang-tidy)
4142 if (NOT CLANG_TIDY_COMMAND)
@@ -57,6 +58,18 @@ if (POLICY CMP0074)
5758endif ()
5859project (OSRM C CXX)
5960
61+
62+ if (ENABLE_LTO AND (CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES MinRelSize OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo))
63+ include (CheckIPOSupported)
64+ check_ipo_supported(RESULT LTO_SUPPORTED OUTPUT error)
65+ if (LTO_SUPPORTED)
66+ message (STATUS "IPO / LTO enabled" )
67+ set (CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE )
68+ else ()
69+ message (FATAL_ERROR "IPO / LTO not supported: <${error} >" )
70+ endif ()
71+ endif ()
72+
6073# add @loader_path/$ORIGIN to rpath to make binaries relocatable
6174if (APPLE )
6275 set (CMAKE_BUILD_RPATH "@loader_path" )
@@ -208,17 +221,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
208221 set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og -ggdb" )
209222endif ()
210223
211- if (ENABLE_LTO AND (CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES MinRelSize OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo))
212- include (CheckIPOSupported)
213- check_ipo_supported(RESULT LTO_SUPPORTED OUTPUT error)
214- if (LTO_SUPPORTED)
215- message (STATUS "IPO / LTO enabled" )
216- set (CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE )
217- else ()
218- message (WARNING "IPO / LTO not supported: <${error} >" )
219- endif ()
220- endif ()
221-
222224set (MAYBE_COVERAGE_LIBRARIES "" )
223225if (ENABLE_COVERAGE)
224226 if (NOT CMAKE_BUILD_TYPE MATCHES "Debug" )
@@ -290,6 +292,7 @@ include_directories(SYSTEM ${MICROTAR_INCLUDE_DIR})
290292
291293add_library (MICROTAR OBJECT "${CMAKE_CURRENT_SOURCE_DIR} /third_party/microtar/src/microtar.c" )
292294set_property (TARGET MICROTAR PROPERTY POSITION_INDEPENDENT_CODE ON )
295+
293296target_no_warning(MICROTAR unused-variable )
294297target_no_warning(MICROTAR format)
295298
0 commit comments