PlatformVariables.cmake 762 B

1234567891011121314151617181920212223
  1. enable_language(C)
  2. # Normally this variable should be set by a platform information module or
  3. # a toolchain file, but for purposes of this test we simply set it here.
  4. set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES MY_CUSTOM_VARIABLE)
  5. set(MY_CUSTOM_VARIABLE SOME_VALUE)
  6. try_compile(result ${CMAKE_CURRENT_BINARY_DIR}
  7. SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.c
  8. OUTPUT_VARIABLE out
  9. )
  10. if(NOT result)
  11. message(FATAL_ERROR "try_compile failed:\n${out}")
  12. endif()
  13. # Check that the cache was populated with our custom variable.
  14. file(STRINGS ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/CMakeCache.txt entries
  15. REGEX MY_CUSTOM_VARIABLE:UNINITIALIZED=${MY_CUSTOM_VARIABLE}
  16. )
  17. if(NOT entries)
  18. message(FATAL_ERROR "try_compile did not populate cache as expected")
  19. endif()