CMakeLists.txt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. cmake_minimum_required(VERSION 2.8.11)
  2. project(QtAutogen)
  3. if (QT_TEST_VERSION STREQUAL 4)
  4. find_package(Qt4 REQUIRED)
  5. # Include this directory before using the UseQt4 file.
  6. add_subdirectory(defines_test)
  7. include(UseQt4)
  8. set(QT_QTCORE_TARGET Qt4::QtCore)
  9. macro(qtx_wrap_cpp)
  10. qt4_wrap_cpp(${ARGN})
  11. endmacro()
  12. else()
  13. if (NOT QT_TEST_VERSION STREQUAL 5)
  14. message(SEND_ERROR "Invalid Qt version specified.")
  15. endif()
  16. find_package(Qt5Widgets REQUIRED)
  17. set(QT_QTCORE_TARGET Qt5::Core)
  18. include_directories(${Qt5Widgets_INCLUDE_DIRS})
  19. set(QT_LIBRARIES Qt5::Widgets)
  20. if(Qt5_POSITION_INDEPENDENT_CODE)
  21. set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  22. endif()
  23. macro(qtx_wrap_cpp)
  24. qt5_wrap_cpp(${ARGN})
  25. endmacro()
  26. endif()
  27. add_executable(rcconly rcconly.cpp second_resource.qrc)
  28. set_property(TARGET rcconly PROPERTY AUTORCC ON)
  29. target_link_libraries(rcconly ${QT_QTCORE_TARGET})
  30. include_directories(${CMAKE_CURRENT_BINARY_DIR})
  31. add_definitions(-DFOO -DSomeDefine="Barx")
  32. # enable relaxed mode so automoc can handle all the special cases:
  33. set(CMAKE_AUTOMOC_RELAXED_MODE TRUE)
  34. set(CMAKE_AUTOUIC ON)
  35. set(CMAKE_AUTORCC ON)
  36. # create an executable and two library targets, each requiring automoc:
  37. add_library(codeeditorLib STATIC codeeditor.cpp)
  38. add_library(privateSlot OBJECT private_slot.cpp)
  39. add_custom_target(generate_moc_input
  40. COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/myinterface.h.in" "${CMAKE_CURRENT_BINARY_DIR}"
  41. COMMAND ${CMAKE_COMMAND} -E rename "${CMAKE_CURRENT_BINARY_DIR}/myinterface.h.in" "${CMAKE_CURRENT_BINARY_DIR}/myinterface.h"
  42. )
  43. add_custom_command(
  44. OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/myotherinterface.h"
  45. COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/myotherinterface.h.in" "${CMAKE_CURRENT_BINARY_DIR}/myotherinterface.h"
  46. DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/myotherinterface.h.in"
  47. )
  48. message("CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
  49. if (CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]" AND NOT CMAKE_CONFIGURATION_TYPES)
  50. set(debug_srcs "$<$<CONFIG:Debug>:debug_class.cpp>" $<$<CONFIG:Debug>:debug_resource.qrc>)
  51. add_definitions(-DTEST_DEBUG_CLASS)
  52. endif()
  53. add_executable(QtAutogen main.cpp calwidget.cpp second_widget.cpp foo.cpp blub.cpp bar.cpp abc.cpp
  54. multiplewidgets.cpp
  55. xyz.cpp yaf.cpp gadget.cpp $<TARGET_OBJECTS:privateSlot>
  56. test.qrc second_resource.qrc resourcetester.cpp generated.cpp ${debug_srcs}
  57. )
  58. set_property(TARGET QtAutogen APPEND PROPERTY AUTOGEN_TARGET_DEPENDS generate_moc_input "${CMAKE_CURRENT_BINARY_DIR}/myotherinterface.h")
  59. set_target_properties(QtAutogen codeeditorLib privateSlot PROPERTIES AUTOMOC TRUE)
  60. include(GenerateExportHeader)
  61. # The order is relevant here. B depends on A, and B headers depend on A
  62. # headers both subdirectories use CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE and we
  63. # test that CMAKE_AUTOMOC successfully reads the include directories
  64. # for the build interface from those targets. There has previously been
  65. # a bug where caching of the include directories happened before
  66. # extracting the includes to pass to moc.
  67. add_subdirectory(Bdir)
  68. add_subdirectory(Adir)
  69. add_library(libC SHARED libC.cpp)
  70. set_target_properties(libC PROPERTIES AUTOMOC TRUE)
  71. generate_export_header(libC)
  72. target_link_libraries(libC LINK_PUBLIC libB)
  73. target_link_libraries(QtAutogen codeeditorLib ${QT_LIBRARIES} libC)
  74. # Add not_generated_file.qrc to the source list to get the file-level
  75. # dependency, but don't generate a c++ file from it. Disable the AUTORCC
  76. # feature for this target. This tests that qrc files in the sources don't
  77. # have an effect on generation if AUTORCC is off.
  78. add_library(empty STATIC empty.cpp not_generated_file.qrc)
  79. set_target_properties(empty PROPERTIES AUTORCC OFF)
  80. set_target_properties(empty PROPERTIES AUTOMOC TRUE)
  81. target_link_libraries(empty no_link_language)
  82. add_library(no_link_language STATIC empty.h)
  83. set_target_properties(no_link_language PROPERTIES AUTOMOC TRUE)
  84. qtx_wrap_cpp(uicOnlyMoc sub/uiconly.h)
  85. add_executable(uiconly sub/uiconly.cpp ${uicOnlyMoc})
  86. target_link_libraries(uiconly ${QT_LIBRARIES})