summaryrefslogtreecommitdiffstats
path: root/Tests/Module/CheckIPOSupported-CXX/CMakeLists.txt
blob: 1bb2b8496dce7fabe46144b2fe66a612f6ef0756 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
cmake_minimum_required(VERSION 3.8)
project(CheckIPOSupported-CXX LANGUAGES CXX)

cmake_policy(SET CMP0069 NEW)

include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_output)
if(ipo_supported)
  set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
elseif(CMake_TEST_IPO_WORKS_CXX)
  string(REPLACE "\n" "\n  " ipo_output "${ipo_output}")
  message(FATAL_ERROR "IPO expected to work, but the check failed:\n  ${ipo_output}")
endif()

add_library(foo foo.cpp)
add_executable(CheckIPOSupported-CXX main.cpp)
target_link_libraries(CheckIPOSupported-CXX PUBLIC foo)

enable_testing()
add_test(NAME CheckIPOSupported-CXX COMMAND CheckIPOSupported-CXX)