Make lto detection more robust and not resetting cxx flags when lto fails.
This refines the last commit of parallelizing lto. Discussion: this is ugly as hell, dispatching 1/ on the availability of the `-flto` flag, then 2/ on the compiler since GCC allows `-flto=n` whereas Clang for example does not. I tried setting the CMake property `INTERPROCEDURAL_OPTIMIZATION`, without any effect. All I could see was some lto related utilities in the cmake debug output, but not in the actual compiler or linker invocation. This would eliminate the need for our hacks, with 1/ using an option `WITH_LTO` setting `ON` by default, and based on this value setting the `INTERPROCEDURAL_OPTIMIZATION` flag with CMake doing the actual work of selecting the best LTO method on the target platform. By the way, this also fixes a bug where we reset the `CMAKE_CXX_FLAGS` to a variable that was never defined, resulting in setting the flags to an empty string. Yay CMake, as usual. References: - http://www.cmake.org/cmake/help/v3.0/prop_tgt/INTERPROCEDURAL_OPTIMIZATION.html
This commit is contained in:
parent
941483c14d
commit
71a00fc01b
@ -124,16 +124,21 @@ endif()
|
|||||||
if(CMAKE_BUILD_TYPE MATCHES Release)
|
if(CMAKE_BUILD_TYPE MATCHES Release)
|
||||||
message(STATUS "Configuring OSRM in release mode")
|
message(STATUS "Configuring OSRM in release mode")
|
||||||
# Check if LTO is available
|
# Check if LTO is available
|
||||||
include(ProcessorCount)
|
check_cxx_compiler_flag("-flto" LTO_AVAILABLE)
|
||||||
ProcessorCount(NPROC)
|
|
||||||
set(LTO_FLAGS "")
|
|
||||||
check_cxx_compiler_flag("-flto=${NPROC}" LTO_AVAILABLE)
|
|
||||||
if(LTO_AVAILABLE)
|
if(LTO_AVAILABLE)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto=${NPROC}")
|
set(OLD_CXX_FLAGS ${CMAKE_CXX_FLAGS})
|
||||||
|
# GCC in addition allows parallelizing LTO
|
||||||
|
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||||
|
include(ProcessorCount)
|
||||||
|
ProcessorCount(NPROC)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto=${NPROC}")
|
||||||
|
else()
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
|
||||||
|
endif()
|
||||||
set(CHECK_LTO_SRC "int main(){return 0;}")
|
set(CHECK_LTO_SRC "int main(){return 0;}")
|
||||||
check_cxx_source_compiles("${CHECK_LTO_SRC}" LTO_WORKS)
|
check_cxx_source_compiles("${CHECK_LTO_SRC}" LTO_WORKS)
|
||||||
if(LTO_WORKS)
|
if(LTO_WORKS)
|
||||||
message(STATUS "LTO working")
|
message(STATUS "LTO working")
|
||||||
else()
|
else()
|
||||||
message(STATUS "LTO broken")
|
message(STATUS "LTO broken")
|
||||||
set(CMAKE_CXX_FLAGS "${OLD_CXX_FLAGS}")
|
set(CMAKE_CXX_FLAGS "${OLD_CXX_FLAGS}")
|
||||||
|
Loading…
Reference in New Issue
Block a user