Skip to content

Commit 421ed1b

Browse files
committed
cmake: Introduce SECP256K1_APPEND_LDFLAGS variable
Downstream projects may include libsecp test executables in their test suites. In such cases, if a `-fsanitize=...` flag is passed via the `SECP256K1_APPEND_CFLAGS` variable, the same flag must also be passed to the linker.
1 parent 1988855 commit 421ed1b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,14 @@ if(SECP256K1_APPEND_CFLAGS)
276276
string(APPEND CMAKE_C_COMPILE_OBJECT " ${SECP256K1_APPEND_CFLAGS}")
277277
endif()
278278

279+
set(SECP256K1_APPEND_LDFLAGS "" CACHE STRING "Linker flags that are appended to the command line after all other flags added by the build system. This variable is intended for debugging and special builds.")
280+
if(SECP256K1_APPEND_LDFLAGS)
281+
# Appending to this low-level rule variable is the only way to
282+
# guarantee that the flags appear at the end of the command line.
283+
string(APPEND CMAKE_C_CREATE_SHARED_LIBRARY " ${SECP256K1_APPEND_LDFLAGS}")
284+
string(APPEND CMAKE_C_LINK_EXECUTABLE " ${SECP256K1_APPEND_LDFLAGS}")
285+
endif()
286+
279287
add_subdirectory(src)
280288
if(SECP256K1_BUILD_EXAMPLES)
281289
add_subdirectory(examples)
@@ -355,6 +363,9 @@ endif()
355363
if(SECP256K1_APPEND_CFLAGS)
356364
message("SECP256K1_APPEND_CFLAGS ............... ${SECP256K1_APPEND_CFLAGS}")
357365
endif()
366+
if(SECP256K1_APPEND_LDFLAGS)
367+
message("SECP256K1_APPEND_LDFLAGS .............. ${SECP256K1_APPEND_LDFLAGS}")
368+
endif()
358369
message("")
359370
if(print_msan_notice)
360371
message(

0 commit comments

Comments
 (0)