2022-03-04 12:04:38 +01:00
cmake_minimum_required ( VERSION 3.10 )
if ( ${ CMAKE_VERSION } VERSION_LESS 3.10 )
cmake_policy ( VERSION ${ CMAKE_MAJOR_VERSION } . ${ CMAKE_MINOR_VERSION } )
endif ( )
# project information
project ( unit_tests
V E R S I O N 0 . 1
D E S C R I P T I O N " U n i t t e s t s f o r C p r o j e c t "
L A N G U A G E S C )
# guard against bad build-type strings
if ( NOT CMAKE_BUILD_TYPE )
set ( CMAKE_BUILD_TYPE "Debug" )
endif ( )
include ( CTest )
ENABLE_TESTING ( )
# specify C standard
set ( CMAKE_C_STANDARD 11 )
set ( CMAKE_C_STANDARD_REQUIRED True )
set ( CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -pedantic -g -O0 --coverage" )
set ( GCC_COVERAGE_LINK_FLAGS "--coverage -lgcov" )
set ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}" )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}" )
# guard against in-source builds
if ( ${ CMAKE_SOURCE_DIR } STREQUAL ${ CMAKE_BINARY_DIR } )
message ( FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt. " )
endif ( )
# Fetch cmocka
find_package ( cmocka QUIET )
include ( FetchContent )
FetchContent_Declare (
c m o c k a
G I T _ R E P O S I T O R Y h t t p s : / / g i t . c r y p t o m i l k . o r g / p r o j e c t s / c m o c k a . g i t
G I T _ T A G c m o c k a - 1 . 1 . 5
G I T _ S H A L L O W 1
)
set ( WITH_STATIC_LIB ON CACHE BOOL "CMocka: Build with a static library" FORCE )
set ( WITH_CMOCKERY_SUPPORT OFF CACHE BOOL "CMocka: Install a cmockery header" FORCE )
set ( WITH_EXAMPLES OFF CACHE BOOL "CMocka: Build examples" FORCE )
set ( UNIT_TESTING OFF CACHE BOOL "CMocka: Build with unit testing" FORCE )
set ( PICKY_DEVELOPER OFF CACHE BOOL "CMocka: Build with picky developer flags" FORCE )
FetchContent_MakeAvailable ( cmocka )
add_compile_definitions ( TEST DEBUG=0 SKIP_FOR_CMOCKA )
include_directories ( ../../src/ )
2022-07-20 15:40:01 +02:00
# add cmocka tests
add_executable ( test_demo tests/demo.c )
2022-03-04 12:04:38 +01:00
2022-07-20 15:40:01 +02:00
# add src
add_library ( demo SHARED ./demo_tu.c )
2022-03-04 12:04:38 +01:00
2022-07-20 15:40:01 +02:00
target_link_libraries ( test_demo PUBLIC cmocka gcov demo )
2022-03-04 12:04:38 +01:00
2024-03-18 17:28:51 +01:00
add_test ( test_demo test_demo )