-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
54 lines (41 loc) · 1.38 KB
/
CMakeLists.txt
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
48
49
50
51
52
53
54
#####################
# START CMAKE SETUP #
#####################
cmake_minimum_required(VERSION 3.0)
project(libcp2p LANGUAGES C)
set(CMAKE_C_COMPILER /usr/bin/gcc)
# handle debug build type
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# -g indicates to include debug symbols
list(APPEND flags -std=c17 -Wall -Wextra -Werror -pedantic -g)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Analyze")
# override gcc compiler to v10 for static analysis
set(CMAKE_C_COMPILER /usr/bin/gcc-10)
list(APPEND flags -std=c17 -Wall -Wextra -Werror -pedantic -g -fanalyzer)
message(STATUS "enabling static analysis")
endif()
# handle ci build type
if(CMAKE_BUILD_TYPE STREQUAL "CI")
set(CMAKE_BUILD_TYPE "Release")
# override the previous C compiler choice
set(CMAKE_C_COMPILER /usr/bin/gcc-9)
endif()
# handle no build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
list(APPEND flags -std=c17 -Wall -Wextra -Werror -pedantic)
endif()
list(APPEND flags -D_POSIX_C_SOURCE=201112L)
add_library(libexample
SHARED
./example.c
)
target_compile_options(libexample PRIVATE ${flags})
add_executable(libexample-test ./example_test.c)
target_link_libraries(libexample-test cmocka)
target_link_libraries(libexample-test libexample)
add_executable(cli ./main.c)
target_link_libraries(cli libexample)
add_test(NAME LibExampleTest COMMAND libexample-test)
enable_testing()