forked from czertyaka/prosoft-c-stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
48 lines (42 loc) · 1.41 KB
/
CMakeLists.txt
File metadata and controls
48 lines (42 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
cmake_minimum_required(VERSION 3.22)
project(cstack)
enable_testing()
option(WITH_TEST "Build test (GTest library required)" OFF)
# build library
add_library(cstack STATIC cstack.c)
# build test
if (WITH_TEST)
enable_testing()
add_executable(cstack_test test.cpp)
target_link_libraries(cstack_test cstack)
add_test(NAME cstack_test COMMAND cstack_test)
# link with googletest
find_package(GTest)
if (NOT ${GTest_FOUND})
include(cmake/gtest.cmake)
endif()
target_link_libraries(cstack_test
GTest::gtest
GTest::gtest_main
GTest::gmock
GTest::gmock_main
)
endif()
# compiler-specific project settings
if (MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(MSVC_FLAGS /Wall /WX)
target_compile_options(cstack PRIVATE ${MSVC_FLAGS})
target_link_options(cstack PRIVATE ${MSVC_FLAGS})
if (WITH_TEST)
target_compile_options(cstack_test PRIVATE /fsanitize=address)
target_compile_definitions(cstack_test PRIVATE _DISABLE_VECTOR_ANNOTATION)
endif()
else()
target_compile_options(cstack PRIVATE -Wall -Wextra -Wformat -Wformat-security -Werror)
set(SANITIZERS_FLAGS -fsanitize=undefined -fsanitize=address)
if (WITH_TEST)
target_compile_options(cstack_test PRIVATE ${SANITIZERS_FLAGS})
target_link_options(cstack_test PRIVATE ${SANITIZERS_FLAGS})
endif()
endif()