summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStephen Kelly <stephen.kelly@kdab.com>2012-10-19 16:59:53 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-26 15:23:30 +0200
commit49555e3ac956d9f90b01d136c510206cf50d0a8b (patch)
treedd4d68e953cc3d91bad95be05930b9d0e096d525 /src
parent356f3c89b83704591e3c37cf8c322b52d6840763 (diff)
Add a CMake macro to test module includes
The variations of includes which should work are tested. For example, in the case of testing the QtCore module and QObject include, the following includes are generated and compiled: #include <QObject> #include <QtCore/QObject> #include <QtCore> #include <QtCore/QtCore> As the private include directories are not available to the compiler, this also tests that private headers are not included from public ones. Change-Id: Id03d0fe290c9691e0f7515015892991d1701ab72 Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/Qt5CTestMacros.cmake75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/corelib/Qt5CTestMacros.cmake b/src/corelib/Qt5CTestMacros.cmake
index 3d1b3b3191..0db83e3fb3 100644
--- a/src/corelib/Qt5CTestMacros.cmake
+++ b/src/corelib/Qt5CTestMacros.cmake
@@ -59,3 +59,78 @@ macro(expect_fail _dir)
--build-options "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${BUILD_OPTIONS_LIST}
)
endmacro()
+
+function(test_module_includes)
+
+ set(all_args ${ARGN})
+ set(packages_string "")
+ set(libraries_string "")
+
+ foreach(_package ${Qt5_MODULE_TEST_DEPENDS})
+ set(packages_string
+ "
+ ${packages_string}
+ find_package(Qt5${_package} REQUIRED)
+ "
+ )
+ endforeach()
+
+ while(all_args)
+ list(GET all_args 0 qtmodule)
+ list(REMOVE_AT all_args 0 1)
+ set(packages_string
+ "${packages_string}
+ find_package(Qt5${qtmodule} REQUIRED)
+ include_directories(\${Qt5${qtmodule}_INCLUDE_DIRS})
+ add_definitions(\${Qt5${qtmodule}_DEFINITIONS})\n"
+ )
+ set(libraries_string "${libraries_string} Qt5::${qtmodule}")
+ endwhile()
+
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/module_includes/CMakeLists.txt"
+ "
+ cmake_minimum_required(VERSION 2.8)
+ project(module_includes)
+
+ ${packages_string}
+
+ set(CMAKE_CXX_FLAGS \"\${CMAKE_CXX_FLAGS} \${Qt5Core_EXECUTABLE_COMPILE_FLAGS}\")
+
+ add_executable(module_includes_exe \"\${CMAKE_CURRENT_SOURCE_DIR}/main.cpp\")
+ target_link_libraries(module_includes_exe ${libraries_string})\n"
+ )
+
+ set(all_args ${ARGN})
+ set(includes_string "")
+ while(all_args)
+ list(GET all_args 0 qtmodule)
+ list(GET all_args 1 qtinclude)
+ list(REMOVE_AT all_args 0 1)
+ set(includes_string
+ "${includes_string}
+ #include <${qtinclude}>
+ #include <Qt${qtmodule}/${qtinclude}>
+ #include <Qt${qtmodule}>
+ #include <Qt${qtmodule}/Qt${qtmodule}>"
+ )
+ endwhile()
+
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/module_includes/main.cpp"
+ "
+
+ ${includes_string}
+
+ int main(int, char **) { return 0; }\n"
+ )
+
+ add_test(module_includes ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMAKE_CURRENT_BINARY_DIR}/module_includes/"
+ "${CMAKE_CURRENT_BINARY_DIR}/module_includes/build"
+ --build-config "${CMAKE_BUILD_TYPE}"
+ --build-generator ${CMAKE_GENERATOR}
+ --build-makeprogram ${CMAKE_MAKE_PROGRAM}
+ --build-project module_includes
+ --build-options "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${BUILD_OPTIONS_LIST}
+ )
+endfunction()