2013-10-11 22:16:43 +04:00
|
|
|
cmake_minimum_required(VERSION 2.8.11)
|
2011-08-16 04:10:45 +04:00
|
|
|
|
2013-10-11 16:17:32 +04:00
|
|
|
project(QtAutogen)
|
2011-08-16 04:10:45 +04:00
|
|
|
|
2013-03-16 18:52:18 +04:00
|
|
|
if (QT_TEST_VERSION STREQUAL 4)
|
|
|
|
find_package(Qt4 REQUIRED)
|
|
|
|
|
2013-05-15 21:17:41 +04:00
|
|
|
# Include this directory before using the UseQt4 file.
|
|
|
|
add_subdirectory(defines_test)
|
|
|
|
|
2013-03-16 18:52:18 +04:00
|
|
|
include(UseQt4)
|
|
|
|
|
|
|
|
set(QT_QTCORE_TARGET Qt4::QtCore)
|
2014-01-24 20:01:59 +04:00
|
|
|
|
|
|
|
macro(qtx_wrap_cpp)
|
|
|
|
qt4_wrap_cpp(${ARGN})
|
|
|
|
endmacro()
|
|
|
|
|
2013-03-16 18:52:18 +04:00
|
|
|
else()
|
|
|
|
if (NOT QT_TEST_VERSION STREQUAL 5)
|
|
|
|
message(SEND_ERROR "Invalid Qt version specified.")
|
|
|
|
endif()
|
|
|
|
find_package(Qt5Widgets REQUIRED)
|
|
|
|
|
|
|
|
set(QT_QTCORE_TARGET Qt5::Core)
|
|
|
|
|
|
|
|
include_directories(${Qt5Widgets_INCLUDE_DIRS})
|
|
|
|
set(QT_LIBRARIES Qt5::Widgets)
|
|
|
|
|
|
|
|
if(Qt5_POSITION_INDEPENDENT_CODE)
|
|
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
|
|
endif()
|
2014-01-24 20:01:59 +04:00
|
|
|
|
|
|
|
macro(qtx_wrap_cpp)
|
|
|
|
qt5_wrap_cpp(${ARGN})
|
|
|
|
endmacro()
|
|
|
|
|
2013-03-16 18:52:18 +04:00
|
|
|
endif()
|
2011-08-16 04:10:45 +04:00
|
|
|
|
|
|
|
|
|
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
|
2012-03-27 00:11:46 +04:00
|
|
|
add_definitions(-DFOO -DSomeDefine="Barx")
|
2011-08-16 04:10:45 +04:00
|
|
|
|
2011-12-14 01:11:47 +04:00
|
|
|
# enable relaxed mode so automoc can handle all the special cases:
|
|
|
|
set(CMAKE_AUTOMOC_RELAXED_MODE TRUE)
|
|
|
|
|
2013-07-25 11:24:53 +04:00
|
|
|
set(CMAKE_AUTOUIC ON)
|
2013-09-15 16:41:07 +04:00
|
|
|
set(CMAKE_AUTORCC ON)
|
2013-07-25 11:24:53 +04:00
|
|
|
|
2013-01-11 13:40:13 +04:00
|
|
|
# create an executable and two library targets, each requiring automoc:
|
2011-08-16 04:10:45 +04:00
|
|
|
add_library(codeeditorLib STATIC codeeditor.cpp)
|
|
|
|
|
2013-01-11 13:40:13 +04:00
|
|
|
add_library(privateSlot OBJECT private_slot.cpp)
|
2011-08-16 04:10:45 +04:00
|
|
|
|
2013-11-18 11:09:56 +04:00
|
|
|
add_custom_target(generate_moc_input
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/myinterface.h.in" "${CMAKE_CURRENT_BINARY_DIR}"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E rename "${CMAKE_CURRENT_BINARY_DIR}/myinterface.h.in" "${CMAKE_CURRENT_BINARY_DIR}/myinterface.h"
|
|
|
|
)
|
|
|
|
|
2014-03-05 16:43:50 +04:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/myotherinterface.h"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/myotherinterface.h.in" "${CMAKE_CURRENT_BINARY_DIR}/myotherinterface.h"
|
|
|
|
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/myotherinterface.h.in"
|
|
|
|
)
|
|
|
|
|
2014-03-25 04:26:27 +04:00
|
|
|
add_executable(QtAutogen main.cpp calwidget.cpp second_widget.cpp foo.cpp blub.cpp bar.cpp abc.cpp
|
2013-09-15 16:41:07 +04:00
|
|
|
xyz.cpp yaf.cpp gadget.cpp $<TARGET_OBJECTS:privateSlot>
|
2014-03-25 04:16:49 +04:00
|
|
|
test.qrc second_resource.qrc resourcetester.cpp generated.cpp
|
2013-09-15 16:41:07 +04:00
|
|
|
)
|
2014-03-05 16:43:50 +04:00
|
|
|
set_property(TARGET QtAutogen APPEND PROPERTY AUTOGEN_TARGET_DEPENDS generate_moc_input "${CMAKE_CURRENT_BINARY_DIR}/myotherinterface.h")
|
2013-01-11 13:40:13 +04:00
|
|
|
|
2013-10-11 22:16:43 +04:00
|
|
|
set_target_properties(QtAutogen codeeditorLib privateSlot PROPERTIES AUTOMOC TRUE)
|
2011-08-16 04:10:45 +04:00
|
|
|
|
2013-02-07 22:35:00 +04:00
|
|
|
include(GenerateExportHeader)
|
|
|
|
# The order is relevant here. B depends on A, and B headers depend on A
|
2013-03-20 00:40:06 +04:00
|
|
|
# headers both subdirectories use CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE and we
|
2013-02-07 22:35:00 +04:00
|
|
|
# test that CMAKE_AUTOMOC successfully reads the include directories
|
|
|
|
# for the build interface from those targets. There has previously been
|
|
|
|
# a bug where caching of the include directories happened before
|
|
|
|
# extracting the includes to pass to moc.
|
|
|
|
add_subdirectory(Bdir)
|
|
|
|
add_subdirectory(Adir)
|
|
|
|
add_library(libC SHARED libC.cpp)
|
|
|
|
set_target_properties(libC PROPERTIES AUTOMOC TRUE)
|
|
|
|
generate_export_header(libC)
|
|
|
|
target_link_libraries(libC LINK_PUBLIC libB)
|
|
|
|
|
2013-10-11 22:16:43 +04:00
|
|
|
target_link_libraries(QtAutogen codeeditorLib ${QT_LIBRARIES} libC)
|
2013-02-20 20:06:45 +04:00
|
|
|
|
2014-02-05 12:55:51 +04:00
|
|
|
# Add not_generated_file.qrc to the source list to get the file-level
|
|
|
|
# dependency, but don't generate a c++ file from it. Disable the AUTORCC
|
|
|
|
# feature for this target. This tests that qrc files in the sources don't
|
|
|
|
# have an effect on generation if AUTORCC is off.
|
|
|
|
add_library(empty STATIC empty.cpp not_generated_file.qrc)
|
|
|
|
set_target_properties(empty PROPERTIES AUTORCC OFF)
|
|
|
|
|
2013-02-20 20:06:45 +04:00
|
|
|
set_target_properties(empty PROPERTIES AUTOMOC TRUE)
|
|
|
|
target_link_libraries(empty no_link_language)
|
|
|
|
add_library(no_link_language STATIC empty.h)
|
|
|
|
set_target_properties(no_link_language PROPERTIES AUTOMOC TRUE)
|
2014-01-24 20:01:59 +04:00
|
|
|
|
2014-02-02 16:19:27 +04:00
|
|
|
qtx_wrap_cpp(uicOnlyMoc sub/uiconly.h)
|
|
|
|
add_executable(uiconly sub/uiconly.cpp ${uicOnlyMoc})
|
2014-01-24 20:01:59 +04:00
|
|
|
target_link_libraries(uiconly ${QT_LIBRARIES})
|