diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2018-11-15 14:21:17 +0100 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2018-11-22 15:20:17 +0000 |
commit | 24fe9211617ad1f98c69c2702e2b10412c7a55d7 (patch) | |
tree | b01cdf459b4ef88e37495c8c0e40be624f7c1436 /cmake/tests | |
parent | 13e1c93e370551a7398d8e819b8ec4710def0151 (diff) | |
download | qtbase-24fe9211617ad1f98c69c2702e2b10412c7a55d7.tar.gz |
CMake: Add simple test for moc handling and fix the implementation
Add a simple test for moc-file handling and fix the implementation
to make the test pass.
Change-Id: I34e8d65a5e01a6f557d3a3d8cb262fd147ad78e4
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
Diffstat (limited to 'cmake/tests')
-rw-r--r-- | cmake/tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | cmake/tests/moc/CMakeLists.txt | 34 | ||||
-rw-r--r-- | cmake/tests/moc/foo.cpp | 0 | ||||
-rw-r--r-- | cmake/tests/moc/sub/bar.h | 0 | ||||
-rw-r--r-- | cmake/tests/moc/sub2/foobar.h | 0 | ||||
-rw-r--r-- | cmake/tests/test.cmake | 10 |
6 files changed, 42 insertions, 3 deletions
diff --git a/cmake/tests/CMakeLists.txt b/cmake/tests/CMakeLists.txt index 3f51c24025..44aacb7b07 100644 --- a/cmake/tests/CMakeLists.txt +++ b/cmake/tests/CMakeLists.txt @@ -45,6 +45,7 @@ macro(add_cmake_test_generate name) endmacro() add_cmake_test_generate(features) +add_cmake_test_generate(moc) add_cmake_test_generate(qrc) add_cmake_test_generate(qt_make_output_file) add_cmake_test_generate(uic) diff --git a/cmake/tests/moc/CMakeLists.txt b/cmake/tests/moc/CMakeLists.txt new file mode 100644 index 0000000000..297b1ac17d --- /dev/null +++ b/cmake/tests/moc/CMakeLists.txt @@ -0,0 +1,34 @@ +cmake_minimum_required(VERSION 3.12.0) + +project(MocTest + VERSION 1.0.0 + DESCRIPTION "Moc test" + HOMEPAGE_URL "https://qt.io/" + LANGUAGES CXX +) + +## Add some paths to check for cmake modules: +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../;${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/extra-cmake-modules/find-modules;${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/kwin") + +## Qt specific setup common for all modules: +include(QtSetup) + +include(../test.cmake) + +fake_moc_results(MOC foo.cpp sub2/foobar.h MOC_AND_BUILD main.cpp sub/bar.h) +add_qt_executable(test_executable + SOURCES + ../main.cpp + sub/bar.h + sub2/foobar.h + foo.cpp +) + +test_source_file(test_executable "${CMAKE_CURRENT_BINARY_DIR}/main.moc" BUILD) +test_source_file(test_executable "${CMAKE_CURRENT_BINARY_DIR}/sub/moc_bar.cpp" BUILD) +test_source_file(test_executable "${CMAKE_CURRENT_BINARY_DIR}/sub2/moc_foobar.cpp") +test_source_file(test_executable "${CMAKE_CURRENT_BINARY_DIR}/foo.moc") + +test_include_directory(test_executable "${CMAKE_CURRENT_BINARY_DIR}/sub" UNKNOWN) +test_include_directory(test_executable "${CMAKE_CURRENT_BINARY_DIR}/sub2") + diff --git a/cmake/tests/moc/foo.cpp b/cmake/tests/moc/foo.cpp new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/cmake/tests/moc/foo.cpp diff --git a/cmake/tests/moc/sub/bar.h b/cmake/tests/moc/sub/bar.h new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/cmake/tests/moc/sub/bar.h diff --git a/cmake/tests/moc/sub2/foobar.h b/cmake/tests/moc/sub2/foobar.h new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/cmake/tests/moc/sub2/foobar.h diff --git a/cmake/tests/test.cmake b/cmake/tests/test.cmake index 8c11b3a42e..099f490c94 100644 --- a/cmake/tests/test.cmake +++ b/cmake/tests/test.cmake @@ -7,9 +7,13 @@ set(QT_MOCSCANNER /usr/bin/true) # The files passed in after MOC_AND_BUILD will be reported to be in need # of moc-ing and should also be built by the target. function(fake_moc_results) - cmake_parse_arguments(arg "" "" "INCLUDED;BUILT") - file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/moc_files_included.txt" "${arg_INCLUDED}") - file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/moc_files_to_build.txt" "${arg_BUILT}") + cmake_parse_arguments(arg "" "" "MOC;MOC_AND_BUILD" ${ARGN}) + + string(REPLACE ";" "\n" arg_MOC "${arg_MOC}") + string(REPLACE ";" "\n" arg_MOC_AND_BUILD "${arg_MOC_AND_BUILD}") + + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/moc_files_included.txt" "${arg_MOC}") + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/moc_files_to_build.txt" "${arg_MOC_AND_BUILD}") endfunction() # Test whether a target has a file listed in its sources. |