Skip to content

Commit

Permalink
Rulat teste fara sanitizer
Browse files Browse the repository at this point in the history
  • Loading branch information
Duta-Sebastian committed Jan 13, 2025
1 parent 0d1e7eb commit 41c7273
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
16 changes: 14 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ cmake_minimum_required(VERSION 3.26)
set(MAIN_PROJECT_NAME "oop")
set(MAIN_EXECUTABLE_NAME "${MAIN_PROJECT_NAME}")
set(MAIN_PROJECT_LIB_NAME "${MAIN_PROJECT_NAME}_lib")
set(MAIN_PROJECT_NO_SAN_LIB_NAME "${MAIN_PROJECT_NAME}_nslib")
set(TESTS_PROJECT_NAME "${MAIN_PROJECT_NAME}_test")
set(TESTS_EXECUTABLE_NAME "${TESTS_PROJECT_NAME}")

Expand Down Expand Up @@ -63,13 +64,24 @@ target_include_directories(${MAIN_PROJECT_LIB_NAME} PUBLIC
exemplu_test_oop/
)

add_library(${MAIN_PROJECT_NO_SAN_LIB_NAME}
generated/src/Helper.cpp
exemplu_test_oop/BankAccount.cpp
)

target_include_directories(${MAIN_PROJECT_NO_SAN_LIB_NAME} PUBLIC
generated/include
exemplu_test_oop/
)


add_executable(${MAIN_EXECUTABLE_NAME}
main.cpp
)

# NOTE: Add all defined targets (e.g. executables, libraries, etc. )
set_compiler_flags(TARGET_NAMES ${MAIN_EXECUTABLE_NAME} ${MAIN_PROJECT_LIB_NAME})
set_compiler_flags(RUN_SANITIZERS FALSE TARGET_NAMES ${MAIN_PROJECT_NO_SAN_LIB_NAME})
# set_compiler_flags(TARGET_NAMES ${MAIN_EXECUTABLE_NAME} ${FOO} ${BAR})
# where ${FOO} and ${BAR} represent additional executables or libraries
# you want to compile with the set compiler flags
Expand All @@ -87,10 +99,10 @@ add_executable(${TESTS_EXECUTABLE_NAME}
${TEST_SOURCES_DIR}/test_simplu.cpp
)

target_link_libraries(${TESTS_EXECUTABLE_NAME} PRIVATE ${MAIN_PROJECT_LIB_NAME})
target_link_libraries(${TESTS_EXECUTABLE_NAME} PRIVATE ${MAIN_PROJECT_NO_SAN_LIB_NAME})
target_include_directories(${TESTS_EXECUTABLE_NAME} SYSTEM PRIVATE ${BOOST_UT_INCLUDE_DIR})

set_compiler_flags(TARGET_NAMES ${TESTS_EXECUTABLE_NAME})
set_compiler_flags(RUN_SANITIZERS FALSE TARGET_NAMES ${TESTS_EXECUTABLE_NAME})

add_test(NAME ${TESTS_EXECUTABLE_NAME} COMMAND ${TESTS_PROJECT_NAME})

Expand Down
10 changes: 8 additions & 2 deletions cmake/CompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ include(cmake/CustomStdlibAndSanitizers.cmake)

function(set_compiler_flags)
set(multiValueArgs TARGET_NAMES)
cmake_parse_arguments(PARSE_ARGV 0 ARG "" "" "${multiValueArgs}")
set(oneValueArgs RUN_SANITIZERS)
cmake_parse_arguments(PARSE_ARGV 0 ARG "" "${oneValueArgs}" "${multiValueArgs}")

if(NOT DEFINED ARG_RUN_SANITIZERS)
set(ARG_RUN_SANITIZERS TRUE)
endif()


# iterate over all specified targets
foreach (TARGET_NAME IN LISTS ARG_TARGET_NAMES)
Expand All @@ -30,7 +36,7 @@ function(set_compiler_flags)
###############################################################################

# sanitizers
if(NOT "${TARGET_NAME}" STREQUAL "${TESTS_EXECUTABLE_NAME}")
if("${ARG_RUN_SANITIZERS}" STREQUAL "TRUE")
set_custom_stdlib_and_sanitizers(${TARGET_NAME} true)
endif ()
endforeach ()
Expand Down

0 comments on commit 41c7273

Please sign in to comment.