summaryrefslogtreecommitdiffstats
path: root/Tests/Module/CheckIPOSupported-Fortran/CMakeLists.txt
blob: 3017898e24950791c98152e2de3fc8c00b6d925f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
cmake_minimum_required(VERSION 3.10)
project(CheckIPOSupported-Fortran LANGUAGES Fortran)

cmake_policy(SET CMP0069 NEW)

if(CMAKE_Fortran_COMPILER_ID STREQUAL "LFortran")
  if(CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL "0.55")
    set(_LFORTRAN_SC_FLAG --separate-compilation)
  else()
    set(_LFORTRAN_SC_FLAG --generate-object-code)
  endif()
  add_compile_options(--implicit-interface ${_LFORTRAN_SC_FLAG})
endif()

include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_output)
if(ipo_supported)
  set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
elseif(CMake_TEST_IPO_WORKS_Fortran)
  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.f)
add_executable(CheckIPOSupported-Fortran main.f)
target_link_libraries(CheckIPOSupported-Fortran PUBLIC foo)

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