CMakeLists.txt 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. cmake_minimum_required(VERSION 3.10)
  2. project(RerunRccDepends)
  3. include("../AutogenTest.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. "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
  21. OUTPUT_VARIABLE output
  22. )
  23. if (NOT RCC_DEPENDS)
  24. message(SEND_ERROR "Initial build of rccDepends failed. Output: ${output}")
  25. endif()
  26. # Get name of the output binaries
  27. file(STRINGS "${rccDepBD}/targetPlain.txt" targetListPlain ENCODING UTF-8)
  28. file(STRINGS "${rccDepBD}/targetGen.txt" targetListGen ENCODING UTF-8)
  29. list(GET targetListPlain 0 rccDepBinPlain)
  30. list(GET targetListGen 0 rccDepBinGen)
  31. message("Target that uses a plain .qrc file is:\n ${rccDepBinPlain}")
  32. message("Target that uses a GENERATED .qrc file is:\n ${rccDepBinGen}")
  33. message("Changing a resource files listed in the .qrc file")
  34. # - Acquire binary timestamps before the build
  35. file(TIMESTAMP "${rccDepBinPlain}" rdPlainBefore "${timeformat}")
  36. file(TIMESTAMP "${rccDepBinGen}" rdGenBefore "${timeformat}")
  37. # - Ensure that the timestamp will change
  38. # - Change a resource files listed in the .qrc file
  39. # - Rebuild
  40. execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
  41. execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${rccDepBD}/resPlain/input.txt")
  42. execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${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 a 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. execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${rccDepBD}/resPlain/inputAdded.txt")
  90. execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${rccDepBD}/resGen/inputAdded.txt")
  91. execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDepBD}" RESULT_VARIABLE result)
  92. if (result)
  93. message(SEND_ERROR "Fourth build of rccDepends failed.")
  94. endif()
  95. # - Acquire binary timestamps after the build
  96. file(TIMESTAMP "${rccDepBinPlain}" rdPlainAfter "${timeformat}")
  97. file(TIMESTAMP "${rccDepBinGen}" rdGenAfter "${timeformat}")
  98. # - Test if timestamps changed
  99. if (NOT rdPlainAfter GREATER rdPlainBefore)
  100. message(SEND_ERROR "Plain .qrc binary ${rccDepBinPlain}) should have changed!")
  101. endif()
  102. if (NOT rdGenAfter GREATER rdGenBefore)
  103. message(SEND_ERROR "GENERATED .qrc binary ${rccDepBinGen} should have changed!")
  104. endif()
  105. message("Changing nothing in the .qrc file")
  106. # - Acquire binary timestamps before the build
  107. file(TIMESTAMP "${rccDepBinPlain}" rdPlainBefore "${timeformat}")
  108. file(TIMESTAMP "${rccDepBinGen}" rdGenBefore "${timeformat}")
  109. # - Ensure that the timestamp will change
  110. # - Change nothing
  111. # - Rebuild
  112. execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
  113. execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDepBD}" RESULT_VARIABLE result)
  114. if (result)
  115. message(SEND_ERROR "Fifth build of rccDepends failed.")
  116. endif()
  117. # - Acquire binary timestamps after the build
  118. file(TIMESTAMP "${rccDepBinPlain}" rdPlainAfter "${timeformat}")
  119. file(TIMESTAMP "${rccDepBinGen}" rdGenAfter "${timeformat}")
  120. # - Test if timestamps changed
  121. if (rdPlainAfter GREATER rdPlainBefore)
  122. message(SEND_ERROR "Plain .qrc binary ${rccDepBinPlain}) should NOT have changed!")
  123. endif()
  124. if (rdGenAfter GREATER rdGenBefore)
  125. message(SEND_ERROR "GENERATED .qrc binary ${rccDepBinGen} should NOT have changed!")
  126. endif()