[Tarantool-patches] [PATCH luajit 2/6] test: refactor CMake macro LibRealPath
Sergey Bronnikov
estetus at gmail.com
Tue Mar 26 11:33:28 MSK 2024
From: Sergey Bronnikov <sergeyb at tarantool.org>
The patch refactors the CMake macro LibRealPath:
- Replace CMAKE_CXX_COMPILER with CMAKE_C_COMPILER because
LuaJIT doesn't require the CXX compiler, and thus it can be
unavailable on a build system.
- Add a check for a code returned by a command with the compiler.
- Add a check for a value returned by the compiler. A value equal
to a passed one means that the library was not found in
the system.
- Unset local variables to avoid namespace pollution.
Needed for tarantool/tarantool#9656
---
test/LuaJIT-tests/CMakeLists.txt | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/test/LuaJIT-tests/CMakeLists.txt b/test/LuaJIT-tests/CMakeLists.txt
index a0fb5440..badec91d 100644
--- a/test/LuaJIT-tests/CMakeLists.txt
+++ b/test/LuaJIT-tests/CMakeLists.txt
@@ -33,18 +33,41 @@ if(LUAJIT_USE_ASAN)
# https://github.com/google/sanitizers/issues/934.
macro(LibRealPath output lib)
execute_process(
- COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=${lib}
+ # CMAKE_C_COMPILER is used because it has the same behaviour
+ # as CMAKE_CXX_COMPILER, but CMAKE_CXX_COMPILER is not
+ # required for building LuaJIT and can be missed in GH
+ # Actions.
+ COMMAND ${CMAKE_C_COMPILER} -print-file-name=${lib}
OUTPUT_VARIABLE LIB_LINK
OUTPUT_STRIP_TRAILING_WHITESPACE
+ RESULT_VARIABLE RES
)
+
+ if(NOT RES EQUAL 0)
+ message(FATAL_ERROR
+ "Executing '${CMAKE_C_COMPILER} -print-file-name=${lib}' has failed"
+ )
+ endif()
+
+ # GCC and Clang return a passed filename when a library is
+ # not found.
+ if(LIB_LINK STREQUAL ${lib})
+ message(FATAL_ERROR "Library '${lib}' is not found")
+ endif()
+
# Fortunately, we are not interested in macOS here, so we can
- # use realpath.
+ # use realpath. Beware, `realpath` always returns an exit code
+ # equal to 0, so we cannot check if it fails.
execute_process(
COMMAND realpath ${LIB_LINK}
OUTPUT_VARIABLE ${output}
OUTPUT_STRIP_TRAILING_WHITESPACE
)
+
+ unset(LIB_LINK)
+ unset(RES)
endmacro()
+
LibRealPath(LIB_STDCPP libstdc++.so)
# XXX: GCC requires both. Clang requires only libstdc++.
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
--
2.34.1
More information about the Tarantool-patches
mailing list