2015-04-16 20:57:17 +03:00
|
|
|
cmake_minimum_required(VERSION 3.1)
|
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
|
|
|
|
2015-04-16 20:54:54 +03:00
|
|
|
# Tell find_package(Qt5) where to find Qt.
|
|
|
|
if(QT_QMAKE_EXECUTABLE)
|
|
|
|
get_filename_component(Qt_BIN_DIR "${QT_QMAKE_EXECUTABLE}" PATH)
|
|
|
|
get_filename_component(Qt_PREFIX_DIR "${Qt_BIN_DIR}" PATH)
|
|
|
|
set(CMAKE_PREFIX_PATH ${Qt_PREFIX_DIR})
|
|
|
|
endif()
|
|
|
|
|
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)
|
|
|
|
|
2015-06-21 15:50:50 +03:00
|
|
|
if(Qt5_POSITION_INDEPENDENT_CODE AND CMAKE_CXX_COMPILE_OPTIONS_PIC)
|
|
|
|
add_definitions(${CMAKE_CXX_COMPILE_OPTIONS_PIC})
|
2013-03-16 18:52:18 +04:00
|
|
|
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
|
|
|
|
2014-09-10 18:20:43 +04:00
|
|
|
add_executable(rcconly rcconly.cpp second_resource.qrc)
|
|
|
|
set_property(TARGET rcconly PROPERTY AUTORCC ON)
|
|
|
|
target_link_libraries(rcconly ${QT_QTCORE_TARGET})
|
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
|
|
|
|
2015-04-20 23:42:19 +03:00
|
|
|
configure_file(generated_resource.qrc.in generated_resource.qrc @ONLY)
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT generated.txt
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/generated.txt.in" "${CMAKE_CURRENT_BINARY_DIR}/generated.txt"
|
|
|
|
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/generated.txt.in"
|
|
|
|
)
|
|
|
|
|
2013-11-18 11:09:56 +04:00
|
|
|
add_custom_target(generate_moc_input
|
2015-04-20 23:42:19 +03:00
|
|
|
DEPENDS generated.txt
|
2013-11-18 11:09:56 +04:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2015-04-16 20:30:32 +03:00
|
|
|
if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_GENERATOR STREQUAL Ninja)
|
2014-02-13 20:25:00 +04:00
|
|
|
set(debug_srcs "$<$<CONFIG:Debug>:debug_class.cpp>" $<$<CONFIG:Debug>:debug_resource.qrc>)
|
2015-04-16 20:30:32 +03:00
|
|
|
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:TEST_DEBUG_CLASS>)
|
2014-02-13 20:25:00 +04:00
|
|
|
endif()
|
|
|
|
|
2015-01-12 03:22:11 +03:00
|
|
|
# The -no-protection option disables the generation of include guards. Verify
|
|
|
|
# that setting the source file property has an effect by using this and
|
|
|
|
# issue an error in the preprocessor in calwidget.cpp if the include guard
|
|
|
|
# is defined.
|
|
|
|
set_source_files_properties(calwidget.ui PROPERTIES AUTOUIC_OPTIONS "-no-protection")
|
|
|
|
|
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
|
2014-09-17 03:23:57 +04:00
|
|
|
multiplewidgets.cpp
|
2013-09-15 16:41:07 +04:00
|
|
|
xyz.cpp yaf.cpp gadget.cpp $<TARGET_OBJECTS:privateSlot>
|
2014-02-13 20:25:00 +04:00
|
|
|
test.qrc second_resource.qrc resourcetester.cpp generated.cpp ${debug_srcs}
|
2015-04-20 23:42:19 +03:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/generated_resource.qrc
|
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})
|
2014-09-17 04:42:30 +04:00
|
|
|
|
|
|
|
try_compile(RCC_DEPENDS
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/autorcc_depends"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/autorcc_depends"
|
|
|
|
autorcc_depends
|
|
|
|
CMAKE_FLAGS "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}" "-DQT_TEST_VERSION=${QT_TEST_VERSION}"
|
2015-04-16 20:54:54 +03:00
|
|
|
"-DCMAKE_PREFIX_PATH=${Qt_PREFIX_DIR}"
|
2014-09-17 04:42:30 +04:00
|
|
|
OUTPUT_VARIABLE output
|
|
|
|
)
|
|
|
|
if (NOT RCC_DEPENDS)
|
|
|
|
message(SEND_ERROR "Initial build of autorcc_depends failed. Output: ${output}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/autorcc_depends/info_file.txt" qrc_files)
|
|
|
|
|
|
|
|
list(GET qrc_files 0 qrc_file1)
|
|
|
|
|
|
|
|
set(timeformat "%Y%j%H%M%S")
|
|
|
|
|
|
|
|
file(TIMESTAMP "${qrc_file1}" file1_before "${timeformat}")
|
|
|
|
|
|
|
|
execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) # Ensure that the timestamp will change.
|
2015-04-16 19:51:05 +03:00
|
|
|
execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${CMAKE_CURRENT_BINARY_DIR}/autorcc_depends/res1/input.txt")
|
2014-09-17 04:42:30 +04:00
|
|
|
|
|
|
|
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
|
|
|
|
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/autorcc_depends"
|
|
|
|
)
|
|
|
|
|
|
|
|
file(TIMESTAMP "${qrc_file1}" file1_step1 "${timeformat}")
|
|
|
|
|
|
|
|
if (NOT file1_step1 GREATER file1_before)
|
|
|
|
message(SEND_ERROR "file1 (${qrc_file1}) should have changed in the first step!")
|
|
|
|
endif()
|
2015-06-19 16:38:04 +03:00
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
try_compile(MOC_RERUN
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/automoc_rerun"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/automoc_rerun"
|
|
|
|
automoc_rerun
|
|
|
|
CMAKE_FLAGS "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}" "-DQT_TEST_VERSION=${QT_TEST_VERSION}"
|
|
|
|
"-DCMAKE_PREFIX_PATH=${Qt_PREFIX_DIR}"
|
|
|
|
OUTPUT_VARIABLE output
|
|
|
|
)
|
|
|
|
if (NOT MOC_RERUN)
|
|
|
|
message(SEND_ERROR "Initial build of automoc_rerun failed. Output: ${output}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
configure_file(automoc_rerun/test1.h.in2 automoc_rerun/test1.h COPYONLY)
|
|
|
|
|
|
|
|
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
|
|
|
|
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/automoc_rerun"
|
|
|
|
RESULT_VARIABLE automoc_rerun_result
|
|
|
|
)
|
|
|
|
if (automoc_rerun_result)
|
|
|
|
message(SEND_ERROR "Second build of automoc_rerun failed.")
|
|
|
|
endif()
|