CMakeLists.txt 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. cmake_minimum_required(VERSION 3.10)
  2. project(RerunRccDepends)
  3. include("../AutogenCoreTest.cmake")
  4. # Tests rcc rebuilding when a resource file changes
  5. # Dummy executable to generate a clean target
  6. add_executable(dummy dummy.cpp)
  7. # When a .qrc or a file listed in a .qrc file changes,
  8. # the target must be rebuilt
  9. set(timeformat "%Y%j%H%M%S")
  10. set(rccDepSD "${CMAKE_CURRENT_SOURCE_DIR}/RccDepends")
  11. set(rccDepBD "${CMAKE_CURRENT_BINARY_DIR}/RccDepends")
  12. # Initial build
  13. configure_file(${rccDepSD}/resPlainA.qrc.in ${rccDepBD}/resPlain.qrc COPYONLY)
  14. configure_file(${rccDepSD}/resGenA.qrc.in ${rccDepBD}/resGen.qrc.in COPYONLY)
  15. try_compile(RCC_DEPENDS
  16. "${rccDepBD}"
  17. "${rccDepSD}"
  18. RccDepends
  19. CMAKE_FLAGS "-DQT_TEST_VERSION=${QT_TEST_VERSION}"
  20. "-DCMAKE_AUTOGEN_VERBOSE=${CMAKE_AUTOGEN_VERBOSE}"
  21. "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
  22. OUTPUT_VARIABLE output
  23. )
  24. if (NOT RCC_DEPENDS)
  25. message(SEND_ERROR "Initial build of rccDepends failed. Output: ${output}")
  26. endif()
  27. # Get name of the output binaries
  28. file(STRINGS "${rccDepBD}/targetPlain.txt" targetListPlain ENCODING UTF-8)
  29. file(STRINGS "${rccDepBD}/targetGen.txt" targetListGen ENCODING UTF-8)
  30. list(GET targetListPlain 0 rccDepBinPlain)
  31. list(GET targetListGen 0 rccDepBinGen)
  32. message("Target that uses a plain .qrc file is:\n ${rccDepBinPlain}")
  33. message("Target that uses a GENERATED .qrc file is:\n ${rccDepBinGen}")
  34. message("Changing a resource files listed in the .qrc file")
  35. # - Acquire binary timestamps before the build
  36. file(TIMESTAMP "${rccDepBinPlain}" rdPlainBefore "${timeformat}")
  37. file(TIMESTAMP "${rccDepBinGen}" rdGenBefore "${timeformat}")
  38. # - Ensure that the timestamp will change
  39. # - Change a resource files listed in the .qrc file
  40. # - Rebuild
  41. execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
  42. file(TOUCH "${rccDepBD}/resPlain/input.txt" "${rccDepBD}/resGen/input.txt")
  43. execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDepBD}" RESULT_VARIABLE result)
  44. if (result)
  45. message(SEND_ERROR "Second build of rccDepends failed.")
  46. endif()
  47. # - Acquire binary timestamps after the build
  48. file(TIMESTAMP "${rccDepBinPlain}" rdPlainAfter "${timeformat}")
  49. file(TIMESTAMP "${rccDepBinGen}" rdGenAfter "${timeformat}")
  50. # - Test if timestamps changed
  51. if (NOT rdPlainAfter GREATER rdPlainBefore)
  52. message(SEND_ERROR "Plain .qrc binary ${rccDepBinPlain}) should have changed!")
  53. endif()
  54. if (NOT rdGenAfter GREATER rdGenBefore)
  55. message(SEND_ERROR "GENERATED .qrc binary ${rccDepBinGen} should have changed!")
  56. endif()
  57. message("Changing the .qrc file")
  58. # - Acquire binary timestamps before the build
  59. file(TIMESTAMP "${rccDepBinPlain}" rdPlainBefore "${timeformat}")
  60. file(TIMESTAMP "${rccDepBinGen}" rdGenBefore "${timeformat}")
  61. # - Ensure that the timestamp will change
  62. # - Change the .qrc file
  63. # - Rebuild
  64. execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
  65. configure_file(${rccDepSD}/resPlainB.qrc.in ${rccDepBD}/resPlain.qrc COPYONLY)
  66. configure_file(${rccDepSD}/resGenB.qrc.in ${rccDepBD}/resGen.qrc.in COPYONLY)
  67. execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDepBD}" RESULT_VARIABLE result)
  68. if (result)
  69. message(SEND_ERROR "Third build of rccDepends failed.")
  70. endif()
  71. # - Acquire binary timestamps after the build
  72. file(TIMESTAMP "${rccDepBinPlain}" rdPlainAfter "${timeformat}")
  73. file(TIMESTAMP "${rccDepBinGen}" rdGenAfter "${timeformat}")
  74. # - Test if timestamps changed
  75. if (NOT rdPlainAfter GREATER rdPlainBefore)
  76. message(SEND_ERROR "Plain .qrc binary ${rccDepBinPlain}) should have changed!")
  77. endif()
  78. if (NOT rdGenAfter GREATER rdGenBefore)
  79. message(SEND_ERROR "GENERATED .qrc binary ${rccDepBinGen} should have changed!")
  80. endif()
  81. message("Changing a newly added resource files listed in the .qrc file")
  82. # - Acquire binary timestamps before the build
  83. file(TIMESTAMP "${rccDepBinPlain}" rdPlainBefore "${timeformat}")
  84. file(TIMESTAMP "${rccDepBinGen}" rdGenBefore "${timeformat}")
  85. # - Ensure that the timestamp will change
  86. # - Change a newly added resource files listed in the .qrc file
  87. # - Rebuild
  88. execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
  89. file(TOUCH "${rccDepBD}/resPlain/inputAdded.txt" "${rccDepBD}/resGen/inputAdded.txt")
  90. execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDepBD}" RESULT_VARIABLE result)
  91. if (result)
  92. message(SEND_ERROR "Fourth build of rccDepends failed.")
  93. endif()
  94. # - Acquire binary timestamps after the build
  95. file(TIMESTAMP "${rccDepBinPlain}" rdPlainAfter "${timeformat}")
  96. file(TIMESTAMP "${rccDepBinGen}" rdGenAfter "${timeformat}")
  97. # - Test if timestamps changed
  98. if (NOT rdPlainAfter GREATER rdPlainBefore)
  99. message(SEND_ERROR "Plain .qrc binary ${rccDepBinPlain}) should have changed!")
  100. endif()
  101. if (NOT rdGenAfter GREATER rdGenBefore)
  102. message(SEND_ERROR "GENERATED .qrc binary ${rccDepBinGen} should have changed!")
  103. endif()
  104. message("Changing nothing in the .qrc file")
  105. # - Acquire binary timestamps before the build
  106. file(TIMESTAMP "${rccDepBinPlain}" rdPlainBefore "${timeformat}")
  107. file(TIMESTAMP "${rccDepBinGen}" rdGenBefore "${timeformat}")
  108. # - Ensure that the timestamp will change
  109. # - Change nothing
  110. # - Rebuild
  111. execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
  112. execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDepBD}" RESULT_VARIABLE result)
  113. if (result)
  114. message(SEND_ERROR "Fifth build of rccDepends failed.")
  115. endif()
  116. # - Acquire binary timestamps after the build
  117. file(TIMESTAMP "${rccDepBinPlain}" rdPlainAfter "${timeformat}")
  118. file(TIMESTAMP "${rccDepBinGen}" rdGenAfter "${timeformat}")
  119. # - Test if timestamps changed
  120. if (rdPlainAfter GREATER rdPlainBefore)
  121. message(SEND_ERROR "Plain .qrc binary ${rccDepBinPlain}) should NOT have changed!")
  122. endif()
  123. if (rdGenAfter GREATER rdGenBefore)
  124. message(SEND_ERROR "GENERATED .qrc binary ${rccDepBinGen} should NOT have changed!")
  125. endif()