summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorOrkun Tokdemir <orkun.tokdemir@qt.io>2023-03-21 17:18:46 (GMT)
committerBrad King <brad.king@kitware.com>2023-03-30 10:41:51 (GMT)
commit429a452705f5a3b7f9a46833aca6560393659cc2 (patch)
treeb8de404afbd748ba6746c2839e748d9cb79ba289 /Tests
parent21f812e57c48166ec5529460182d6f266d0ee55e (diff)
downloadCMake-429a452705f5a3b7f9a46833aca6560393659cc2.zip
CMake-429a452705f5a3b7f9a46833aca6560393659cc2.tar.gz
CMake-429a452705f5a3b7f9a46833aca6560393659cc2.tar.bz2
Autogen: Add target's C++ standard to moc_predef.h
Generate `moc_predef.h` using the same C++ standard level that will be used to compile the target so that the compiler's predefined macros can be more accurately recovered. Fixes: #24624 Qt-Issue: https://bugreports.qt.io/browse/QTBUG-110847
Diffstat (limited to 'Tests')
-rw-r--r--Tests/RunCMake/Autogen/MocPredefs-build-stderr.txt1
-rw-r--r--Tests/RunCMake/Autogen/MocPredefs-check.cxx60
-rw-r--r--Tests/RunCMake/Autogen/MocPredefs-prefix.cmake3
-rw-r--r--Tests/RunCMake/Autogen/MocPredefs.cmake40
-rw-r--r--Tests/RunCMake/Autogen/MocPredefs.cxx3
-rw-r--r--Tests/RunCMake/Autogen/RunCMakeTest.cmake7
6 files changed, 114 insertions, 0 deletions
diff --git a/Tests/RunCMake/Autogen/MocPredefs-build-stderr.txt b/Tests/RunCMake/Autogen/MocPredefs-build-stderr.txt
new file mode 100644
index 0000000..8d98f9d
--- /dev/null
+++ b/Tests/RunCMake/Autogen/MocPredefs-build-stderr.txt
@@ -0,0 +1 @@
+.*
diff --git a/Tests/RunCMake/Autogen/MocPredefs-check.cxx b/Tests/RunCMake/Autogen/MocPredefs-check.cxx
new file mode 100644
index 0000000..2b4791f
--- /dev/null
+++ b/Tests/RunCMake/Autogen/MocPredefs-check.cxx
@@ -0,0 +1,60 @@
+#include <iostream>
+
+#include "check_predefs.h"
+
+#define TO_STRING(x) TO_STRING0(x)
+#define TO_STRING0(x) #x
+
+int main()
+{
+ int ret = 0;
+#if defined(__STRICT_ANSI__)
+# if !defined(CHECK___STRICT_ANSI__)
+ std::cout << "__STRICT_ANSI__: Expected " << TO_STRING(__STRICT_ANSI__)
+ << " but it is not defined.\n";
+ ret = 1;
+# elif __STRICT_ANSI__ != CHECK___STRICT_ANSI__
+ std::cout << "__STRICT_ANSI__: Expected " << TO_STRING(__STRICT_ANSI__)
+ << " but got: " << TO_STRING(CHECK___STRICT_ANSI__) << "\n";
+ ret = 1;
+# endif
+#elif defined(CHECK___STRICT_ANSI__)
+ std::cout << "__STRICT_ANSI__: Expected undefined but got: "
+ << TO_STRING(CHECK___STRICT_ANSI__) << "\n";
+ ret = 1;
+#endif
+
+#if defined(__cplusplus)
+# if !defined(CHECK___cplusplus)
+ std::cout << "__cplusplus: Expected " << TO_STRING(__cplusplus)
+ << " but it is not defined.\n";
+ ret = 1;
+# elif __cplusplus != CHECK___cplusplus
+ std::cout << "__cplusplus: Expected " << TO_STRING(__cplusplus)
+ << " but got: " << TO_STRING(CHECK___cplusplus) << "\n";
+ ret = 1;
+# endif
+#elif defined(CHECK___cplusplus)
+ std::cout << "__cplusplus: Expected undefined but got: "
+ << TO_STRING(CHECK___cplusplus) << "\n";
+ ret = 1;
+#endif
+
+#if defined(_MSVC_LANG)
+# if !defined(CHECK__MSVC_LANG)
+ std::cout << "_MSVC_LANG: Expected " << TO_STRING(_MSVC_LANG)
+ << " but it is not defined.\n";
+ ret = 1;
+# elif _MSVC_LANG != CHECK__MSVC_LANG
+ std::cout << "_MSVC_LANG: Expected " << TO_STRING(_MSVC_LANG)
+ << " but got: " << TO_STRING(CHECK__MSVC_LANG) << "\n";
+ ret = 1;
+# endif
+#elif defined(CHECK__MSVC_LANG)
+ std::cout << "_MSVC_LANG: Expected undefined but got: "
+ << TO_STRING(CHECK__MSVC_LANG) << "\n";
+ ret = 1;
+#endif
+
+ return ret;
+}
diff --git a/Tests/RunCMake/Autogen/MocPredefs-prefix.cmake b/Tests/RunCMake/Autogen/MocPredefs-prefix.cmake
new file mode 100644
index 0000000..460a05d
--- /dev/null
+++ b/Tests/RunCMake/Autogen/MocPredefs-prefix.cmake
@@ -0,0 +1,3 @@
+file(READ ${in} predefs)
+string(REGEX REPLACE "#define +" "#define CHECK_" predefs "${predefs}")
+file(WRITE ${out} "${predefs}")
diff --git a/Tests/RunCMake/Autogen/MocPredefs.cmake b/Tests/RunCMake/Autogen/MocPredefs.cmake
new file mode 100644
index 0000000..7a89bb5
--- /dev/null
+++ b/Tests/RunCMake/Autogen/MocPredefs.cmake
@@ -0,0 +1,40 @@
+cmake_policy(SET CMP0129 NEW)
+enable_language(CXX)
+
+find_package(Qt${with_qt_version} REQUIRED COMPONENTS Core)
+
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_EXTENSIONS OFF)
+
+add_library(MocPredefs MocPredefs.cxx)
+
+if(NOT DEFINED CMAKE_CXX_COMPILER_PREDEFINES_COMMAND)
+ return()
+endif()
+
+if(CMAKE_CXX_COMPILER_ID STREQUAL "LCC" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "1.26")
+ return()
+endif()
+
+get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if(_isMultiConfig)
+ set(moc_predefs_h "moc_predefs_$<CONFIG>.h")
+ set(check_dir "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>")
+else()
+ set(moc_predefs_h "moc_predefs.h")
+ set(check_dir "${CMAKE_CURRENT_BINARY_DIR}")
+endif()
+
+add_custom_command(TARGET MocPredefs POST_BUILD VERBATIM COMMAND
+ ${CMAKE_COMMAND}
+ -Din=${CMAKE_CURRENT_BINARY_DIR}/MocPredefs_autogen/${moc_predefs_h}
+ -Dout=${check_dir}/check_predefs.h
+ -P${CMAKE_CURRENT_SOURCE_DIR}/MocPredefs-prefix.cmake
+ )
+
+add_executable(MocPredefs-check MocPredefs-check.cxx)
+target_include_directories(MocPredefs-check PRIVATE ${check_dir})
+add_dependencies(MocPredefs-check MocPredefs)
+
+add_custom_target(MocPredefs-run-check ALL VERBATIM COMMAND MocPredefs-check)
diff --git a/Tests/RunCMake/Autogen/MocPredefs.cxx b/Tests/RunCMake/Autogen/MocPredefs.cxx
new file mode 100644
index 0000000..b27cec5
--- /dev/null
+++ b/Tests/RunCMake/Autogen/MocPredefs.cxx
@@ -0,0 +1,3 @@
+void MocPredefs()
+{
+}
diff --git a/Tests/RunCMake/Autogen/RunCMakeTest.cmake b/Tests/RunCMake/Autogen/RunCMakeTest.cmake
index e4c5811..6a3c49b 100644
--- a/Tests/RunCMake/Autogen/RunCMakeTest.cmake
+++ b/Tests/RunCMake/Autogen/RunCMakeTest.cmake
@@ -15,4 +15,11 @@ if (DEFINED with_qt_version)
run_cmake(CMP0111-imported-target-full)
run_cmake(CMP0111-imported-target-libname)
run_cmake(CMP0111-imported-target-implib-only)
+
+ block()
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/MocPredefs-build)
+ run_cmake(MocPredefs)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ run_cmake_command(MocPredefs-build ${CMAKE_COMMAND} --build . --config Debug)
+ endblock()
endif ()