CMakeLists.txt 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. cmake_minimum_required(VERSION 3.10)
  2. project(RerunMocBasic)
  3. include("../AutogenTest.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. "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
  17. OUTPUT_VARIABLE output
  18. )
  19. if (NOT MOC_RERUN)
  20. message(SEND_ERROR "Initial build of mocBasic failed. Output: ${output}")
  21. endif()
  22. # Get name of the output binary
  23. file(STRINGS "${mocBasicBinDir}/mocBasic.txt" mocBasicList ENCODING UTF-8)
  24. list(GET mocBasicList 0 mocBasicBin)
  25. message("Changing the header content for a MOC rerun")
  26. # - Acquire binary timestamps before the build
  27. file(TIMESTAMP "${mocBasicBin}" timeBefore "${timeformat}")
  28. # - Ensure that the timestamp will change
  29. # - Change header file content and rebuild
  30. # - Rebuild
  31. execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
  32. configure_file("${mocBasicSrcDir}/test1b.h.in" "${mocBasicBinDir}/test1.h" COPYONLY)
  33. execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocBasicBinDir}" RESULT_VARIABLE result )
  34. if (result)
  35. message(SEND_ERROR "Second build of mocBasic failed.")
  36. endif()
  37. # - Acquire binary timestamps after the build
  38. file(TIMESTAMP "${mocBasicBin}" timeAfter "${timeformat}")
  39. # - Test if timestamps changed
  40. if (NOT timeAfter GREATER timeBefore)
  41. message(SEND_ERROR "File (${mocBasicBin}) should have changed!")
  42. endif()
  43. message("Changing nothing for a MOC rerun")
  44. # - Acquire binary timestamps before the build
  45. file(TIMESTAMP "${mocBasicBin}" timeBefore "${timeformat}")
  46. # - Ensure that the timestamp would change
  47. # - Change nothing
  48. # - Rebuild
  49. execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
  50. execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocBasicBinDir}" RESULT_VARIABLE result )
  51. if (result)
  52. message(SEND_ERROR "Third build of mocBasic failed.")
  53. endif()
  54. # - Acquire binary timestamps after the build
  55. file(TIMESTAMP "${mocBasicBin}" timeAfter "${timeformat}")
  56. # - Test if timestamps changed
  57. if (timeAfter GREATER timeBefore)
  58. message(SEND_ERROR "File (${mocBasicBin}) should not have changed!")
  59. endif()