Skip to content

Commit ff20482

Browse files
committed
tests: fix leading whitespace in linker flags
Building a project as ExternalProject in Tarantool is failed because initial LDFLAGS is empty and after adding an option a final value has a leading whitespace, but should not [1]: CMake Error at tests/capi/CMakeLists.txt:69 (add_executable): Target "ffi_cdef_proto_test" links to item " -g" which has leading or trailing whitespace. This is now an error according to policy CMP0004. Call Stack (most recent call first): tests/capi/ffi_cdef_proto/CMakeLists.txt:16 (create_test) The patch add a macro `AppendFlags` that allow to avoid such issues. Needed by tarantool/tarantool#10911 1. https://cmake.org/cmake/help/latest/policy/CMP0004.html
1 parent b7eec9f commit ff20482

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

cmake/utils.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,13 @@ function(lua_source varname filename symbolname)
3232
set(var ${${varname}})
3333
set(${varname} ${var} ${dstfile} PARENT_SCOPE)
3434
endfunction()
35+
36+
macro(AppendFlags flags)
37+
foreach(flag ${ARGN})
38+
if (${flags})
39+
set(${flags} "${${flags}} ${flag}")
40+
else()
41+
set(${flags} "${flag}")
42+
endif()
43+
endforeach()
44+
endmacro()

tests/capi/CMakeLists.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,29 @@ target_link_libraries(
2727
>
2828
)
2929

30+
# The following condition looks unnecessary, it was added to fix
31+
# an issue for Sydr: in the Lua external project in the build
32+
# system the explicit build command is used:
33+
# BUILD_COMMAND cd <SOURCE_DIR> && make -j CC=${CMAKE_C_COMPILER} CFLAGS=${CFLAGS} LDFLAGS=${LDFLAGS},
34+
# which use only flags for Lua build, which were explicitly
35+
# declared earlier, so we need to add `-g` to CFLAGS by ourselves.
36+
# See [1].
37+
#
38+
# 1. https://github.com/ligurio/lua-c-api-tests/pull/6#discussion_r1185003511
3039
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
31-
set(LDFLAGS "${LDFLAGS} ${CMAKE_C_FLAGS_DEBUG}")
40+
AppendFlags(LDFLAGS ${CMAKE_C_FLAGS_DEBUG})
3241
endif()
3342

3443
if (ENABLE_ASAN)
35-
set(LDFLAGS "${LDFLAGS} -fsanitize=address")
44+
AppendFlags(LDFLAGS -fsanitize=address)
3645
endif()
3746

3847
if (ENABLE_UBSAN)
39-
set(LDFLAGS "${LDFLAGS} -fsanitize=undefined")
48+
AppendFlags(LDFLAGS -fsanitize=undefined)
4049
endif()
4150

4251
if (ENABLE_COV)
43-
set(LDFLAGS "${LDFLAGS} -fprofile-instr-generate -fcoverage-mapping")
52+
AppendFlags(LDFLAGS -fprofile-instr-generate -fcoverage-mapping)
4453
endif()
4554

4655
set(DEFAULT_RUNS_NUMBER 5)

0 commit comments

Comments
 (0)