1
1
cmake_minimum_required ( VERSION 3.13.0 )
2
- project ( "coreSNTP unit test"
2
+ project ( "coreSNTP tests"
3
+ VERSION 1.2.0
3
4
LANGUAGES C )
4
5
5
6
# Allow the project to be organized into folders.
@@ -9,6 +10,13 @@ set_property( GLOBAL PROPERTY USE_FOLDERS ON )
9
10
set ( CMAKE_C_STANDARD 90 )
10
11
set ( CMAKE_C_STANDARD_REQUIRED ON )
11
12
13
+ # If no configuration is defined, turn everything on.
14
+ if ( NOT DEFINED COV_ANALYSIS AND NOT DEFINED UNITTEST AND NOT DEFINED BUILD_CODE_EXAMPLE )
15
+ set ( COV_ANALYSIS ON )
16
+ set ( UNITTEST ON )
17
+ set ( BUILD_CODE_EXAMPLE ON )
18
+ endif ()
19
+
12
20
# Do not allow in-source build.
13
21
if ( ${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR} )
14
22
message ( FATAL_ERROR "In-source build is not allowed. Please build in a separate directory, such as ${PROJECT_SOURCE_DIR} /build." )
@@ -30,42 +38,51 @@ set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
30
38
set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /lib )
31
39
set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /lib )
32
40
33
- # ================================ Coverity Analysis Configuration =================================
34
-
35
41
# Include filepaths for source and include.
36
42
include ( ${MODULE_ROOT_DIR} /coreSntpFilePaths.cmake )
37
43
38
- # Target for Coverity analysis that builds the library.
39
- add_library ( coverity_analysis
40
- ${CORE_SNTP_SOURCES} )
44
+ # ================================ Coverity Analysis Configuration =================================
45
+
46
+ if ( COV_ANALYSIS )
41
47
42
- # Add coreSNTP library public include path.
43
- target_include_directories ( coverity_analysis
44
- PUBLIC
45
- ${CORE_SNTP_INCLUDE_PUBLIC_DIRS} )
48
+ # Target for Coverity analysis that builds the library.
49
+ add_library ( coverity_analysis
50
+ ${CORE_SNTP_SOURCES} )
51
+
52
+ # Add coreSNTP library public include path.
53
+ target_include_directories ( coverity_analysis
54
+ PUBLIC
55
+ ${CORE_SNTP_INCLUDE_PUBLIC_DIRS} )
46
56
47
- # Build SNTP library target without custom config dependency.
48
- target_compile_definitions ( coverity_analysis PUBLIC SNTP_DO_NOT_USE_CUSTOM_CONFIG=1 )
57
+ # Build SNTP library target without custom config dependency.
58
+ target_compile_definitions ( coverity_analysis PUBLIC SNTP_DO_NOT_USE_CUSTOM_CONFIG=1 )
49
59
50
- # Build without debug enabled when performing static analysis
51
- target_compile_options (coverity_analysis PUBLIC -DNDEBUG )
60
+ # Build without debug enabled when performing static analysis
61
+ target_compile_options (coverity_analysis PUBLIC -DNDEBUG )
62
+ endif ()
52
63
53
64
# ==================================== Code Example Build ====================================
54
65
55
- if (${ BUILD_CODE_EXAMPLE} )
66
+ if ( BUILD_CODE_EXAMPLE )
56
67
# Target for Coverity analysis that builds the library.
57
68
add_executable ( code_example_posix
69
+ ${CORE_SNTP_SOURCES}
58
70
${MODULE_ROOT_DIR} /docs/doxygen/code_examples/example_sntp_client_posix.c )
59
71
60
- # Add coreSNTP library public include path.
61
- target_link_libraries ( code_example_posix
62
- coverity_analysis )
72
+ target_include_directories ( code_example_posix
73
+ PUBLIC
74
+ ${CORE_SNTP_INCLUDE_PUBLIC_DIRS} )
75
+
76
+ # Build SNTP library target without custom config dependency.
77
+ target_compile_definitions ( code_example_posix PUBLIC SNTP_DO_NOT_USE_CUSTOM_CONFIG=1 )
63
78
79
+ # Build without debug enabled when performing static analysis
80
+ target_compile_options ( code_example_posix PUBLIC -DNDEBUG )
64
81
endif ()
65
82
66
83
# ==================================== Unit Test Configuration ====================================
67
84
68
- if (${BUILD_UNIT_TESTS} )
85
+ if ( UNITTEST )
69
86
# Include CMock build configuration.
70
87
include ( unit-test /cmock_build.cmake )
71
88
0 commit comments