CMP0056.cmake 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. enable_language(C)
  2. set(obj "${CMAKE_C_OUTPUT_EXTENSION}")
  3. if(BORLAND)
  4. set(pre -)
  5. endif()
  6. set(CMAKE_EXE_LINKER_FLAGS ${pre}BADFLAG${obj})
  7. #-----------------------------------------------------------------------------
  8. message("before try_compile with CMP0056 WARN-default")
  9. try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
  10. ${CMAKE_CURRENT_SOURCE_DIR}/src.c
  11. OUTPUT_VARIABLE out
  12. )
  13. string(REPLACE "\n" "\n " out " ${out}")
  14. if(NOT RESULT)
  15. message(FATAL_ERROR "try_compile failed but should have passed:\n${out}")
  16. elseif("x${out}" MATCHES "BADFLAG")
  17. message(FATAL_ERROR "try_compile output mentions BADFLAG:\n${out}")
  18. else()
  19. message(STATUS "try_compile with CMP0056 WARN-default worked as expected")
  20. endif()
  21. message("after try_compile with CMP0056 WARN-default")
  22. #-----------------------------------------------------------------------------
  23. set(CMAKE_POLICY_WARNING_CMP0056 ON)
  24. try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
  25. ${CMAKE_CURRENT_SOURCE_DIR}/src.c
  26. OUTPUT_VARIABLE out
  27. )
  28. string(REPLACE "\n" "\n " out " ${out}")
  29. if(NOT RESULT)
  30. message(FATAL_ERROR "try_compile failed but should have passed:\n${out}")
  31. elseif("x${out}" MATCHES "BADFLAG")
  32. message(FATAL_ERROR "try_compile output mentions BADFLAG:\n${out}")
  33. else()
  34. message(STATUS "try_compile with CMP0056 WARN-enabled worked as expected")
  35. endif()
  36. #-----------------------------------------------------------------------------
  37. cmake_policy(SET CMP0056 OLD)
  38. try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
  39. ${CMAKE_CURRENT_SOURCE_DIR}/src.c
  40. OUTPUT_VARIABLE out
  41. )
  42. string(REPLACE "\n" "\n " out " ${out}")
  43. if(NOT RESULT)
  44. message(FATAL_ERROR "try_compile failed but should have passed:\n${out}")
  45. elseif("x${out}" MATCHES "BADFLAG")
  46. message(FATAL_ERROR "try_compile output mentions BADFLAG:\n${out}")
  47. else()
  48. message(STATUS "try_compile with CMP0056 OLD worked as expected")
  49. endif()
  50. #-----------------------------------------------------------------------------
  51. cmake_policy(SET CMP0056 NEW)
  52. try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
  53. ${CMAKE_CURRENT_SOURCE_DIR}/src.c
  54. OUTPUT_VARIABLE out
  55. )
  56. string(REPLACE "\n" "\n " out " ${out}")
  57. if(RESULT)
  58. message(FATAL_ERROR "try_compile passed but should have failed:\n${out}")
  59. elseif(NOT "x${out}" MATCHES "BADFLAG")
  60. message(FATAL_ERROR "try_compile did not fail with BADFLAG:\n${out}")
  61. else()
  62. message(STATUS "try_compile with CMP0056 NEW worked as expected")
  63. endif()