CMakeLists.txt 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. cmake_minimum_required(VERSION 3.11)
  2. project(AutogenOriginDependsOff)
  3. include("../AutogenCoreTest.cmake")
  4. get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  5. # XXX(xcode-per-cfg-src): Enable multi-config code path for Xcode
  6. # when the Xcode generator supports per-config sources.
  7. if(_isMultiConfig AND NOT CMAKE_GENERATOR STREQUAL "Xcode")
  8. set(mocs_compilation_cpp "mocs_compilation_$<CONFIG>.cpp")
  9. else()
  10. set(mocs_compilation_cpp "mocs_compilation.cpp")
  11. endif()
  12. set(CSD ${CMAKE_CURRENT_SOURCE_DIR})
  13. set(CBD ${CMAKE_CURRENT_BINARY_DIR})
  14. include_directories(${CSD})
  15. include_directories(${CBD})
  16. # A GENERATED file ensures there will be an _autogen target in VS
  17. add_custom_command (
  18. OUTPUT "${CBD}/config_a.hpp"
  19. COMMAND ${CMAKE_COMMAND} -E copy "${CSD}/config.hpp.in" "${CBD}/config_a.hpp"
  20. )
  21. # Library "a_mc" provides a header that holds a string with the content of
  22. # mocs_compilation.cpp from a_qt. It therefore must depend on a_qt_autogen.
  23. add_custom_target ( a_mc
  24. COMMAND ${CMAKE_COMMAND} -E sleep 2
  25. COMMAND ${CMAKE_COMMAND}
  26. "-DMCF=${CBD}/a_qt_autogen/${mocs_compilation_cpp}"
  27. "-DCF_IN=${CSD}/a_mc.hpp.in"
  28. "-DCF_OUT=${CBD}/a_mc.hpp"
  29. -P ${CSD}/configure_content.cmake
  30. )
  31. add_dependencies ( a_mc a_qt_autogen )
  32. # Library "a_qt"
  33. # - depends on a GENERATED file
  34. # - AUTOMOC enabled
  35. # - depends on a target (a_mc) that depends on a_qt_qutogen
  36. add_library ( a_qt a_qt.cpp "${CBD}/config_a.hpp" )
  37. add_dependencies ( a_qt a_mc )
  38. target_link_libraries ( a_qt ${QT_QTCORE_TARGET})
  39. set_target_properties ( a_qt PROPERTIES AUTOMOC TRUE)
  40. # Disable AUTOGEN_ORIGIN_DEPENDS to avoid loop dependencies
  41. set_target_properties ( a_qt PROPERTIES AUTOGEN_ORIGIN_DEPENDS OFF)
  42. # A GENERATED file ensures there will be an _autogen target in VS
  43. add_custom_command (
  44. OUTPUT "${CBD}/config_b.hpp"
  45. COMMAND ${CMAKE_COMMAND} -E copy "${CSD}/config.hpp.in" "${CBD}/config_b.hpp"
  46. )
  47. # Library "b_mc" provides a header that holds a string function that returns
  48. # the content of mocs_compilation.cpp from b_qt.
  49. # It therefore must depend on b_qt_autogen.
  50. add_custom_command (
  51. OUTPUT ${CBD}/b_mc.cpp
  52. DEPENDS b_qt_autogen
  53. COMMAND ${CMAKE_COMMAND} -E sleep 2
  54. COMMAND ${CMAKE_COMMAND}
  55. "-DMCF=${CBD}/b_qt_autogen/${mocs_compilation_cpp}"
  56. "-DCF_IN=${CSD}/b_mc.cpp.in"
  57. "-DCF_OUT=${CBD}/b_mc.cpp"
  58. -P ${CSD}/configure_content.cmake
  59. )
  60. add_library ( b_mc ${CSD}/b_mc.hpp ${CBD}/b_mc.cpp )
  61. # Library "b_qt"
  62. # - depends on a GENERATED file
  63. # - AUTOMOC enabled
  64. # - depends on a library (b_mc) that depends on b_qt_qutogen
  65. add_library ( b_qt b_qt.cpp "${CBD}/config_b.hpp" )
  66. target_link_libraries ( b_qt b_mc )
  67. target_link_libraries ( b_qt ${QT_QTCORE_TARGET})
  68. set_target_properties ( b_qt PROPERTIES AUTOMOC TRUE)
  69. # Disable AUTOGEN_ORIGIN_DEPENDS to avoid loop dependencies
  70. set_target_properties ( b_qt PROPERTIES AUTOGEN_ORIGIN_DEPENDS OFF)
  71. # The main target depends on both libraries which depend on the _autogen
  72. # target of the main target.
  73. add_executable ( autogenOriginDependsOff main.cpp )
  74. target_link_libraries ( autogenOriginDependsOff a_qt b_qt )