Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! General CMakeLists improvements - …
Browse files Browse the repository at this point in the history
…cmake v2→v3

Fixing how tests clean EXPORT_SYMBOLS
  • Loading branch information
kheaactua committed Jan 10, 2025
1 parent 722fa96 commit bf943c5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
14 changes: 12 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ if(ENABLE_WERROR)
add_compile_options(-Werror)
endif()

# Variable to store compiler options used to export settings. These are stored
# in a variable such that they can be easily removed in test apps (see
# test/CMakeLists.txt)
set(EXPORTSYMBOLS)

if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(OS "LINUX")
target_link_libraries(DL_INTERFACE INTERFACE dl)
Expand Down Expand Up @@ -153,12 +158,17 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# This is only relevant for GCC and causes warnings on Clang

set(EXPORTSYMBOLS
-Wl,-export-dynamic
-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exportmap.gcc
)

target_link_options(
OS_INTERFACE
INTERFACE
-Wl,-z,relro,-z,now
-Wl,-export-dynamic
-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exportmap.gcc
${EXPORTSYMBOLS}
)
endif()
target_link_options(OS_INTERFACE INTERFACE -Wl,--wrap=socket,--wrap=accept,--wrap=open)
Expand Down
6 changes: 2 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ find_package(benchmark)

# remove export symbols from the cxx flags. This is messy, but there's no `remove_link_flags` function
get_target_property(os_link_options OS_INTERFACE INTERFACE_LINK_OPTIONS)
foreach(opt IN ITEMS ${os_link_options})
if(opt MATCHES ".*version.script.*.gcc")
list(REMOVE_ITEM os_link_options ${opt})
endif()
foreach(opt IN ITEMS ${EXPORTSYMBOLS})
list(REMOVE_ITEM os_link_options ${opt})
endforeach()
unset(opt)
if(os_link_options)
Expand Down

0 comments on commit bf943c5

Please sign in to comment.