INTERPROCEDURAL_OPTIMIZATION using Makefiles under MacOS
In a C++ project on MacOS built using the Unix Makefiles generator, the call to check_ipo_supported seems to build a target foo
. Building that target uses CMAKE_CXX_COMPILER_AR and CMAKE_CXX_COMPILER_RANLIB; these are set to NOTFOUND.
Other than this, building the entire project works fine (so CMake actually finds ar and ranlib or is, at least, able to build static and dynamic libraries and executables).
I use the following code to detect support for interprocedural optimization.
set(_UTIL_IPO_SUPPORTED FALSE)
if(${CMAKE_MAJOR_VERSION} GREATER 2 AND ${CMAKE_MINOR_VERSION} GREATER 8)
cmake_policy(SET CMP0069 NEW)
include(CheckIPOSupported)
check_ipo_supported(RESULT _UTIL_IPO_SUPPORTED OUTPUT _UTIL_IPO_UNSUPPORTED_ERROR LANGUAGES CXX)
if(NOT _UTIL_IPO_SUPPORTED)
message(STATUS "Interprocedural/link-time optimization not supported: ${_UTIL_IPO_UNSUPPORTED_ERROR}")
endif()
endif()
This produces an error message that boils down to the detection script trying to run CMAKE_CXX_COMPILER_AR and CMAKE_CXX_COMPILER_RANLIB, both set to NOTFOUND, resulting in a no-such-command error. Setting CMAKE_CXX_COMPILER_AR and CMAKE_CXX_COMPILER_RANLIB manually by passing -D... to cmake works as intended - IPO detection is successful and the appropriate flags are added to all targets with the corresponding property set.