CMakeLists.txt 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. cmake_minimum_required(VERSION 2.8)
  2. project(QtAutomoc)
  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. # create an executable and two library targets, each requiring automoc:
  26. add_library(codeeditorLib STATIC codeeditor.cpp)
  27. add_library(privateSlot OBJECT private_slot.cpp)
  28. add_executable(foo main.cpp calwidget.cpp foo.cpp blub.cpp bar.cpp abc.cpp
  29. xyz.cpp yaf.cpp $<TARGET_OBJECTS:privateSlot>)
  30. set_target_properties(foo codeeditorLib privateSlot PROPERTIES AUTOMOC TRUE)
  31. include(GenerateExportHeader)
  32. # The order is relevant here. B depends on A, and B headers depend on A
  33. # headers both subdirectories use CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE and we
  34. # test that CMAKE_AUTOMOC successfully reads the include directories
  35. # for the build interface from those targets. There has previously been
  36. # a bug where caching of the include directories happened before
  37. # extracting the includes to pass to moc.
  38. add_subdirectory(Bdir)
  39. add_subdirectory(Adir)
  40. add_library(libC SHARED libC.cpp)
  41. set_target_properties(libC PROPERTIES AUTOMOC TRUE)
  42. generate_export_header(libC)
  43. target_link_libraries(libC LINK_PUBLIC libB)
  44. target_link_libraries(foo codeeditorLib ${QT_LIBRARIES} libC)
  45. add_library(empty STATIC empty.cpp)
  46. set_target_properties(empty PROPERTIES AUTOMOC TRUE)
  47. target_link_libraries(empty no_link_language)
  48. add_library(no_link_language STATIC empty.h)
  49. set_target_properties(no_link_language PROPERTIES AUTOMOC TRUE)