CMP0066.cmake 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. enable_language(C)
  2. set(CMAKE_C_FLAGS_RELEASE "-DPP_ERROR ${CMAKE_C_FLAGS_DEBUG}")
  3. set(CMAKE_TRY_COMPILE_CONFIGURATION Release)
  4. #-----------------------------------------------------------------------------
  5. message("before try_compile with CMP0066 WARN-default")
  6. try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
  7. ${CMAKE_CURRENT_SOURCE_DIR}/src.c
  8. OUTPUT_VARIABLE out
  9. )
  10. string(REPLACE "\n" "\n " out " ${out}")
  11. if(NOT RESULT)
  12. message(FATAL_ERROR "try_compile with CMP0066 WARN-default failed but should have passed:\n${out}")
  13. else()
  14. message(STATUS "try_compile with CMP0066 WARN-default worked as expected")
  15. endif()
  16. message("after try_compile with CMP0066 WARN-default")
  17. #-----------------------------------------------------------------------------
  18. set(CMAKE_POLICY_WARNING_CMP0066 ON)
  19. try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
  20. ${CMAKE_CURRENT_SOURCE_DIR}/src.c
  21. OUTPUT_VARIABLE out
  22. )
  23. string(REPLACE "\n" "\n " out " ${out}")
  24. if(NOT RESULT)
  25. message(FATAL_ERROR "try_compile with CMP0066 WARN-enabled failed but should have passed:\n${out}")
  26. else()
  27. message(STATUS "try_compile with CMP0066 WARN-enabled worked as expected")
  28. endif()
  29. #-----------------------------------------------------------------------------
  30. cmake_policy(SET CMP0066 OLD)
  31. try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
  32. ${CMAKE_CURRENT_SOURCE_DIR}/src.c
  33. OUTPUT_VARIABLE out
  34. )
  35. string(REPLACE "\n" "\n " out " ${out}")
  36. if(NOT RESULT)
  37. message(FATAL_ERROR "try_compile with CMP0066 OLD failed but should have passed:\n${out}")
  38. else()
  39. message(STATUS "try_compile with CMP0066 OLD worked as expected")
  40. endif()
  41. #-----------------------------------------------------------------------------
  42. cmake_policy(SET CMP0066 NEW)
  43. try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
  44. ${CMAKE_CURRENT_SOURCE_DIR}/src.c
  45. OUTPUT_VARIABLE out
  46. )
  47. string(REPLACE "\n" "\n " out " ${out}")
  48. if(RESULT)
  49. message(FATAL_ERROR "try_compile with CMP0066 NEW passed but should have failed:\n${out}")
  50. elseif(NOT "x${out}" MATCHES "PP_ERROR is defined")
  51. message(FATAL_ERROR "try_compile with CMP0066 NEW did not fail with PP_ERROR:\n${out}")
  52. else()
  53. message(STATUS "try_compile with CMP0066 NEW worked as expected")
  54. endif()