mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-08 06:40:48 -06:00
Autogen: Tests: Add Q_PLUGIN_METADATA test
This commit is contained in:
committed by
Brad King
parent
39c4819eaa
commit
cd74daf06f
@@ -86,7 +86,8 @@ 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}"
|
||||
CMAKE_FLAGS "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
|
||||
"-DQT_TEST_VERSION=${QT_TEST_VERSION}"
|
||||
"-DCMAKE_PREFIX_PATH=${Qt_PREFIX_DIR}"
|
||||
OUTPUT_VARIABLE output
|
||||
)
|
||||
@@ -121,7 +122,8 @@ 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}"
|
||||
CMAKE_FLAGS "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
|
||||
"-DQT_TEST_VERSION=${QT_TEST_VERSION}"
|
||||
"-DCMAKE_PREFIX_PATH=${Qt_PREFIX_DIR}"
|
||||
OUTPUT_VARIABLE output
|
||||
)
|
||||
@@ -214,6 +216,61 @@ add_subdirectory(mocIncludeStrict)
|
||||
# Tests various include moc patterns
|
||||
add_subdirectory(mocIncludeRelaxed)
|
||||
|
||||
# -- Test
|
||||
# Tests Q_PLUGIN_METADATA json file change detection
|
||||
if (NOT QT_TEST_VERSION STREQUAL 4)
|
||||
try_compile(MOC_PLUGIN
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/mocPlugin"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/mocPlugin"
|
||||
mocPlugin
|
||||
CMAKE_FLAGS "-DQT_TEST_VERSION=${QT_TEST_VERSION}"
|
||||
"-DCMAKE_PREFIX_PATH=${Qt_PREFIX_DIR}"
|
||||
OUTPUT_VARIABLE output
|
||||
)
|
||||
if (NOT MOC_PLUGIN)
|
||||
message(SEND_ERROR "Initial build of mocPlugin failed. Output: ${output}")
|
||||
endif()
|
||||
|
||||
set(timeformat "%Y%j%H%M%S")
|
||||
set(mocPluginBinDir "${CMAKE_CURRENT_BINARY_DIR}/mocPlugin")
|
||||
find_library(style_a_file "PluginStyleA" "${mocPluginBinDir}")
|
||||
find_library(style_b_file "PluginStyleB" "${mocPluginBinDir}")
|
||||
find_library(style_c_file "PluginStyleC" "${mocPluginBinDir}")
|
||||
find_library(style_d_file "PluginStyleD" "${mocPluginBinDir}")
|
||||
|
||||
file(TIMESTAMP "${style_a_file}" style_a_before "${timeformat}")
|
||||
file(TIMESTAMP "${style_b_file}" style_b_before "${timeformat}")
|
||||
file(TIMESTAMP "${style_c_file}" style_c_before "${timeformat}")
|
||||
file(TIMESTAMP "${style_d_file}" style_d_before "${timeformat}")
|
||||
|
||||
# Ensure that the timestamp will change and touch the json files
|
||||
execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
|
||||
execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${mocPluginBinDir}/jsonFiles/StyleC.json")
|
||||
execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${mocPluginBinDir}/jsonFiles/sub/StyleD.json")
|
||||
|
||||
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mocPlugin"
|
||||
)
|
||||
|
||||
file(TIMESTAMP "${style_a_file}" style_a_after "${timeformat}")
|
||||
file(TIMESTAMP "${style_b_file}" style_b_after "${timeformat}")
|
||||
file(TIMESTAMP "${style_c_file}" style_c_after "${timeformat}")
|
||||
file(TIMESTAMP "${style_d_file}" style_d_after "${timeformat}")
|
||||
|
||||
if (style_a_after GREATER style_a_before)
|
||||
message(SEND_ERROR "file (${style_a_file}) should not have changed!")
|
||||
endif()
|
||||
if (style_b_after GREATER style_b_before)
|
||||
message(SEND_ERROR "file (${style_b_file}) should not have changed!")
|
||||
endif()
|
||||
if (NOT style_c_after GREATER style_c_before)
|
||||
message(SEND_ERROR "file (${style_c_file}) should have changed!")
|
||||
endif()
|
||||
if (NOT style_d_after GREATER style_d_before)
|
||||
message(SEND_ERROR "file (${style_d_file}) should have changed!")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# -- Test
|
||||
# Complex test case
|
||||
add_subdirectory(complex)
|
||||
|
||||
25
Tests/QtAutogen/mocPlugin/CMakeLists.txt
Normal file
25
Tests/QtAutogen/mocPlugin/CMakeLists.txt
Normal file
@@ -0,0 +1,25 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
|
||||
if (NOT QT_TEST_VERSION STREQUAL 5)
|
||||
message(SEND_ERROR "Invalid Qt version specified.")
|
||||
endif()
|
||||
find_package(Qt5Widgets REQUIRED)
|
||||
|
||||
if(Qt5_POSITION_INDEPENDENT_CODE AND CMAKE_CXX_COMPILE_OPTIONS_PIC)
|
||||
add_definitions(${CMAKE_CXX_COMPILE_OPTIONS_PIC})
|
||||
endif()
|
||||
|
||||
configure_file(jsonIn/StyleC.json jsonFiles/StyleC.json @ONLY)
|
||||
configure_file(jsonIn/StyleD.json jsonFiles/sub/StyleD.json @ONLY)
|
||||
|
||||
# Enable automoc
|
||||
set(CMAKE_AUTOMOC TRUE)
|
||||
|
||||
include_directories("${CMAKE_CURRENT_BINARY_DIR}/jsonFiles")
|
||||
link_libraries(Qt5::Widgets)
|
||||
|
||||
add_library(PluginStyleA MODULE StyleA.cpp)
|
||||
add_library(PluginStyleB MODULE StyleB.cpp)
|
||||
add_library(PluginStyleC MODULE StyleC.cpp)
|
||||
add_library(PluginStyleD MODULE StyleD.cpp)
|
||||
add_library(PluginStyleE MODULE StyleE.cpp)
|
||||
6
Tests/QtAutogen/mocPlugin/StyleA.cpp
Normal file
6
Tests/QtAutogen/mocPlugin/StyleA.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "StyleA.hpp"
|
||||
|
||||
QStyle* StyleA::create(const QString& key)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
15
Tests/QtAutogen/mocPlugin/StyleA.hpp
Normal file
15
Tests/QtAutogen/mocPlugin/StyleA.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef STYLEA_HPP
|
||||
#define STYLEA_HPP
|
||||
|
||||
#include <QStylePlugin>
|
||||
|
||||
class StyleA : public QStylePlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
// Json file in local directory
|
||||
Q_PLUGIN_METADATA(IID "org.styles.A" FILE "StyleA.json")
|
||||
public:
|
||||
QStyle* create(const QString& key);
|
||||
};
|
||||
|
||||
#endif
|
||||
1
Tests/QtAutogen/mocPlugin/StyleA.json
Normal file
1
Tests/QtAutogen/mocPlugin/StyleA.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "Keys": [ "Rocket", "Starbuster" ] }
|
||||
6
Tests/QtAutogen/mocPlugin/StyleB.cpp
Normal file
6
Tests/QtAutogen/mocPlugin/StyleB.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "StyleB.hpp"
|
||||
|
||||
QStyle* StyleB::create(const QString& key)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
15
Tests/QtAutogen/mocPlugin/StyleB.hpp
Normal file
15
Tests/QtAutogen/mocPlugin/StyleB.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef STYLEB_HPP
|
||||
#define STYLEB_HPP
|
||||
|
||||
#include <QStylePlugin>
|
||||
|
||||
class StyleB : public QStylePlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
// Json file in local subdirectory
|
||||
Q_PLUGIN_METADATA(IID "org.styles.B" FILE "jsonIn/StyleB.json")
|
||||
public:
|
||||
QStyle* create(const QString& key);
|
||||
};
|
||||
|
||||
#endif
|
||||
6
Tests/QtAutogen/mocPlugin/StyleC.cpp
Normal file
6
Tests/QtAutogen/mocPlugin/StyleC.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "StyleC.hpp"
|
||||
|
||||
QStyle* StyleC::create(const QString& key)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
15
Tests/QtAutogen/mocPlugin/StyleC.hpp
Normal file
15
Tests/QtAutogen/mocPlugin/StyleC.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef STYLEC_HPP
|
||||
#define STYLEC_HPP
|
||||
|
||||
#include <QStylePlugin>
|
||||
|
||||
class StyleC : public QStylePlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
// Json file in global root directory
|
||||
Q_PLUGIN_METADATA(IID "org.styles.C" FILE "StyleC.json")
|
||||
public:
|
||||
QStyle* create(const QString& key);
|
||||
};
|
||||
|
||||
#endif
|
||||
17
Tests/QtAutogen/mocPlugin/StyleD.cpp
Normal file
17
Tests/QtAutogen/mocPlugin/StyleD.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "StyleD.hpp"
|
||||
|
||||
class StyleD : public QStylePlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
// Json file in global sub director
|
||||
Q_PLUGIN_METADATA(IID "org.styles.D" FILE "sub/StyleD.json")
|
||||
public:
|
||||
QStyle* create(const QString& key);
|
||||
};
|
||||
|
||||
QStyle* StyleD::create(const QString& key)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include "StyleD.moc"
|
||||
8
Tests/QtAutogen/mocPlugin/StyleD.hpp
Normal file
8
Tests/QtAutogen/mocPlugin/StyleD.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef STYLED_HPP
|
||||
#define STYLED_HPP
|
||||
|
||||
#include <QStylePlugin>
|
||||
|
||||
class StyleD;
|
||||
|
||||
#endif
|
||||
6
Tests/QtAutogen/mocPlugin/StyleE.cpp
Normal file
6
Tests/QtAutogen/mocPlugin/StyleE.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "StyleE.hpp"
|
||||
|
||||
QStyle* StyleE::create(const QString& key)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
15
Tests/QtAutogen/mocPlugin/StyleE.hpp
Normal file
15
Tests/QtAutogen/mocPlugin/StyleE.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef STYLEE_HPP
|
||||
#define STYLEE_HPP
|
||||
|
||||
#include <QStylePlugin>
|
||||
|
||||
class StyleE : public QStylePlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
// No Json file
|
||||
Q_PLUGIN_METADATA(IID "org.styles.E")
|
||||
public:
|
||||
QStyle* create(const QString& key);
|
||||
};
|
||||
|
||||
#endif
|
||||
1
Tests/QtAutogen/mocPlugin/jsonIn/StyleB.json
Normal file
1
Tests/QtAutogen/mocPlugin/jsonIn/StyleB.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "Keys": [ "Rocket", "StarbusterB" ] }
|
||||
1
Tests/QtAutogen/mocPlugin/jsonIn/StyleC.json
Normal file
1
Tests/QtAutogen/mocPlugin/jsonIn/StyleC.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "Keys": [ "Rocket", "StarbusterC" ] }
|
||||
1
Tests/QtAutogen/mocPlugin/jsonIn/StyleD.json
Normal file
1
Tests/QtAutogen/mocPlugin/jsonIn/StyleD.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "Keys": [ "Rocket", "StarbusterD" ] }
|
||||
6
Tests/QtAutogen/mocPlugin/main.cpp
Normal file
6
Tests/QtAutogen/mocPlugin/main.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "StyleA.hpp"
|
||||
|
||||
int main(int argv, char** args)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user