CMake: Set SKIP_AUTOMOC/AUTOUIC where needed

Make sure we don't run into warnings for CMake 3.10

Task-number: QTBUG-63442
Change-Id: Ida004705646f0c32fb4bf6006036d80b1f279fd7
Reviewed-by: David Faure <david.faure@kdab.com>
Reviewed-by: Sebastian Holtermann <sebholt@xwmw.org>
Reviewed-by: Rolf Eike Beer <eb@emlix.com>
This commit is contained in:
Kevin Funk 2017-09-29 22:17:10 +02:00 committed by David Faure
parent c3a5c482ef
commit b71b7461b0
8 changed files with 182 additions and 5 deletions

View File

@ -137,6 +137,9 @@ function(QT5_CREATE_MOC_COMMAND infile outfile moc_flags moc_options moc_target
DEPENDS ${infile} ${moc_depends} DEPENDS ${infile} ${moc_depends}
${_moc_working_dir} ${_moc_working_dir}
VERBATIM) VERBATIM)
set_source_files_properties(${infile} PROPERTIES SKIP_AUTOMOC ON)
set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOMOC ON)
set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOUIC ON)
endfunction() endfunction()
@ -155,7 +158,6 @@ function(QT5_GENERATE_MOC infile outfile )
set(moc_target ${ARGV3}) set(moc_target ${ARGV3})
endif() endif()
qt5_create_moc_command(${abs_infile} ${_outfile} "${moc_flags}" "" "${moc_target}" "") qt5_create_moc_command(${abs_infile} ${_outfile} "${moc_flags}" "" "${moc_target}" "")
set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOMOC TRUE) # dont run automoc on this file
endfunction() endfunction()
@ -246,6 +248,7 @@ function(QT5_ADD_BINARY_RESOURCES target )
get_filename_component(infile ${it} ABSOLUTE) get_filename_component(infile ${it} ABSOLUTE)
_QT5_PARSE_QRC_FILE(${infile} _out_depends _rc_depends) _QT5_PARSE_QRC_FILE(${infile} _out_depends _rc_depends)
set_source_files_properties(${infile} PROPERTIES SKIP_AUTORCC ON)
set(infiles ${infiles} ${infile}) set(infiles ${infiles} ${infile})
set(out_depends ${out_depends} ${_out_depends}) set(out_depends ${out_depends} ${_out_depends})
set(rc_depends ${rc_depends} ${_rc_depends}) set(rc_depends ${rc_depends} ${_rc_depends})
@ -255,7 +258,6 @@ function(QT5_ADD_BINARY_RESOURCES target )
COMMAND ${Qt5Core_RCC_EXECUTABLE} COMMAND ${Qt5Core_RCC_EXECUTABLE}
ARGS ${rcc_options} --binary --name ${target} --output ${rcc_destination} ${infiles} ARGS ${rcc_options} --binary --name ${target} --output ${rcc_destination} ${infiles}
DEPENDS ${rc_depends} ${out_depends} VERBATIM) DEPENDS ${rc_depends} ${out_depends} VERBATIM)
add_custom_target(${target} ALL DEPENDS ${rcc_destination}) add_custom_target(${target} ALL DEPENDS ${rcc_destination})
endfunction() endfunction()
@ -283,12 +285,15 @@ function(QT5_ADD_RESOURCES outfiles )
set(outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_${outfilename}.cpp) set(outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_${outfilename}.cpp)
_QT5_PARSE_QRC_FILE(${infile} _out_depends _rc_depends) _QT5_PARSE_QRC_FILE(${infile} _out_depends _rc_depends)
set_source_files_properties(${infile} PROPERTIES SKIP_AUTORCC ON)
add_custom_command(OUTPUT ${outfile} add_custom_command(OUTPUT ${outfile}
COMMAND ${Qt5Core_RCC_EXECUTABLE} COMMAND ${Qt5Core_RCC_EXECUTABLE}
ARGS ${rcc_options} --name ${outfilename} --output ${outfile} ${infile} ARGS ${rcc_options} --name ${outfilename} --output ${outfile} ${infile}
MAIN_DEPENDENCY ${infile} MAIN_DEPENDENCY ${infile}
DEPENDS ${_rc_depends} "${out_depends}" VERBATIM) DEPENDS ${_rc_depends} "${out_depends}" VERBATIM)
set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOMOC ON)
set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOUIC ON)
list(APPEND ${outfiles} ${outfile}) list(APPEND ${outfiles} ${outfile})
endforeach() endforeach()
set(${outfiles} ${${outfiles}} PARENT_SCOPE) set(${outfiles} ${${outfiles}} PARENT_SCOPE)

