RunCMakeTest.cmake 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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_IS_MULTI_CONFIG)
  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. run_cmake(COMPILE_LANGUAGE-genex)
  22. foreach(l CXX C)
  23. file(READ "${RunCMake_BINARY_DIR}/COMPILE_LANGUAGE-genex-build/opts-${l}.txt" l_defs)
  24. if (NOT l_defs STREQUAL "LANG_IS_${l}\n")
  25. message(FATAL_ERROR "File content does not match: ${l_defs}")
  26. endif()
  27. endforeach()
  28. set(timeformat "%Y%j%H%M%S")
  29. file(REMOVE "${RunCMake_BINARY_DIR}/WriteIfDifferent-build/output_file.txt")
  30. set(RunCMake_TEST_OPTIONS "-DTEST_FILE=WriteIfDifferent.cmake")
  31. set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/WriteIfDifferent-build")
  32. run_cmake(WriteIfDifferent-prepare)
  33. unset(RunCMake_TEST_OPTIONS)
  34. unset(RunCMake_TEST_BINARY_DIR)
  35. file(TIMESTAMP "${RunCMake_BINARY_DIR}/WriteIfDifferent-build/output_file.txt" timestamp ${timeformat})
  36. if(NOT timestamp)
  37. message(SEND_ERROR "Could not get timestamp for \"${RunCMake_BINARY_DIR}/WriteIfDifferent-build/output_file.txt\"")
  38. endif()
  39. execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 1)
  40. set(RunCMake_TEST_NO_CLEAN ON)
  41. run_cmake(WriteIfDifferent)
  42. file(TIMESTAMP "${RunCMake_BINARY_DIR}/WriteIfDifferent-build/output_file.txt" timestamp_after ${timeformat})
  43. if(NOT timestamp_after)
  44. message(SEND_ERROR "Could not get timestamp for \"${RunCMake_BINARY_DIR}/WriteIfDifferent-build/output_file.txt\"")
  45. endif()
  46. unset(RunCMake_TEST_NO_CLEAN)
  47. if (NOT timestamp_after STREQUAL timestamp)
  48. message(SEND_ERROR "WriteIfDifferent changed output file.")
  49. endif()
  50. if (UNIX AND EXISTS /bin/sh)
  51. set(RunCMake_TEST_NO_CLEAN ON)
  52. run_cmake(CarryPermissions)
  53. execute_process(
  54. COMMAND "${RunCMake_BINARY_DIR}/CarryPermissions-build/output_script.sh"
  55. OUTPUT_VARIABLE script_output
  56. RESULT_VARIABLE script_result
  57. ERROR_VARIABLE script_error
  58. OUTPUT_STRIP_TRAILING_WHITESPACE
  59. )
  60. if (script_result)
  61. message(SEND_ERROR "Generated script did not execute correctly: [${script_result}]\n${script_output}\n====\n${script_error}")
  62. endif()
  63. if (NOT script_output STREQUAL SUCCESS)
  64. message(SEND_ERROR "Generated script did not execute correctly:\n${script_output}\n====\n${script_error}")
  65. endif()
  66. endif()
  67. if (RunCMake_GENERATOR MATCHES Makefiles)
  68. file(MAKE_DIRECTORY "${RunCMake_BINARY_DIR}/ReRunCMake-build/")
  69. file(WRITE "${RunCMake_BINARY_DIR}/ReRunCMake-build/input_file.txt" "InitialContent\n")
  70. set(RunCMake_TEST_NO_CLEAN ON)
  71. run_cmake(ReRunCMake)
  72. unset(RunCMake_TEST_NO_CLEAN)
  73. file(TIMESTAMP "${RunCMake_BINARY_DIR}/ReRunCMake-build/output_file.txt" timestamp ${timeformat})
  74. if(NOT timestamp)
  75. message(SEND_ERROR "Could not get timestamp for \"${RunCMake_BINARY_DIR}/ReRunCMake-build/output_file.txt\"")
  76. endif()
  77. execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 1)
  78. file(WRITE "${RunCMake_BINARY_DIR}/ReRunCMake-build/input_file.txt" "ChangedContent\n")
  79. execute_process(COMMAND ${CMAKE_COMMAND} --build "${RunCMake_BINARY_DIR}/ReRunCMake-build/")
  80. file(READ "${RunCMake_BINARY_DIR}/ReRunCMake-build/output_file.txt" out_content)
  81. if(NOT out_content STREQUAL "ChangedContent\n")
  82. message(SEND_ERROR "File did not change: \"${RunCMake_BINARY_DIR}/ReRunCMake-build/output_file.txt\"")
  83. endif()
  84. file(REMOVE "${RunCMake_BINARY_DIR}/ReRunCMake-build/output_file.txt")
  85. execute_process(COMMAND ${CMAKE_COMMAND} --build "${RunCMake_BINARY_DIR}/ReRunCMake-build/")
  86. if (NOT EXISTS "${RunCMake_BINARY_DIR}/ReRunCMake-build/output_file.txt")
  87. message(SEND_ERROR "File did not re-generate: \"${RunCMake_BINARY_DIR}/ReRunCMake-build/output_file.txt\"")
  88. endif()
  89. endif()