CMakeLists.txt 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. cmake_minimum_required(VERSION 3.10)
  2. project(MocDepends)
  3. include("../AutogenTest.cmake")
  4. include_directories(${CMAKE_CURRENT_BINARY_DIR})
  5. set(CSD ${CMAKE_CURRENT_SOURCE_DIR})
  6. set(CBD ${CMAKE_CURRENT_BINARY_DIR})
  7. # -- Test dependency on header generated by a custom command
  8. #
  9. # The ORIGIN_autogen target must depend on the same *GENERATED* source files as
  10. # the ORIGIN target. This is a requirement to ensure that all files for the
  11. # ORIGIN target are generated before the ORIGIN_autogen target is built.
  12. #
  13. # This tests the dependency of the mocDepGenFile_autogen target of
  14. # mocDepGenFile to the source file GenFile.hpp, which is *GENERATED*
  15. # by a custom command.
  16. # If mocDepGenFile_autogen gets built *before* or in *parallel* to the
  17. # custom command, the build will fail. That's because GenFile.hpp,
  18. # which is required by mocDepGenFile_autogen, is only valid after the
  19. # custom command has been completed.
  20. #
  21. # The sleep seconds artificially increase the build time of the custom command
  22. # to simulate a slow file generation process that takes longer to run than
  23. # the build of the mocDepGenFile_autogen target.
  24. add_custom_command(
  25. OUTPUT ${CBD}/GenFile.hpp
  26. COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/object_invalid.hpp.in ${CBD}/GenFile.hpp
  27. COMMAND ${CMAKE_COMMAND} -E sleep 3
  28. COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/object_valid.hpp.in ${CBD}/GenFile.hpp)
  29. add_executable(mocDepGenFile testGenFile.cpp ${CBD}/GenFile.hpp)
  30. target_link_libraries(mocDepGenFile ${QT_QTCORE_TARGET})
  31. set_target_properties(mocDepGenFile PROPERTIES AUTOMOC TRUE)
  32. # -- Test dependency on header generating custom target
  33. #
  34. # The ORIGIN_autogen target must depend on the same user defined targets
  35. # as the ORIGIN target. This is a requirement to ensure that all files for the
  36. # ORIGIN target are generated before the ORIGIN_autogen target is built.
  37. #
  38. # This tests the dependency of the mocDepTarget_autogen target of
  39. # mocDepTarget to the utility target mocDepTargetUtil.
  40. # If mocDepTarget_autogen gets built *before* or in *parallel* to
  41. # mocDepTargetUtil, the build will fail. That's
  42. # because GenTarget.hpp, which is required by mocDepTarget_autogen,
  43. # is only valid after the mocDepTargetUtil build has been completed.
  44. #
  45. # The sleep seconds artificially increase the build time of mocDepTargetUtil
  46. # to simulate a slow utility target build that takes longer to run than
  47. # the build of the mocDepTarget_autogen target.
  48. add_custom_target(mocDepTargetUtil
  49. BYPRODUCTS ${CBD}/GenTarget.hpp
  50. COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/object_invalid.hpp.in ${CBD}/GenTarget.hpp
  51. COMMAND ${CMAKE_COMMAND} -E sleep 3
  52. COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/object_valid.hpp.in ${CBD}/GenTarget.hpp)
  53. add_executable(mocDepTarget testGenTarget.cpp)
  54. target_link_libraries(mocDepTarget ${QT_QTCORE_TARGET})
  55. set_target_properties(mocDepTarget PROPERTIES AUTOMOC TRUE)
  56. add_dependencies(mocDepTarget mocDepTargetUtil)
  57. # -- Test 3: Depend on generated linked library
  58. # The ORIGIN_autogen target must depend on the same linked libraries
  59. # as the ORIGIN target. This is a requirement to ensure that all files for the
  60. # ORIGIN target are generated before the ORIGIN_autogen target is built.
  61. #
  62. # This tests the dependency of the mocDepGenLib_autogen target of mocDepGenLib
  63. # to the user generated library SimpleLib, which mocDepGenLib links to.
  64. # If mocDepGenLib_autogen gets built *before* or in *parallel* to SimpleLib,
  65. # the build will fail. That's because simpleLib.hpp, which is required by
  66. # mocDepGenLib_autogen, is only valid after the SimpleLib build has been
  67. # completed.
  68. #
  69. # The sleep seconds artificially increase the build time of SimpleLib
  70. # to simulate a slow utility library build that takes longer to run than
  71. # the build of the mocDepGenLib_autogen target.
  72. add_custom_command(
  73. OUTPUT ${CBD}/simpleLib.hpp ${CBD}/simpleLib.cpp
  74. COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/object_invalid.hpp.in ${CBD}/simpleLib.hpp
  75. COMMAND ${CMAKE_COMMAND} -E sleep 3
  76. COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/simpleLib.hpp.in ${CBD}/simpleLib.hpp
  77. COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/simpleLib.cpp.in ${CBD}/simpleLib.cpp)
  78. add_library(SimpleLib STATIC ${CBD}/simpleLib.hpp ${CBD}/simpleLib.cpp)
  79. target_link_libraries(SimpleLib ${QT_QTCORE_TARGET})
  80. add_executable(mocDepGenLib testGenLib.cpp)
  81. target_link_libraries(mocDepGenLib SimpleLib ${QT_QTCORE_TARGET})
  82. set_target_properties(mocDepGenLib PROPERTIES AUTOMOC TRUE)
  83. # -- Test AUTOGEN_TARGET_DEPENDS with GENERATED file dependency
  84. #
  85. # This tests the dependency of the mocDepATDFile_autogen target of
  86. # mocDepATDTarget to the utility target mocDepATDFileUtil.
  87. # If mocDepATDFile_autogen gets built *before* or in *parallel* to
  88. # mocDepATDFileUtil, the build will fail. That's
  89. # because ATDFile.hpp, which is required by mocDepATDFile_autogen,
  90. # is only valid after the mocDepATDFileUtil build has been completed.
  91. #
  92. # The sleep seconds artificially increase the build time of
  93. # mocDepATDFileUtil to simulate a slow utility target build that takes
  94. # longer to run than the build of the mocDepATDFile_autogen target.
  95. add_custom_command(
  96. OUTPUT ${CBD}/ATDFile.hpp
  97. COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/object_invalid.hpp.in ${CBD}/ATDFile.hpp
  98. COMMAND ${CMAKE_COMMAND} -E sleep 3
  99. COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/object_valid.hpp.in ${CBD}/ATDFile.hpp)
  100. add_executable(mocDepATDFile testATDFile.cpp)
  101. target_link_libraries(mocDepATDFile ${QT_QTCORE_TARGET})
  102. set_target_properties(mocDepATDFile PROPERTIES AUTOMOC TRUE)
  103. set_target_properties(mocDepATDFile PROPERTIES AUTOGEN_TARGET_DEPENDS ${CBD}/ATDFile.hpp)
  104. # -- Test AUTOGEN_TARGET_DEPENDS with target dependency
  105. #
  106. # This tests the dependency of the mocDepATDTarget_autogen target of
  107. # mocDepATDTarget to the utility target mocDepATDTargetUtil.
  108. # If mocDepATDTarget_autogen gets built *before* or in *parallel* to
  109. # mocDepATDTargetUtil, the build will fail. That's
  110. # because ATDTarget.hpp, which is required by mocDepATDTarget_autogen,
  111. # is only valid after the mocDepATDTargetUtil build has been completed.
  112. #
  113. # The sleep seconds artificially increase the build time of
  114. # mocDepATDTargetUtil to simulate a slow utility target build that takes
  115. # longer to run than the build of the mocDepATDTarget_autogen target.
  116. add_custom_target(mocDepATDTargetUtil
  117. BYPRODUCTS ${CBD}/ATDTarget.hpp
  118. COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/object_invalid.hpp.in ${CBD}/ATDTarget.hpp
  119. COMMAND ${CMAKE_COMMAND} -E sleep 3
  120. COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/object_valid.hpp.in ${CBD}/ATDTarget.hpp)
  121. add_executable(mocDepATDTarget testATDTarget.cpp)
  122. target_link_libraries(mocDepATDTarget ${QT_QTCORE_TARGET})
  123. set_target_properties(mocDepATDTarget PROPERTIES AUTOMOC TRUE)
  124. set_target_properties(mocDepATDTarget PROPERTIES AUTOGEN_TARGET_DEPENDS mocDepATDTargetUtil)