summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2024-05-21 03:12:18 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2024-05-21 03:12:18 +0200
commit2f4c1de6c3fa23e073b81b9dd9fd9869037612db (patch)
treecc4d193728596bdd17367782fb8bccc686f2de5f
parentb54b8f5b25403cf3b9623804b2491ec78a8b913e (diff)
downloadblogc-2f4c1de6c3fa23e073b81b9dd9fd9869037612db.tar.gz
blogc-2f4c1de6c3fa23e073b81b9dd9fd9869037612db.tar.bz2
blogc-2f4c1de6c3fa23e073b81b9dd9fd9869037612db.zip
build: tests: support cmake < 3.25
-rw-r--r--CMakeLists.txt2
-rw-r--r--cmake/try_compile/ldwrap.c16
-rw-r--r--tests/CMakeLists.txt22
3 files changed, 32 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7498ad5..5699552 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: 2024 Rafael G. Martins <rafael@rafaelmartins.eng.br>
# SPDX-License-Identifier: BSD-3-Clause
-cmake_minimum_required(VERSION 3.19)
+cmake_minimum_required(VERSION 3.22)
find_package(Git)
diff --git a/cmake/try_compile/ldwrap.c b/cmake/try_compile/ldwrap.c
new file mode 100644
index 0000000..cc200e8
--- /dev/null
+++ b/cmake/try_compile/ldwrap.c
@@ -0,0 +1,16 @@
+#include <stdlib.h>
+
+void __real_exit(int status);
+
+void
+__wrap_exit(int s)
+{
+ __real_exit(0);
+}
+
+int
+main()
+{
+ exit(1);
+ return 0;
+}
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index e1ca881..8a1d7b0 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -8,13 +8,21 @@ find_program(BASH bash HINTS /bin /usr/bin REQUIRED)
find_program(DIFF diff REQUIRED)
find_program(TEE tee REQUIRED)
-try_compile(HAVE_LD_WRAP
- SOURCE_FROM_CONTENT
- main.c
- "#include <stdlib.h>\nvoid __real_exit(int status);\nvoid __wrap_exit(int s){__real_exit(0);}\nint main(){exit(1);}"
- LINK_OPTIONS
- "-Wl,--wrap=exit"
-)
+if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.25")
+ try_compile(HAVE_LD_WRAP
+ SOURCES
+ "${CMAKE_SOURCE_DIR}/cmake/try_compile/ldwrap.c"
+ LINK_OPTIONS
+ "-Wl,--wrap=exit"
+ )
+else()
+ try_compile(HAVE_LD_WRAP "${CMAKE_BINARY_DIR}/ldwrap"
+ SOURCES
+ "${CMAKE_SOURCE_DIR}/cmake/try_compile/ldwrap.c"
+ LINK_OPTIONS
+ "-Wl,--wrap=exit"
+ )
+endif()
function(blogc_executable_test _libname _src)
if (NOT CMOCKA_FOUND)