PushCheckStateTest.cmake.in 2.23 KB
Newer Older
1
cmake_minimum_required(VERSION 3.8)
2 3
include(CMakePushCheckState)

4
set(CMAKE_EXTRA_INCLUDE_FILES file1)
5
set(CMAKE_REQUIRED_INCLUDES dir1)
6
set(CMAKE_REQUIRED_DEFINITIONS defs1 )
7 8 9
set(CMAKE_REQUIRED_LIBRARIES lib1)
set(CMAKE_REQUIRED_FLAGS flag1)
set(CMAKE_REQUIRED_QUIET 1)
10 11 12

cmake_push_check_state()

13
set(CMAKE_EXTRA_INCLUDE_FILES file2)
14
set(CMAKE_REQUIRED_INCLUDES dir2)
15
set(CMAKE_REQUIRED_DEFINITIONS defs2)
16 17 18
set(CMAKE_REQUIRED_LIBRARIES lib2)
set(CMAKE_REQUIRED_FLAGS flag2)
set(CMAKE_REQUIRED_QUIET 2)
19 20 21

cmake_push_check_state()

22
set(CMAKE_EXTRA_INCLUDE_FILES file3)
23
set(CMAKE_REQUIRED_DEFINITIONS defs3)
24 25 26 27 28
set(CMAKE_REQUIRED_INCLUDES dir3)
set(CMAKE_REQUIRED_DEFINITIONS defs3)
set(CMAKE_REQUIRED_LIBRARIES lib3)
set(CMAKE_REQUIRED_FLAGS flag3)
set(CMAKE_REQUIRED_QUIET 3)
29

30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
cmake_push_check_state(RESET)

foreach(pair IN ITEMS
  EXTRA_INCLUDE_FILES|
  REQUIRED_INCLUDES|
  REQUIRED_DEFINITIONS|
  REQUIRED_LIBRARIES|
  REQUIRED_FLAGS|
  REQUIRED_QUIET|
  )
  string(REPLACE "|" ";" pair "${pair}")
  list(GET pair 0 var)
  list(GET pair 1 expected)
  if (NOT "${CMAKE_${var}}" STREQUAL "${expected}")
    set(fatal TRUE)
    message("ERROR: CMAKE_${var} is \"${CMAKE_${var}}\" (expected \"${expected}\")" )
  endif()
endforeach()

cmake_pop_check_state()

51 52
cmake_pop_check_state()

53
foreach(pair IN ITEMS
54
  EXTRA_INCLUDE_FILES|file2
55 56 57 58 59 60 61 62 63 64 65 66 67 68
  REQUIRED_INCLUDES|dir2
  REQUIRED_DEFINITIONS|defs2
  REQUIRED_LIBRARIES|lib2
  REQUIRED_FLAGS|flag2
  REQUIRED_QUIET|2
  )
  string(REPLACE "|" ";" pair "${pair}")
  list(GET pair 0 var)
  list(GET pair 1 expected)
  if (NOT "${CMAKE_${var}}" STREQUAL "${expected}")
    set(fatal TRUE)
    message("ERROR: CMAKE_${var} is \"${CMAKE_${var}}\" (expected \"${expected}\")" )
  endif()
endforeach()
69 70 71

cmake_pop_check_state()

72
foreach(pair IN ITEMS
73
  EXTRA_INCLUDE_FILES|file1
74 75 76 77 78 79 80 81 82 83 84 85 86 87
  REQUIRED_INCLUDES|dir1
  REQUIRED_DEFINITIONS|defs1
  REQUIRED_LIBRARIES|lib1
  REQUIRED_FLAGS|flag1
  REQUIRED_QUIET|1
  )
  string(REPLACE "|" ";" pair "${pair}")
  list(GET pair 0 var)
  list(GET pair 1 expected)
  if (NOT "${CMAKE_${var}}" STREQUAL "${expected}")
    set(fatal TRUE)
    message("ERROR: CMAKE_${var} is \"${CMAKE_${var}}\" (expected \"${expected}\")" )
  endif()
endforeach()
88 89 90 91

if(fatal)
  message(FATAL_ERROR "cmake_push_check_state() test failed")
endif()