11cmake_minimum_required ( VERSION 3.13.0 )
2- project ( "coreSNTP unit test"
2+ project ( "coreSNTP tests"
3+ VERSION 1.2.0
34 LANGUAGES C )
45
56# Allow the project to be organized into folders.
@@ -9,6 +10,13 @@ set_property( GLOBAL PROPERTY USE_FOLDERS ON )
910set ( CMAKE_C_STANDARD 90 )
1011set ( CMAKE_C_STANDARD_REQUIRED ON )
1112
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+
1220# Do not allow in-source build.
1321if ( ${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR} )
1422 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 )
3038set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /lib )
3139set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /lib )
3240
33- # ================================ Coverity Analysis Configuration =================================
34-
3541# Include filepaths for source and include.
3642include ( ${MODULE_ROOT_DIR} /coreSntpFilePaths.cmake )
3743
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 )
4147
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} )
4656
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 )
4959
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 ()
5263
5364# ==================================== Code Example Build ====================================
5465
55- if (${ BUILD_CODE_EXAMPLE} )
66+ if ( BUILD_CODE_EXAMPLE )
5667 # Target for Coverity analysis that builds the library.
5768 add_executable ( code_example_posix
69+ ${CORE_SNTP_SOURCES}
5870 ${MODULE_ROOT_DIR} /docs/doxygen/code_examples/example_sntp_client_posix.c )
5971
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 )
6378
79+ # Build without debug enabled when performing static analysis
80+ target_compile_options ( code_example_posix PUBLIC -DNDEBUG )
6481endif ()
6582
6683# ==================================== Unit Test Configuration ====================================
6784
68- if (${BUILD_UNIT_TESTS} )
85+ if ( UNITTEST )
6986 # Include CMock build configuration.
7087 include ( unit-test /cmock_build.cmake )
7188
0 commit comments