Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# Build Options:
# BUILD_TESTS = ON/OFF
# BUILD_PY_LIB = ON/OFF
# SANITIZERS_ENABLED = ON/OFF
# Enables Undefined Behaviour Sanitizer for tests (if supported by toolchain)
#
# Generic Invocation:
# cmake -E make_directory buildprod
Expand Down
23 changes: 21 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,29 @@
# Modified by: Michael E. Tryby
# US EPA ORD/NRMRL
#

include(CheckCXXCompilerFlag)

# Sets for output directory for executables and libraries.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

if(UNIX)
set(CMAKE_CXX_FLAGS "-std=c++11")
set(CMAKE_CXX_FLAGS "-std=c++11 -g")
endif(UNIX)

# Check for UBSAN support
set(CMAKE_REQUIRED_FLAGS "-fsanitize=undefined")
set(CMAKE_REQUIRED_LINK_OPTIONS "-fsanitize=undefined")
check_cxx_source_compiles("int main() { return 0; }" SANITIZERS_SUPPORTED)
unset(CMAKE_REQUIRED_FLAGS)
unset(CMAKE_REQUIRED_LINK_OPTIONS)


add_executable(test_net_builder test_net_builder.cpp)
target_link_libraries(test_net_builder ${Boost_LIBRARIES} epanet2)
if(SANITIZERS_SUPPORTED AND SANITIZERS_ENABLED)
target_compile_options(test_net_builder PUBLIC -fsanitize=undefined)
target_link_options(test_net_builder PUBLIC -fsanitize=undefined)
endif()
add_test(NAME test_net_builder
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_net_builder
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data)
Expand Down Expand Up @@ -46,13 +57,21 @@ set(toolkit_test_srcs

add_executable(test_toolkit ${toolkit_test_srcs})
target_link_libraries(test_toolkit ${Boost_LIBRARIES} epanet2)
if(SANITIZERS_SUPPORTED AND SANITIZERS_ENABLED)
target_compile_options(test_toolkit PUBLIC -fsanitize=undefined)
target_link_options(test_toolkit PUBLIC -fsanitize=undefined)
endif()
add_test(NAME test_toolkit
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_toolkit
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data)



add_executable(test_reent test_reent.cpp)
if(SANITIZERS_SUPPORTED AND SANITIZERS_ENABLED)
target_compile_options(test_reent PUBLIC -fsanitize=undefined)
target_link_options(test_reent PUBLIC -fsanitize=undefined)
endif()

IF(MSVC)
target_link_libraries(test_reent ${Boost_LIBRARIES} epanet2)
Expand Down
21 changes: 20 additions & 1 deletion tests/util/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
include(CheckCXXCompilerFlag)

# Check for UBSAN support
set(CMAKE_REQUIRED_FLAGS "-fsanitize=undefined")
set(CMAKE_REQUIRED_LINK_OPTIONS "-fsanitize=undefined")
check_cxx_source_compiles("int main() { return 0; }" SANITIZERS_SUPPORTED)
unset(CMAKE_REQUIRED_FLAGS)
unset(CMAKE_REQUIRED_LINK_OPTIONS)

if(UNIX)
set(CMAKE_CXX_FLAGS "-std=c++11")
Expand All @@ -13,16 +21,27 @@ add_executable(test_cstrhelper ./test_cstrhelper.cpp
../../src/util/cstr_helper.c)
target_include_directories(test_cstrhelper PUBLIC ../../src/)
target_link_libraries(test_cstrhelper ${Boost_LIBRARIES})
if(SANITIZERS_SUPPORTED AND SANITIZERS_ENABLED)
target_compile_options(test_cstrhelper PUBLIC -fsanitize=undefined)
target_link_options(test_cstrhelper PUBLIC -fsanitize=undefined)
endif()


add_executable(test_errormanager ./test_errormanager.cpp
../../src/util/errormanager.c)
target_include_directories(test_errormanager PUBLIC ../../src/)
target_link_libraries(test_errormanager ${Boost_LIBRARIES})

if(SANITIZERS_SUPPORTED AND SANITIZERS_ENABLED)
target_compile_options(test_errormanager PUBLIC -fsanitize=undefined)
target_link_options(test_errormanager PUBLIC -fsanitize=undefined)
endif()

add_executable(test_filemanager ./test_filemanager.cpp
../../src/util/filemanager.c
../../src/util/cstr_helper.c)
target_include_directories(test_filemanager PUBLIC ../../src/)
target_link_libraries(test_filemanager ${Boost_LIBRARIES})
if(SANITIZERS_SUPPORTED AND SANITIZERS_ENABLED)
target_compile_options(test_filemanager PUBLIC -fsanitize=undefined)
target_link_options(test_filemanager PUBLIC -fsanitize=undefined)
endif()