CMP0056.cmake 2.4 KB

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