View File

@ -59,6 +59,9 @@ function(QT5_WRAP_UI outfiles )
COMMAND ${Qt5Widgets_UIC_EXECUTABLE} COMMAND ${Qt5Widgets_UIC_EXECUTABLE}
ARGS ${ui_options} -o ${outfile} ${infile} ARGS ${ui_options} -o ${outfile} ${infile}
MAIN_DEPENDENCY ${infile} VERBATIM) MAIN_DEPENDENCY ${infile} VERBATIM)
set_source_files_properties(${infile} PROPERTIES SKIP_AUTOUIC ON)
set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOMOC ON)
set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOUIC ON)
list(APPEND ${outfiles} ${outfile}) list(APPEND ${outfiles} ${outfile})
endforeach() endforeach()
set(${outfiles} ${${outfiles}} PARENT_SCOPE) set(${outfiles} ${${outfiles}} PARENT_SCOPE)

View File

@ -157,7 +157,13 @@ if (NOT CMAKE_VERSION VERSION_LESS 2.8.11 AND NOT NO_WIDGETS)
expect_pass(test_interface) expect_pass(test_interface)
endif() endif()
if (NOT CMAKE_VERSION VERSION_LESS 2.8.12) expect_pass(test_interface_link_libraries)
expect_pass(test_interface_link_libraries) expect_pass(test_moc_macro_target)
expect_pass(test_moc_macro_target)
if (NOT CMAKE_VERSION VERSION_LESS 3.8)
# With earlier CMake versions, this test would simply run moc multiple times and lead to:
# /usr/bin/ld: error: CMakeFiles/mywidget.dir/mywidget_automoc.cpp.o: multiple definition of 'MyWidget::qt_static_metacall(QObject*, QMetaObject::Call, int, void**)'
# /usr/bin/ld: CMakeFiles/mywidget.dir/moc_mywidget.cpp.o: previous definition here
# Reason: SKIP_* properties were added in CMake 3.8 only
expect_pass(test_QTBUG-63422)
endif() endif()

View File

@ -0,0 +1,30 @@
cmake_minimum_required(VERSION 2.8)
project(test_dependent_modules)
find_package(Qt5Widgets REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# make sure CMP0071 warnings cause a test failure
set(CMAKE_SUPPRESS_DEVELOPER_ERRORS FALSE CACHE INTERNAL "" FORCE)
qt5_wrap_cpp(moc_files mywidget.h)
qt5_wrap_ui(ui_files mywidget.ui)
qt5_add_resources(qrc_files res.qrc)
add_executable(mywidget
# source files
mywidget.cpp
mywidget.h
mywidget.ui
res.qrc
# generated files
${moc_files}
${ui_files}
${qrc_files}
)
target_link_libraries(mywidget ${Qt5Widgets_LIBRARIES})

View File

@ -0,0 +1,43 @@
/****************************************************************************
**
** Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Kevin Funk <kevin.funk@kdab.com>
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "mywidget.h"
#include "ui_mywidget.h"
MyWidget::MyWidget(QWidget *parent)
: QWidget(parent)
{
emit someSignal();
}
int main(int argc, char **argv)
{
QApplication app(argc, argv);
MyWidget myWidget;
return 0;
}

View File

@ -0,0 +1,52 @@
/****************************************************************************
**
** Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Kevin Funk <kevin.funk@kdab.com>
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef MYWIDGET_H
#define MYWIDGET_H
#include <QWidget>
namespace Ui
{
class MyWidget;
}
class MyWidget : public QWidget
{
Q_OBJECT
public:
MyWidget(QWidget *parent = nullptr);
signals:
void someSignal();
private:
Ui::MyWidget *ui = nullptr;
};
#endif

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item>
<widget class="QTextEdit" name="textEdit"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,4 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
</qresource>
</RCC>