CMakeLists.txt 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. cmake_minimum_required(VERSION 3.10)
  2. project(RerunMocBasic)
  3. include("../AutogenCoreTest.cmake")
  4. # Dummy executable to generate a clean target
  5. add_executable(dummy dummy.cpp)
  6. set(timeformat "%Y%j%H%M%S")
  7. set(mocBasicSrcDir "${CMAKE_CURRENT_SOURCE_DIR}/MocBasic")
  8. set(mocBasicBinDir "${CMAKE_CURRENT_BINARY_DIR}/MocBasic")
  9. # Initial build
  10. configure_file("${mocBasicSrcDir}/test1a.h.in" "${mocBasicBinDir}/test1.h" COPYONLY)
  11. try_compile(MOC_RERUN
  12. "${mocBasicBinDir}"
  13. "${mocBasicSrcDir}"
  14. MocBasic
  15. CMAKE_FLAGS "-DQT_TEST_VERSION=${QT_TEST_VERSION}"
  16. "-DCMAKE_AUTOGEN_VERBOSE=${CMAKE_AUTOGEN_VERBOSE}"
  17. "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
  18. OUTPUT_VARIABLE output
  19. )
  20. if (NOT MOC_RERUN)
  21. message(SEND_ERROR "Initial build of mocBasic failed. Output: ${output}")
  22. endif()
  23. # Get name of the output binary
  24. file(STRINGS "${mocBasicBinDir}/mocBasic.txt" mocBasicList ENCODING UTF-8)
  25. list(GET mocBasicList 0 mocBasicBin)
  26. message("Changing the header content for a MOC rerun")
  27. # - Acquire binary timestamps before the build
  28. file(TIMESTAMP "${mocBasicBin}" timeBefore "${timeformat}")
  29. # - Ensure that the timestamp will change
  30. # - Change header file content and rebuild
  31. # - Rebuild
  32. execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
  33. configure_file("${mocBasicSrcDir}/test1b.h.in" "${mocBasicBinDir}/test1.h" COPYONLY)
  34. execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocBasicBinDir}" RESULT_VARIABLE result )
  35. if (result)
  36. message(SEND_ERROR "Second build of mocBasic failed.")
  37. endif()
  38. # - Acquire binary timestamps after the build
  39. file(TIMESTAMP "${mocBasicBin}" timeAfter "${timeformat}")
  40. # - Test if timestamps changed
  41. if (NOT timeAfter GREATER timeBefore)
  42. message(SEND_ERROR "File (${mocBasicBin}) should have changed!")
  43. endif()
  44. message("Changing nothing for a MOC rerun")
  45. # - Acquire binary timestamps before the build
  46. file(TIMESTAMP "${mocBasicBin}" timeBefore "${timeformat}")
  47. # - Ensure that the timestamp would change
  48. # - Change nothing
  49. # - Rebuild
  50. execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
  51. execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocBasicBinDir}" RESULT_VARIABLE result )
  52. if (result)
  53. message(SEND_ERROR "Third build of mocBasic failed.")
  54. endif()
  55. # - Acquire binary timestamps after the build
  56. file(TIMESTAMP "${mocBasicBin}" timeAfter "${timeformat}")
  57. # - Test if timestamps changed
  58. if (timeAfter GREATER timeBefore)
  59. message(SEND_ERROR "File (${mocBasicBin}) should not have changed!")
  60. endif()