2020-11-11 01:19:49 +03:00
|
|
|
cmake_minimum_required(VERSION 3.5.1)
|
|
|
|
project(sc_queue C)
|
|
|
|
|
|
|
|
set(CMAKE_C_STANDARD 99)
|
|
|
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
|
|
|
set(CMAKE_C_EXTENSIONS OFF)
|
|
|
|
|
2021-02-13 19:37:52 -03:00
|
|
|
add_library(
|
2021-02-24 18:37:21 +03:00
|
|
|
sc_queue SHARED
|
|
|
|
sc_queue.c
|
|
|
|
sc_queue.h)
|
2021-02-13 19:37:52 -03:00
|
|
|
|
|
|
|
target_include_directories(sc_queue PUBLIC ${CMAKE_CURRENT_LIST_DIR})
|
2020-11-11 01:19:49 +03:00
|
|
|
|
|
|
|
if (NOT CMAKE_C_COMPILER_ID MATCHES "MSVC")
|
2021-02-07 22:31:04 +03:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Wextra -pedantic -Werror")
|
2020-11-11 01:19:49 +03:00
|
|
|
endif ()
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# --------------------- Test Configuration Start ---------------------------- #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2021-02-24 18:37:21 +03:00
|
|
|
if (SC_BUILD_TEST)
|
2020-11-11 01:19:49 +03:00
|
|
|
|
2021-02-24 18:37:21 +03:00
|
|
|
include(CTest)
|
|
|
|
include(CheckCCompilerFlag)
|
2020-11-11 01:19:49 +03:00
|
|
|
|
2021-02-24 18:37:21 +03:00
|
|
|
if (SC_CLANG_TIDY)
|
|
|
|
message(STATUS "Enabled CLANG_TIDY")
|
2020-11-11 01:19:49 +03:00
|
|
|
|
2021-02-24 18:37:21 +03:00
|
|
|
set(CMAKE_C_CLANG_TIDY
|
|
|
|
clang-tidy;
|
|
|
|
-line-filter=[{"name":"${PROJECT_NAME}.h"},{"name":"${PROJECT_NAME}.c"}];
|
|
|
|
-checks=clang-analyzer-*,misc-*,portability-*,bugprone-*;
|
|
|
|
-warnings-as-errors=clang-analyzer-*,misc-*,portability-*,bugprone-*;)
|
|
|
|
endif ()
|
2020-11-11 01:19:49 +03:00
|
|
|
|
2021-02-24 18:37:21 +03:00
|
|
|
enable_testing()
|
2020-11-11 01:19:49 +03:00
|
|
|
|
2021-02-24 18:37:21 +03:00
|
|
|
add_executable(${PROJECT_NAME}_test queue_test.c sc_queue.c)
|
2020-11-11 01:19:49 +03:00
|
|
|
|
2021-04-07 04:55:05 +03:00
|
|
|
target_compile_options(${PROJECT_NAME}_test PRIVATE -DSC_QUEUE_MAX=1400000ul)
|
2020-11-11 01:19:49 +03:00
|
|
|
|
2021-02-24 18:37:21 +03:00
|
|
|
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
|
|
|
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR
|
|
|
|
"${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
|
2020-11-11 01:19:49 +03:00
|
|
|
|
2021-02-24 18:37:21 +03:00
|
|
|
target_compile_options(${PROJECT_NAME}_test PRIVATE -fno-omit-frame-pointer)
|
|
|
|
target_compile_options(${PROJECT_NAME}_test PRIVATE -DSC_HAVE_WRAP)
|
|
|
|
target_compile_options(${PROJECT_NAME}_test PRIVATE -fno-builtin)
|
|
|
|
target_link_options(${PROJECT_NAME}_test PRIVATE -Wl,--wrap=realloc)
|
|
|
|
endif ()
|
|
|
|
endif ()
|
2020-11-11 01:19:49 +03:00
|
|
|
|
2021-02-24 18:37:21 +03:00
|
|
|
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR
|
|
|
|
"${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang" OR
|
|
|
|
"${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
|
2020-11-11 01:19:49 +03:00
|
|
|
|
2021-02-24 18:37:21 +03:00
|
|
|
target_compile_options(${PROJECT_NAME}_test PRIVATE -fno-omit-frame-pointer)
|
2020-11-11 01:19:49 +03:00
|
|
|
|
2021-02-24 18:37:21 +03:00
|
|
|
if (SANITIZER)
|
|
|
|
target_compile_options(${PROJECT_NAME}_test PRIVATE -fsanitize=${SANITIZER})
|
|
|
|
target_link_options(${PROJECT_NAME}_test PRIVATE -fsanitize=${SANITIZER})
|
|
|
|
endif ()
|
|
|
|
endif ()
|
2020-11-11 01:19:49 +03:00
|
|
|
|
2021-02-24 18:37:21 +03:00
|
|
|
|
|
|
|
add_test(NAME ${PROJECT_NAME}_test COMMAND ${PROJECT_NAME}_test)
|
|
|
|
|
|
|
|
SET(MEMORYCHECK_COMMAND_OPTIONS
|
|
|
|
"-q --log-fd=2 --trace-children=yes --track-origins=yes \
|
2021-02-14 13:49:21 -03:00
|
|
|
--leak-check=full --show-leak-kinds=all \
|
|
|
|
--error-exitcode=255")
|
2020-11-11 01:19:49 +03:00
|
|
|
|
2021-02-24 18:37:21 +03:00
|
|
|
add_custom_target(valgrind_${PROJECT_NAME} ${CMAKE_COMMAND}
|
|
|
|
-E env CTEST_OUTPUT_ON_FAILURE=1
|
|
|
|
${CMAKE_CTEST_COMMAND} -C $<CONFIG>
|
|
|
|
--overwrite MemoryCheckCommandOptions=${MEMORYCHECK_COMMAND_OPTIONS}
|
|
|
|
--verbose -T memcheck WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
|
|
|
|
|
|
|
add_custom_target(check_${PROJECT_NAME} ${CMAKE_COMMAND}
|
|
|
|
-E env CTEST_OUTPUT_ON_FAILURE=1
|
|
|
|
${CMAKE_CTEST_COMMAND} -C $<CONFIG> --verbose
|
|
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
|
|
|
|
|
|
|
# ----------------------- - Code Coverage Start ----------------------------- #
|
|
|
|
|
|
|
|
if (${CMAKE_BUILD_TYPE} MATCHES "Coverage")
|
|
|
|
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
|
|
|
|
target_compile_options(${PROJECT_NAME}_test PRIVATE --coverage)
|
|
|
|
target_link_libraries(${PROJECT_NAME}_test gcov)
|
|
|
|
else ()
|
|
|
|
message(FATAL_ERROR "Only GCC is supported for coverage")
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
add_custom_target(coverage_${PROJECT_NAME})
|
|
|
|
add_custom_command(
|
|
|
|
TARGET coverage_${PROJECT_NAME}
|
|
|
|
COMMAND lcov --capture --directory .
|
|
|
|
--output-file coverage.info --rc lcov_branch_coverage=1 --rc lcov_excl_br_line='assert'
|
|
|
|
COMMAND lcov --remove coverage.info '/usr/*' '*example*' '*test*'
|
|
|
|
--output-file coverage.info --rc lcov_branch_coverage=1 --rc lcov_excl_br_line='assert'
|
|
|
|
COMMAND lcov --list coverage.info --rc lcov_branch_coverage=1 --rc lcov_excl_br_line='assert'
|
|
|
|
)
|
|
|
|
|
|
|
|
add_dependencies(coverage_${PROJECT_NAME} check_${PROJECT_NAME})
|
|
|
|
|
|
|
|
# -------------------------- Code Coverage End ------------------------------ #
|
2021-02-14 13:49:21 -03:00
|
|
|
endif ()
|
2020-11-11 01:19:49 +03:00
|
|
|
# ----------------------- Test Configuration End ---------------------------- #
|
|
|
|
|