]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3732] Meson: Add gtest.cc compiler check to detect crashes
authorAndrei Pavel <andrei@isc.org>
Tue, 22 Apr 2025 20:08:26 +0000 (23:08 +0300)
committerAndrei Pavel <andrei@isc.org>
Wed, 23 Apr 2025 20:15:58 +0000 (23:15 +0300)
compiler-checks/gtest.cc [new file with mode: 0644]
meson.build

diff --git a/compiler-checks/gtest.cc b/compiler-checks/gtest.cc
new file mode 100644 (file)
index 0000000..eb1bcea
--- /dev/null
@@ -0,0 +1,12 @@
+#include <gtest/gtest.h>
+
+// musl's mallocng memory allocator stupidly crash for test names that are
+// lengthier than 16 characters. Hence the long test name.
+TEST(Fixture, testWithLongLongLongName) {
+    EXPECT_LT(1, 2);
+}
+
+int main() {
+    testing::InitGoogleTest();
+    return RUN_ALL_TESTS();
+}
index 3f5d541a6796f4a4e5fe046b5a196aeb37aac79f..f66a543e53e6e3dfbed4bc0f7812699a4d5677f2 100644 (file)
@@ -244,11 +244,22 @@ if netconf_opt.enabled() and NETCONF_DEP.get_variable(
     error('Dependency not found: NETCONF.')
 endif
 
-GTEST_DEP = dependency(
-    'gtest',
-    fallback: ['gtest', 'gtest_dep'],
-    required: TESTS_OPT.enabled() or FUZZ_OPT.enabled(),
-)
+# Google Test
+GTEST_DEP = dependency('gtest', required: TESTS_OPT.enabled() or FUZZ_OPT.enabled())
+if GTEST_DEP.found()
+    result = cpp.run(
+        fs.read('compiler-checks/gtest.cc'),
+        name: 'Check if a simple GTest test runs.',
+        dependencies: [GTEST_DEP],
+    )
+    if result.returncode() != 0
+        GTEST_DEP = disabler()
+        gtest_subproject = subproject('gtest', required: false)
+        if gtest_subproject.found()
+            GTEST_DEP = gtest_subproject.get_variable('gtest_dep')
+        endif
+    endif
+endif
 
 # Crypto
 if crypto_opt == 'botan'