-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from NeoResearch/38_fix_tests
Fix unit tests build
- Loading branch information
Showing
35 changed files
with
1,889 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,5 @@ vendor/ | |
*.dot | ||
*.png | ||
*.o | ||
#*.pb.cc | ||
#*.pb.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
MACRO(ADD_MY_DEFINITIONS) | ||
message(STATUS "Adding definitiions") | ||
# https://developers.redhat.com/blog/2018/03/21/compiler-and-linker-flags-gcc/ | ||
# https://caiorss.github.io/C-Cpp-Notes/compiler-flags-options.html | ||
add_definitions(-std=c++17) | ||
#add_definitions(-fconcepts) | ||
add_definitions(-fpermissive) | ||
add_definitions(-fasynchronous-unwind-tables) | ||
|
||
#add_definitions(-fno-rtti) | ||
add_definitions(-pedantic-errors) | ||
add_definitions(-pipe) | ||
|
||
add_definitions(-W) | ||
add_definitions(-Wall) | ||
add_definitions(-Wconversion) | ||
add_definitions(-Wcast-align) | ||
add_definitions(-Wextra) | ||
#add_definitions(-Werror) | ||
add_definitions(-Werror=format-security) | ||
add_definitions(-Werror=implicit-function-declaration) | ||
add_definitions(-Wpedantic) | ||
add_definitions(-Wno-long-long) | ||
add_definitions(-Wno-missing-braces) | ||
add_definitions(-Wno-parentheses) | ||
add_definitions(-Wno-switch) | ||
add_definitions(-Wno-unused-parameter) | ||
add_definitions(-Wold-style-cast) | ||
add_definitions(-Wpointer-arith) | ||
add_definitions(-Wshadow) | ||
#add_definitions(-Wswitch-default) | ||
#add_definitions(-Wswitch-enum) | ||
add_definitions(-Wcast-qual) | ||
#add_definitions(-Wundef) | ||
add_definitions(-Wunused) | ||
add_definitions(-Wunreachable-code) | ||
add_definitions(-Wunused-function) | ||
add_definitions(-Wunused-variable) | ||
add_definitions(-Wwrite-strings) | ||
|
||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-prototypes") | ||
|
||
string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type) | ||
if (build_type STREQUAL "debug") | ||
message(STATUS "--- Debug build ---") | ||
add_definitions(-g) | ||
add_definitions(-grecord-gcc-switches) | ||
# add_definitions(-D_GLIBCXX_DEBUG) # Not sure why it's breaking the mainRPC.cpp build | ||
# add_definitions(-D_GLIBCXX_DEBUG_PEDANTIC) # Not sure why it's breaking the mainRPC.cpp build | ||
add_definitions(-D_FORTIFY_SOURCE=2) | ||
add_definitions(-D_GLIBCXX_ASSERTIONS) | ||
add_definitions(-ggdb) | ||
add_definitions(-O0) | ||
add_definitions(-fstack-protector-all) | ||
|
||
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined") | ||
else () | ||
message(STATUS "--- Release build ---") | ||
add_definitions(-O3) | ||
# add_definitions(-Ofast) | ||
add_definitions(-finline-functions) | ||
add_definitions(-funroll-loops) | ||
|
||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -frecursive") | ||
endif () | ||
ENDMACRO() | ||
|
||
MACRO(ADD_TEST_DEFINITIONS) | ||
message(STATUS "Adding test definitions") | ||
|
||
string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type) | ||
if (build_type STREQUAL "debug") | ||
message(STATUS "--- Debug build ---") | ||
message(STATUS "Adding sanitizer") | ||
add_definitions(-fsanitize=address) | ||
add_definitions(-fsanitize=alignment) | ||
add_definitions(-fsanitize=bool) | ||
add_definitions(-fsanitize=bounds) | ||
add_definitions(-fsanitize=bounds-strict) | ||
add_definitions(-fsanitize=builtin) | ||
add_definitions(-fsanitize=enum) | ||
add_definitions(-fsanitize=float-divide-by-zero) | ||
add_definitions(-fsanitize=float-cast-overflow) | ||
add_definitions(-fsanitize=integer-divide-by-zero) | ||
add_definitions(-fsanitize=leak) | ||
# add_definitions(-fsanitize=kernel-address) | ||
add_definitions(-fsanitize=nonnull-attribute) | ||
add_definitions(-fsanitize=null) | ||
add_definitions(-fsanitize=object-size) | ||
add_definitions(-fsanitize=pointer-compare) | ||
add_definitions(-fsanitize=pointer-overflow) | ||
add_definitions(-fsanitize=pointer-subtract) | ||
add_definitions(-fsanitize=return) | ||
add_definitions(-fsanitize=returns-nonnull-attribute) | ||
add_definitions(-fsanitize=signed-integer-overflow) | ||
add_definitions(-fsanitize=shift) | ||
add_definitions(-fsanitize=shift-base) | ||
add_definitions(-fsanitize=shift-exponent) | ||
# add_definitions(-fsanitize=thread) | ||
add_definitions(-fsanitize=undefined) | ||
add_definitions(-fsanitize=unreachable) | ||
add_definitions(-fsanitize=vla-bound) | ||
add_definitions(-fsanitize=vptr) | ||
endif () | ||
ENDMACRO() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
MACRO(SUBDIRLIST result curdir) | ||
FILE(GLOB children RELATIVE ${curdir} ${curdir}/*) | ||
SET(dirlist "") | ||
FOREACH (child ${children}) | ||
IF (IS_DIRECTORY ${curdir}/${child} AND EXISTS ${curdir}/${child}/CMakeLists.txt) | ||
LIST(APPEND dirlist ${child}) | ||
ENDIF () | ||
ENDFOREACH () | ||
SET(${result} ${dirlist}) | ||
ENDMACRO() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#================================================================# | ||
# Protobuf code generation | ||
#================================================================# | ||
find_package(Protobuf REQUIRED) | ||
|
||
#include_directories(protos) | ||
|
||
#file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR} PROTOMODEL_PATH) | ||
#file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${PROTOBUF_GENERATED_PATH} PROTOBINDING_PATH) | ||
|
||
MACRO(GENERATE_PROTO proto) | ||
file(TO_NATIVE_PATH ${proto} proto_native) | ||
message(STATUS "Generating Protobuf ${proto}") | ||
execute_process( | ||
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} | ||
# --proto_path=${PROTOMODEL_PATH} | ||
--proto_path=${CMAKE_CURRENT_SOURCE_DIR} | ||
# --cpp_out=${PROTOBINDING_PATH} ${proto_native} | ||
--cpp_out=${CMAKE_CURRENT_SOURCE_DIR} ${proto_native} | ||
RESULT_VARIABLE rv | ||
) | ||
|
||
execute_process( | ||
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} | ||
# --proto_path=${PROTOMODEL_PATH} | ||
--proto_path=${CMAKE_CURRENT_SOURCE_DIR} | ||
# --grpc_out=${PROTOBINDING_PATH} | ||
--grpc_out=${CMAKE_CURRENT_SOURCE_DIR} | ||
--plugin=protoc-gen-grpc=${GRPC_PLUGIN_CPP} ${proto_native} | ||
RESULT_VARIABLE rv | ||
) | ||
ENDMACRO() | ||
|
||
MACRO(target_link_libraries_proto name) | ||
# find_package(gRPC CONFIG REQUIRED) | ||
# find_package(Protobuf REQUIRED) | ||
target_link_libraries( | ||
${name} | ||
protobuf | ||
pthread | ||
# gRPC::grpc++ | ||
grpc++ | ||
grpc++_reflection | ||
dl | ||
m | ||
rt | ||
${_GRPC_GRPCPP_UNSECURE} | ||
${_PROTOBUF_LIBPROTOBUF} | ||
) | ||
ENDMACRO() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
MACRO(ADD_TEST_ALL_FILES asan) | ||
get_filename_component(test_name ${CMAKE_CURRENT_SOURCE_DIR} NAME) | ||
|
||
if (${asan} STREQUAL "ON") | ||
message(STATUS "Adding address sanitizer to ${test_name}") | ||
ADD_TEST_DEFINITIONS() | ||
else () | ||
message(STATUS "No address sanitizer to ${test_name}") | ||
endif () | ||
message(STATUS "Creating test ${test_name}") | ||
|
||
file(GLOB_RECURSE test_sources *) | ||
list(FILTER test_sources INCLUDE REGEX "cpp$") | ||
|
||
set(lib_name "${PROJECT_NAME}_${PROJECT_VERSION}") | ||
|
||
add_executable( | ||
"${test_name}_test" | ||
${test_sources} | ||
) | ||
|
||
target_link_libraries( | ||
"${test_name}_test" | ||
${lib_name} | ||
gtest | ||
gtest_main | ||
${CMAKE_THREAD_LIBS_INIT} | ||
) | ||
|
||
if (${asan} STREQUAL "ON") | ||
target_link_libraries("${test_name}_test" asan) | ||
endif () | ||
|
||
target_link_libraries("${test_name}_test" ${lib_name}) | ||
include_directories(${CMAKE_SOURCE_DIR}/src) | ||
|
||
message(STATUS "Adding test: ${test_name}_test") | ||
add_test(NAME "${test_name}_test_caller" COMMAND "${test_name}_test") | ||
|
||
target_compile_options("${test_name}_test" PRIVATE --coverage) | ||
target_link_libraries("${test_name}_test" --coverage) | ||
ENDMACRO() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.