1
0

RunCMakeTest.cmake 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. include(RunCMake)
  2. run_cmake(CMP0070-NEW)
  3. run_cmake(CMP0070-OLD)
  4. run_cmake(CMP0070-WARN)
  5. run_cmake(CommandConflict)
  6. if("${RunCMake_GENERATOR}" MATCHES "Visual Studio|Xcode")
  7. run_cmake(OutputConflict)
  8. endif()
  9. run_cmake(EmptyCondition1)
  10. run_cmake(EmptyCondition2)
  11. run_cmake(BadCondition)
  12. run_cmake(DebugEvaluate)
  13. run_cmake(GenerateSource)
  14. run_cmake(OutputNameMatchesSources)
  15. run_cmake(OutputNameMatchesObjects)
  16. run_cmake(OutputNameMatchesOtherSources)
  17. file(READ "${RunCMake_BINARY_DIR}/OutputNameMatchesOtherSources-build/1somefile.cpp" file_contents)
  18. if (NOT file_contents MATCHES "generated.cpp.rule")
  19. message(SEND_ERROR "Rule file not in target sources! ${file_contents}")
  20. endif()
  21. if (NOT RunCMake_GENERATOR MATCHES "Visual Studio")
  22. run_cmake(COMPILE_LANGUAGE-genex)
  23. foreach(l CXX C)
  24. file(READ "${RunCMake_BINARY_DIR}/COMPILE_LANGUAGE-genex-build/opts-${l}.txt" l_defs)
  25. if (NOT l_defs STREQUAL "LANG_IS_${l}\n")
  26. message(FATAL_ERROR "File content does not match: ${l_defs}")
  27. endif()
  28. endforeach()
  29. endif()
  30. set(timeformat "%Y%j%H%M%S")
  31. file(REMOVE "${RunCMake_BINARY_DIR}/WriteIfDifferent-build/output_file.txt")
  32. set(RunCMake_TEST_OPTIONS "-DTEST_FILE=WriteIfDifferent.cmake")
  33. set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/WriteIfDifferent-build")
  34. run_cmake(WriteIfDifferent-prepare)
  35. unset(RunCMake_TEST_OPTIONS)
  36. unset(RunCMake_TEST_BINARY_DIR)
  37. file(TIMESTAMP "${RunCMake_BINARY_DIR}/WriteIfDifferent-build/output_file.txt" timestamp ${timeformat})
  38. if(NOT timestamp)
  39. message(SEND_ERROR "Could not get timestamp for \"${RunCMake_BINARY_DIR}/WriteIfDifferent-build/output_file.txt\"")
  40. endif()
  41. execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 1)
  42. set(RunCMake_TEST_NO_CLEAN ON)
  43. run_cmake(WriteIfDifferent)
  44. file(TIMESTAMP "${RunCMake_BINARY_DIR}/WriteIfDifferent-build/output_file.txt" timestamp_after ${timeformat})
  45. if(NOT timestamp_after)
  46. message(SEND_ERROR "Could not get timestamp for \"${RunCMake_BINARY_DIR}/WriteIfDifferent-build/output_file.txt\"")
  47. endif()
  48. unset(RunCMake_TEST_NO_CLEAN)
  49. if (NOT timestamp_after STREQUAL timestamp)
  50. message(SEND_ERROR "WriteIfDifferent changed output file.")
  51. endif()
  52. if (UNIX AND EXISTS /bin/sh)
  53. set(RunCMake_TEST_NO_CLEAN ON)
  54. run_cmake(CarryPermissions)
  55. execute_process(
  56. COMMAND "${RunCMake_BINARY_DIR}/CarryPermissions-build/output_script.sh"
  57. OUTPUT_VARIABLE script_output
  58. RESULT_VARIABLE script_result
  59. ERROR_VARIABLE script_error
  60. OUTPUT_STRIP_TRAILING_WHITESPACE
  61. )
  62. if (script_result)
  63. message(SEND_ERROR "Generated script did not execute correctly: [${script_result}]\n${script_output}\n====\n${script_error}")
  64. endif()
  65. if (NOT script_output STREQUAL SUCCESS)
  66. message(SEND_ERROR "Generated script did not execute correctly:\n${script_output}\n====\n${script_error}")
  67. endif()
  68. endif()
  69. if (RunCMake_GENERATOR MATCHES Makefiles)
  70. file(MAKE_DIRECTORY "${RunCMake_BINARY_DIR}/ReRunCMake-build/")
  71. file(WRITE "${RunCMake_BINARY_DIR}/ReRunCMake-build/input_file.txt" "InitialContent\n")
  72. set(RunCMake_TEST_NO_CLEAN ON)
  73. run_cmake(ReRunCMake)
  74. unset(RunCMake_TEST_NO_CLEAN)
  75. file(TIMESTAMP "${RunCMake_BINARY_DIR}/ReRunCMake-build/output_file.txt" timestamp ${timeformat})
  76. if(NOT timestamp)
  77. message(SEND_ERROR "Could not get timestamp for \"${RunCMake_BINARY_DIR}/ReRunCMake-build/output_file.txt\"")
  78. endif()
  79. execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 1)
  80. file(WRITE "${RunCMake_BINARY_DIR}/ReRunCMake-build/input_file.txt" "ChangedContent\n")
  81. execute_process(COMMAND ${CMAKE_COMMAND} --build "${RunCMake_BINARY_DIR}/ReRunCMake-build/")
  82. file(READ "${RunCMake_BINARY_DIR}/ReRunCMake-build/output_file.txt" out_content)
  83. if(NOT out_content STREQUAL "ChangedContent\n")
  84. message(SEND_ERROR "File did not change: \"${RunCMake_BINARY_DIR}/ReRunCMake-build/output_file.txt\"")
  85. endif()
  86. file(REMOVE "${RunCMake_BINARY_DIR}/ReRunCMake-build/output_file.txt")
  87. execute_process(COMMAND ${CMAKE_COMMAND} --build "${RunCMake_BINARY_DIR}/ReRunCMake-build/")
  88. if (NOT EXISTS "${RunCMake_BINARY_DIR}/ReRunCMake-build/output_file.txt")
  89. message(SEND_ERROR "File did not re-generate: \"${RunCMake_BINARY_DIR}/ReRunCMake-build/output_file.txt\"")
  90. endif()
  91. endif()