CMakeLists.txt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. cmake_minimum_required(VERSION 3.10)
  2. project(RerunMocPlugin)
  3. include("../AutogenTest.cmake")
  4. # Tests Q_PLUGIN_METADATA and CMAKE_AUTOMOC_DEPEND_FILTERS
  5. # json file change detection
  6. # Dummy executable to generate a clean target
  7. add_executable(dummy dummy.cpp)
  8. # Utility variables
  9. set(timeformat "%Y%j%H%M%S")
  10. set(mocPlugSrcDir "${CMAKE_CURRENT_SOURCE_DIR}/MocPlugin")
  11. set(mocPlugBinDir "${CMAKE_CURRENT_BINARY_DIR}/MocPlugin")
  12. # Initial build
  13. try_compile(MOC_PLUGIN
  14. "${mocPlugBinDir}"
  15. "${mocPlugSrcDir}"
  16. MocPlugin
  17. CMAKE_FLAGS "-DQT_TEST_VERSION=${QT_TEST_VERSION}"
  18. "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
  19. OUTPUT_VARIABLE output
  20. )
  21. if (NOT MOC_PLUGIN)
  22. message(SEND_ERROR "Initial build of mocPlugin failed. Output: ${output}")
  23. endif()
  24. find_library(plAFile "PlugA" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH)
  25. find_library(plBFile "PlugB" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH)
  26. find_library(plCFile "PlugC" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH)
  27. find_library(plDFile "PlugD" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH)
  28. find_library(plEFile "PlugE" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH)
  29. # - Ensure that the timestamp will change.
  30. # - Change the json files referenced by Q_PLUGIN_METADATA
  31. # - Rebuild
  32. file(TIMESTAMP "${plAFile}" plABefore "${timeformat}")
  33. file(TIMESTAMP "${plBFile}" plBBefore "${timeformat}")
  34. file(TIMESTAMP "${plCFile}" plCBefore "${timeformat}")
  35. file(TIMESTAMP "${plDFile}" plDBefore "${timeformat}")
  36. file(TIMESTAMP "${plEFile}" plEBefore "${timeformat}")
  37. execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
  38. configure_file("${mocPlugSrcDir}/jsonIn/StyleD.json" "${mocPlugBinDir}/jsonFiles/StyleC.json")
  39. configure_file("${mocPlugSrcDir}/jsonIn/StyleE.json" "${mocPlugBinDir}/jsonFiles/sub/StyleD.json")
  40. configure_file("${mocPlugSrcDir}/jsonIn/StyleC.json" "${mocPlugBinDir}/jsonFiles/StyleE.json")
  41. execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocPlugBinDir}")
  42. file(TIMESTAMP "${plAFile}" plAAfter "${timeformat}")
  43. file(TIMESTAMP "${plBFile}" plBAfter "${timeformat}")
  44. file(TIMESTAMP "${plCFile}" plCAfter "${timeformat}")
  45. file(TIMESTAMP "${plDFile}" plDAfter "${timeformat}")
  46. file(TIMESTAMP "${plEFile}" plEAfter "${timeformat}")
  47. if (plAAfter GREATER plABefore)
  48. message(SEND_ERROR "file (${plAFile}) should not have changed!")
  49. endif()
  50. if (plBAfter GREATER plBBefore)
  51. message(SEND_ERROR "file (${plBFile}) should not have changed!")
  52. endif()
  53. if (NOT plCAfter GREATER plCBefore)
  54. message(SEND_ERROR "file (${plCFile}) should have changed!")
  55. endif()
  56. if (NOT plDAfter GREATER plDBefore)
  57. message(SEND_ERROR "file (${plDFile}) should have changed!")
  58. endif()
  59. if (NOT plEAfter GREATER plEBefore)
  60. # There's a bug in Ninja on Windows
  61. # https://gitlab.kitware.com/cmake/cmake/issues/16776
  62. if(NOT ("${CMAKE_GENERATOR}" MATCHES "Ninja"))
  63. message(SEND_ERROR "file (${plEFile}) should have changed!")
  64. endif()
  65. endif()
  66. # - Ensure that the timestamp will change.
  67. # - Change the json files referenced by A_CUSTOM_MACRO
  68. # - Rebuild
  69. file(TIMESTAMP "${plCFile}" plCBefore "${timeformat}")
  70. file(TIMESTAMP "${plDFile}" plDBefore "${timeformat}")
  71. file(TIMESTAMP "${plEFile}" plEBefore "${timeformat}")
  72. execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
  73. configure_file("${mocPlugSrcDir}/jsonIn/StyleE.json" "${mocPlugBinDir}/jsonFiles/StyleC_Custom.json")
  74. configure_file("${mocPlugSrcDir}/jsonIn/StyleC.json" "${mocPlugBinDir}/jsonFiles/sub/StyleD_Custom.json")
  75. configure_file("${mocPlugSrcDir}/jsonIn/StyleD.json" "${mocPlugBinDir}/jsonFiles/StyleE_Custom.json")
  76. execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocPlugBinDir}")
  77. file(TIMESTAMP "${plCFile}" plCAfter "${timeformat}")
  78. file(TIMESTAMP "${plDFile}" plDAfter "${timeformat}")
  79. file(TIMESTAMP "${plEFile}" plEAfter "${timeformat}")
  80. if (NOT plCAfter GREATER plCBefore)
  81. message(SEND_ERROR "file (${plCFile}) should have changed!")
  82. endif()
  83. if (NOT plDAfter GREATER plDBefore)
  84. message(SEND_ERROR "file (${plDFile}) should have changed!")
  85. endif()
  86. if (NOT plEAfter GREATER plEBefore)
  87. # There's a bug in Ninja on Windows
  88. # https://gitlab.kitware.com/cmake/cmake/issues/16776
  89. if(NOT ("${CMAKE_GENERATOR}" MATCHES "Ninja"))
  90. message(SEND_ERROR "file (${plEFile}) should have changed!")
  91. endif()
  92. endif()