1
0

CMakeLists.txt 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. else()
  10. if (NOT QT_TEST_VERSION STREQUAL 5)
  11. message(SEND_ERROR "Invalid Qt version specified.")
  12. endif()
  13. find_package(Qt5Widgets REQUIRED)
  14. set(QT_QTCORE_TARGET Qt5::Core)
  15. include_directories(${Qt5Widgets_INCLUDE_DIRS})
  16. set(QT_LIBRARIES Qt5::Widgets)
  17. if(Qt5_POSITION_INDEPENDENT_CODE)
  18. set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  19. endif()
  20. endif()
  21. include_directories(${CMAKE_CURRENT_BINARY_DIR})
  22. add_definitions(-DFOO -DSomeDefine="Barx")
  23. # enable relaxed mode so automoc can handle all the special cases:
  24. set(CMAKE_AUTOMOC_RELAXED_MODE TRUE)
  25. set(CMAKE_AUTOUIC ON)
  26. set(CMAKE_AUTORCC ON)
  27. # create an executable and two library targets, each requiring automoc:
  28. add_library(codeeditorLib STATIC codeeditor.cpp)
  29. add_library(privateSlot OBJECT private_slot.cpp)
  30. add_custom_target(generate_moc_input
  31. COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/myinterface.h.in" "${CMAKE_CURRENT_BINARY_DIR}"
  32. COMMAND ${CMAKE_COMMAND} -E rename "${CMAKE_CURRENT_BINARY_DIR}/myinterface.h.in" "${CMAKE_CURRENT_BINARY_DIR}/myinterface.h"
  33. )
  34. # set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/myinterface.h" PROPERTIES GENERATED TRUE)
  35. add_executable(QtAutogen main.cpp calwidget.cpp foo.cpp blub.cpp bar.cpp abc.cpp
  36. xyz.cpp yaf.cpp gadget.cpp $<TARGET_OBJECTS:privateSlot>
  37. test.qrc resourcetester.cpp generated.cpp
  38. )
  39. set_property(TARGET QtAutogen APPEND PROPERTY AUTOGEN_TARGET_DEPENDS generate_moc_input)
  40. set_target_properties(QtAutogen codeeditorLib privateSlot PROPERTIES AUTOMOC TRUE)
  41. include(GenerateExportHeader)
  42. # The order is relevant here. B depends on A, and B headers depend on A
  43. # headers both subdirectories use CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE and we
  44. # test that CMAKE_AUTOMOC successfully reads the include directories
  45. # for the build interface from those targets. There has previously been
  46. # a bug where caching of the include directories happened before
  47. # extracting the includes to pass to moc.
  48. add_subdirectory(Bdir)
  49. add_subdirectory(Adir)
  50. add_library(libC SHARED libC.cpp)
  51. set_target_properties(libC PROPERTIES AUTOMOC TRUE)
  52. generate_export_header(libC)
  53. target_link_libraries(libC LINK_PUBLIC libB)
  54. target_link_libraries(QtAutogen codeeditorLib ${QT_LIBRARIES} libC)
  55. add_library(empty STATIC empty.cpp)
  56. set_target_properties(empty PROPERTIES AUTOMOC TRUE)
  57. target_link_libraries(empty no_link_language)
  58. add_library(no_link_language STATIC empty.h)
  59. set_target_properties(no_link_language PROPERTIES AUTOMOC TRUE)