Skip to content

Commit 0b48d4b

Browse files
committed
Add CMakeLists.txt file update missed in previous commit
1 parent 1b48ca6 commit 0b48d4b

File tree

1 file changed

+42
-30
lines changed

1 file changed

+42
-30
lines changed

test/CMakeLists.txt

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ set( UNIT_TEST_DIR ${MODULE_ROOT_DIR}/test/unit-test CACHE INTERNAL "backoffAlgo
2222
set( UNITY_DIR ${UNIT_TEST_DIR}/Unity CACHE INTERNAL "Unity library source directory." )
2323

2424
# Configure options to always show in CMake GUI.
25-
option( BUILD_CLONE_SUBMODULES
26-
"Set this to ON to automatically clone any required Git submodules. When OFF, submodules must be manually cloned."
25+
option( BUILD_UNIT_TESTS
26+
"Set this to ON to build unit tests. This will clone the required Unity test framework submodule if it is not cloned already."
2727
OFF )
2828

2929
# Set output directories.
@@ -47,41 +47,53 @@ target_include_directories( coverity_analysis
4747

4848
# ==================================== Unit Test Configuration ====================================
4949

50-
# Include Unity build configuration.
51-
include( unit-test/unity_build.cmake )
50+
if(${BUILD_CODE_EXAMPLE})
5251

53-
# Check if the Unity source directory exists, and if not present, clone the submodule
54-
# if BUILD_CLONE_SUBMODULES configuration is enabled.
55-
if( NOT EXISTS ${UNITY_DIR}/src )
56-
# Attempt to clone Unity.
57-
if( ${BUILD_CLONE_SUBMODULES} )
52+
# Target for code example binary.
53+
add_executable( code_example_posix
54+
${MODULE_ROOT_DIR}/docs/doxygen/code_examples/backoff_algorithm_posix.c )
55+
56+
target_link_libraries( code_example_posix coverity_analysis )
57+
58+
endif()
59+
60+
# ==================================== Unit Test Configuration ====================================
61+
62+
if(${BUILD_UNIT_TESTS})
63+
64+
# Include Unity build configuration.
65+
include( unit-test/unity_build.cmake )
66+
67+
# Check if the Unity source directory exists, and if not present, clone the submodule
68+
# if BUILD_CLONE_SUBMODULES configuration is enabled.
69+
if( NOT EXISTS ${UNITY_DIR}/src )
70+
# Attempt to clone Unity.
5871
clone_unity()
59-
else()
60-
message( FATAL_ERROR "The required submodule Unity does not exist. Either clone it manually, or set BUILD_CLONE_SUBMODULES to 1 to automatically clone it during build." )
6172
endif()
62-
endif()
6373

64-
# Add unit test and coverage configuration.
74+
# Add unit test and coverage configuration.
75+
76+
# Use CTest utility for managing test runs. This has to be added BEFORE
77+
# defining test targets with add_test()
78+
enable_testing()
6579

66-
# Use CTest utility for managing test runs. This has to be added BEFORE
67-
# defining test targets with add_test()
68-
enable_testing()
80+
# Add build targets for Unity and Unit, required for unit testing.
81+
add_unity_targets()
6982

70-
# Add build targets for Unity and Unit, required for unit testing.
71-
add_unity_targets()
83+
# Add function to enable Unity based tests and coverage.
84+
include( ${MODULE_ROOT_DIR}/tools/unity/create_test.cmake )
7285

73-
# Add function to enable Unity based tests and coverage.
74-
include( ${MODULE_ROOT_DIR}/tools/unity/create_test.cmake )
86+
# Include build configuration for unit tests.
87+
add_subdirectory( unit-test )
7588

76-
# Include build configuration for unit tests.
77-
add_subdirectory( unit-test )
89+
# ==================================== Coverage Analysis configuration ============================
7890

79-
# ==================================== Coverage Analysis configuration ============================
91+
# Add a target for running coverage on tests.
92+
add_custom_target( coverage
93+
COMMAND ${CMAKE_COMMAND} -DUNITY_DIR=${UNITY_DIR}
94+
-P ${MODULE_ROOT_DIR}/tools/unity/coverage.cmake
95+
DEPENDS unity backoff_algorithm_utest
96+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
97+
)
8098

81-
# Add a target for running coverage on tests.
82-
add_custom_target( coverage
83-
COMMAND ${CMAKE_COMMAND} -DUNITY_DIR=${UNITY_DIR}
84-
-P ${MODULE_ROOT_DIR}/tools/unity/coverage.cmake
85-
DEPENDS unity backoff_algorithm_utest
86-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
87-
)
99+
endif()

0 commit comments

Comments
 (0)