diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | cmake/try_compile/ldwrap.c | 16 | ||||
-rw-r--r-- | tests/CMakeLists.txt | 22 |
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) |