Skip to content

Commit

Permalink
fix cmake: sanitize filter for install
Browse files Browse the repository at this point in the history
sanitize filter for install

Tests: протестировано CI
990ba52b450ff78950a107415901e618a94c7b8c
alexiprof committed Feb 19, 2024
1 parent e8ddf5c commit 8b4e3a0
Showing 4 changed files with 46 additions and 19 deletions.
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -118,9 +118,6 @@ if(USERVER_INSTALL)
include(GNUInstallDirs)
endif()

include(Sanitizers)
_userver_make_sanitize_target()

include(GetUserverVersion)
include(AddGoogleTests)
include(CheckSubmodule)
57 changes: 42 additions & 15 deletions cmake/Sanitizers.cmake
Original file line number Diff line number Diff line change
@@ -2,6 +2,29 @@ include_guard(GLOBAL)

set_property(GLOBAL PROPERTY userver_cmake_dir "${CMAKE_CURRENT_LIST_DIR}")

function(_userver_get_sanitize_blacklist_file COMPILE_FLAGS_BL LINK_FLAGS_BL)
set(sanitize_cxx_flags)
set(sanitize_link_flags)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT USERVER_INSTALL)
set(USERVER_BLACKLIST "${USERVER_CMAKE_DIR}/sanitize.blacklist.txt")
list(APPEND sanitize_cxx_flags "-fsanitize-blacklist=${USERVER_BLACKLIST}")
list(APPEND sanitize_link_flags "-fsanitize-blacklist=${USERVER_BLACKLIST}")

set(USERVER_MACOS_BLACKLIST "${USERVER_CMAKE_DIR}/sanitize-macos.blacklist.txt")
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
list(APPEND sanitize_cxx_flags "-fsanitize-blacklist=${USERVER_MACOS_BLACKLIST}")
list(APPEND sanitize_link_flags "-fsanitize-blacklist=${USERVER_MACOS_BLACKLIST}")
endif()

if (USERVER_SANITIZE_BLACKLIST)
list(APPEND sanitize_cxx_flags "-fsanitize-blacklist=${USERVER_SANITIZE_BLACKLIST}")
list(APPEND sanitize_link_flags "-fsanitize-blacklist=${USERVER_SANITIZE_BLACKLIST}")
endif()
endif()
set("${COMPILE_FLAGS_BL}" ${sanitize_cxx_flags} PARENT_SCOPE)
set("${LINK_FLAGS_BL}" ${sanitize_link_flags} PARENT_SCOPE)
endfunction()

function(_userver_get_sanitize_options SANITIZER_LIST_VAR COMPILE_FLAGS_VAR LINK_FLAGS_VAR)
get_property(USERVER_CMAKE_DIR GLOBAL PROPERTY userver_cmake_dir)

@@ -26,21 +49,10 @@ function(_userver_get_sanitize_options SANITIZER_LIST_VAR COMPILE_FLAGS_VAR LINK
set(sanitizer_list)

if (USERVER_SANITIZE AND sanitizers_supported)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(USERVER_BLACKLIST "${USERVER_CMAKE_DIR}/sanitize.blacklist.txt")
list(APPEND sanitize_cxx_flags "-fsanitize-blacklist=${USERVER_BLACKLIST}")
list(APPEND sanitize_link_flags "-fsanitize-blacklist=${USERVER_BLACKLIST}")

set(USERVER_MACOS_BLACKLIST "${USERVER_CMAKE_DIR}/sanitize-macos.blacklist.txt")
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
list(APPEND sanitize_cxx_flags "-fsanitize-blacklist=${USERVER_MACOS_BLACKLIST}")
list(APPEND sanitize_link_flags "-fsanitize-blacklist=${USERVER_MACOS_BLACKLIST}")
endif()

if (USERVER_SANITIZE_BLACKLIST)
list(APPEND sanitize_cxx_flags "-fsanitize-blacklist=${USERVER_SANITIZE_BLACKLIST}")
list(APPEND sanitize_link_flags "-fsanitize-blacklist=${USERVER_SANITIZE_BLACKLIST}")
endif()
if(NOT USERVER_INSTALL)
_userver_get_sanitize_blacklist_file(compile_flags_bl link_flags_bl)
list(APPEND sanitize_cxx_flags ${compile_flags_bl})
list(APPEND sanitize_link_flags ${link_flags_bl})
endif()

set(sanitizer_list ${USERVER_SANITIZE})
@@ -104,3 +116,18 @@ function(_userver_make_sanitize_target)
${sanitize_link_flags}
)
endfunction()

# We mush use this function only in install
function(_userver_make_sanitize_blacklist)
if (NOT TARGET userver::userver-internal-sanitize-options)
message(FATAL_ERROR "target userver-internal-sanitize-options not defined")
return()
endif()
_userver_get_sanitize_blacklist_file(compile_flags_bl link_flags_bl)
target_compile_options(userver::userver-internal-sanitize-options INTERFACE
${compile_flags_bl}
)
target_link_libraries(userver::userver-internal-sanitize-options INTERFACE
${link_flags_bl}
)
endfunction()
2 changes: 1 addition & 1 deletion cmake/install/userver-universal-config.cmake
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ include("${USERVER_CMAKE_DIR}/Sanitizers.cmake")
include("${USERVER_CMAKE_DIR}/SetupLTO.cmake")
include("${USERVER_CMAKE_DIR}/SetupLinker.cmake")

_userver_make_sanitize_target()
_userver_make_sanitize_blacklist()

add_library(userver::universal ALIAS userver::userver-universal)

3 changes: 3 additions & 0 deletions universal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -8,6 +8,9 @@ if (TARGET userver-core)
message(FATAL_ERROR "userver-core should be included after userver-universal")
endif()

include(Sanitizers)
_userver_make_sanitize_target()

file(GLOB_RECURSE SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/*.hpp

0 comments on commit 8b4e3a0

Please sign in to comment.