2019-03-23 02:24:51 +08:00
|
|
|
cmake_minimum_required(VERSION 3.3)
|
|
|
|
|
2022-06-11 01:27:38 +08:00
|
|
|
enable_testing()
|
|
|
|
|
2019-03-23 02:24:51 +08:00
|
|
|
project(minmea)
|
|
|
|
|
2022-06-03 05:09:17 +08:00
|
|
|
find_package(Threads REQUIRED) # Workaround for https://github.com/libcheck/check/issues/48#issuecomment-322965461
|
|
|
|
find_package(PkgConfig)
|
|
|
|
pkg_check_modules(CHECK REQUIRED check)
|
2022-06-11 01:19:54 +08:00
|
|
|
link_directories(${CHECK_LIBRARY_DIRS})
|
2022-06-03 05:09:17 +08:00
|
|
|
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Wextra -Werror -std=c99")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_POSIX_C_SOURCE=199309L -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_DARWIN_C_SOURCE")
|
|
|
|
|
|
|
|
set(minmea_SRCS minmea.c minmea.h)
|
|
|
|
add_library(minmea ${minmea_SRCS})
|
2022-06-11 01:28:53 +08:00
|
|
|
|
2022-06-03 05:09:17 +08:00
|
|
|
add_executable(example example.c)
|
|
|
|
target_link_libraries(example minmea)
|
2022-06-11 01:28:53 +08:00
|
|
|
|
|
|
|
add_executable(tests tests.c)
|
2022-06-03 05:09:17 +08:00
|
|
|
target_link_libraries(tests minmea ${CHECK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
|
|
|
|
target_include_directories(tests PUBLIC ${CHECK_INCLUDE_DIRS})
|
|
|
|
target_compile_options(tests PUBLIC ${CHECK_CFLAGS_OTHER})
|
2022-06-11 01:27:38 +08:00
|
|
|
|
|
|
|
add_test(NAME tests COMMAND $<TARGET_FILE:tests>)
|
2022-08-04 18:38:30 +08:00
|
|
|
list(APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure")
|
2022-06-11 01:43:39 +08:00
|
|
|
|
|
|
|
find_program(SCAN_FOUND scan-build)
|
|
|
|
|
|
|
|
if (SCAN_FOUND)
|
|
|
|
add_test(
|
|
|
|
NAME clang_static_analysis
|
|
|
|
COMMAND scan-build make
|
|
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
MESSAGE(STATUS "scan-build not found, not scanning code")
|
|
|
|
endif()
|