mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-16 14:08:35 +08:00
AutoGen: Add test to check for correct AutoMoc dependencies
When using Qt 5.15.0 or above together with Ninja, check that touching a source file of a dependency does not needlessly re-run AUTOMOC for the dependee target.
This commit is contained in:
@@ -134,6 +134,9 @@ if(CMAKE_GENERATOR MATCHES "Ninja")
|
||||
if(CMAKE_Fortran_COMPILER)
|
||||
list(APPEND Ninja_ARGS -DTEST_Fortran=1)
|
||||
endif()
|
||||
if(CMake_TEST_Qt5 AND Qt5Core_FOUND)
|
||||
list(APPEND Ninja_ARGS -DCMake_TEST_Qt5=1 -DCMAKE_TEST_Qt5Core_Version=${Qt5Core_VERSION})
|
||||
endif()
|
||||
add_RunCMake_test(Ninja)
|
||||
set(NinjaMultiConfig_ARGS
|
||||
-DCYGWIN=${CYGWIN}
|
||||
|
9
Tests/RunCMake/Ninja/Qt5AutoMocDeps.cmake
Normal file
9
Tests/RunCMake/Ninja/Qt5AutoMocDeps.cmake
Normal file
@@ -0,0 +1,9 @@
|
||||
enable_language(CXX)
|
||||
|
||||
find_package(Qt5Core REQUIRED)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
add_library(simple_lib SHARED simple_lib.cpp)
|
||||
add_executable(app_with_qt app.cpp app_qt.cpp)
|
||||
target_link_libraries(app_with_qt PRIVATE simple_lib Qt5::Core)
|
@@ -132,6 +132,7 @@ ${ninja_stderr}
|
||||
message(FATAL_ERROR
|
||||
"top ninja build failed exited with status ${ninja_result}")
|
||||
endif()
|
||||
set(ninja_stdout "${ninja_stdout}" PARENT_SCOPE)
|
||||
endfunction(run_ninja)
|
||||
|
||||
function (run_LooseObjectDepends)
|
||||
@@ -316,3 +317,23 @@ function (run_ChangeBuildType)
|
||||
run_ninja("${RunCMake_TEST_BINARY_DIR}" -w dupbuild=err)
|
||||
endfunction()
|
||||
run_ChangeBuildType()
|
||||
|
||||
function(run_Qt5AutoMocDeps)
|
||||
if(CMake_TEST_Qt5 AND CMAKE_TEST_Qt5Core_Version VERSION_GREATER_EQUAL 5.15.0)
|
||||
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Qt5AutoMocDeps-build)
|
||||
run_cmake(Qt5AutoMocDeps)
|
||||
unset(RunCMake_TEST_OPTIONS)
|
||||
# Build the project.
|
||||
run_ninja("${RunCMake_TEST_BINARY_DIR}")
|
||||
# Touch just the library source file, which shouldn't cause a rerun of AUTOMOC
|
||||
# for app_with_qt target.
|
||||
touch("${RunCMake_SOURCE_DIR}/simple_lib.cpp")
|
||||
# Build and assert that AUTOMOC was not run for app_with_qt.
|
||||
run_ninja("${RunCMake_TEST_BINARY_DIR}")
|
||||
if(ninja_stdout MATCHES "Automatic MOC for target app_with_qt")
|
||||
message(FATAL_ERROR
|
||||
"AUTOMOC should not have executed for 'app_with_qt' target:\nstdout:\n${ninja_stdout}")
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
run_Qt5AutoMocDeps()
|
||||
|
6
Tests/RunCMake/Ninja/app.cpp
Normal file
6
Tests/RunCMake/Ninja/app.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
return 0;
|
||||
}
|
11
Tests/RunCMake/Ninja/app_qt.cpp
Normal file
11
Tests/RunCMake/Ninja/app_qt.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <QObject>
|
||||
|
||||
class Mango : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Q_SIGNALS:
|
||||
void eatFruit();
|
||||
};
|
||||
|
||||
#include "app_qt.moc"
|
6
Tests/RunCMake/Ninja/simple_lib.cpp
Normal file
6
Tests/RunCMake/Ninja/simple_lib.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifdef _WIN32
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void dummy_symbol()
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user