if(OpenMP_TEST_CASE STREQUAL "Unchanged")
  set(expected_required OpenMP_old_LIBRARY)
else()
  unset(OpenMP_old_LIBRARY CACHE)
  if(OpenMP_TEST_CASE STREQUAL "Empty")
    set(OpenMP_C_LIB_NAMES "")
    set(expected_required "")
  elseif(OpenMP_TEST_CASE STREQUAL "Changed")
    set(OpenMP_C_LIB_NAMES current)
    file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/current.a" "")
    set(OpenMP_current_LIBRARY "${CMAKE_CURRENT_BINARY_DIR}/current.a" CACHE FILEPATH "")
    set(expected_required OpenMP_current_LIBRARY)
  elseif(OpenMP_TEST_CASE STREQUAL "Missing")
    set(OpenMP_C_LIB_NAMES missing)
    set(OpenMP_missing_LIBRARY "OpenMP_missing_LIBRARY-NOTFOUND" CACHE FILEPATH "")
    set(expected_required OpenMP_missing_LIBRARY)
  else()
    message(FATAL_ERROR "Unknown test case: ${OpenMP_TEST_CASE}")
  endif()
endif()

find_package(OpenMP QUIET COMPONENTS C)
if(OpenMP_TEST_CASE STREQUAL "Missing")
  if(OpenMP_FOUND OR OpenMP_C_FOUND)
    message(FATAL_ERROR "OpenMP found despite a missing current library")
  endif()
  if(NOT "OpenMP_missing_LIBRARY" IN_LIST _OPENMP_C_REQUIRED_LIB_VARS)
    message(FATAL_ERROR "Missing current library was not required")
  endif()
  return()
elseif(NOT OpenMP_FOUND OR NOT OpenMP_C_FOUND)
  message(FATAL_ERROR "OpenMP not found with ${OpenMP_TEST_CASE} library list")
endif()
if(NOT "${_OPENMP_C_REQUIRED_LIB_VARS}" STREQUAL "${expected_required}")
  message(FATAL_ERROR "Expected required libraries '${expected_required}', got '${_OPENMP_C_REQUIRED_LIB_VARS}'")
endif()
