Skip to content

Commit

Permalink
Add option to conditionally build unit tests
Browse files Browse the repository at this point in the history
To disable compilation of unit tests one can invoke
"BUILD_UNIT_TESTS=OFF ./build.sh"

MCM_unit_tests was renamed to mcm_unit_tests

Signed-off-by: Kasiewicz, Marek <[email protected]>
  • Loading branch information
Sakoram committed Aug 14, 2024
1 parent 7b1a07e commit 122b471
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

enable_testing()

add_subdirectory(${SDK_DIR})
add_subdirectory(${MP_DIR})
add_subdirectory(${TESTS_DIR})

option(BUILD_UNIT_TESTS "Build and enable unit tests" ON)
if (BUILD_UNIT_TESTS)
enable_testing()
add_subdirectory(${TESTS_DIR})
endif()

target_include_directories(media_proxy_lib PUBLIC ${SDK_INCLUDE_DIR})
target_link_libraries(media_proxy_lib PUBLIC mcm_dp)

3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ SCRIPT_DIR="$(readlink -f "$(dirname -- "${BASH_SOURCE[0]}")")"

# Set build type. ("Debug" or "Release")
BUILD_TYPE="${BUILD_TYPE:-Release}"
# To disable the building of unit tests, set the value to "OFF".
BUILD_UNIT_TESTS="${BUILD_UNIT_TESTS:-ON}"
INSTALL_PREFIX="${INSTALL_PREFIX:-/usr/local}"

cmake -B "${SCRIPT_DIR}/out" \
-DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \
-DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" \
-DBUILD_UNIT_TESTS="${BUILD_UNIT_TESTS}" \
"${SCRIPT_DIR}"
cmake --build "${SCRIPT_DIR}/out" -j

Expand Down
8 changes: 4 additions & 4 deletions tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ file(GLOB TEST_SOURCES "*.cc")
set(MP_LIB media_proxy_lib)

# Add an executable for tests
add_executable(MCM_unit_tests ${TEST_SOURCES})
add_executable(mcm_unit_tests ${TEST_SOURCES})

# Link the executable with gtest and gtest_main
target_link_libraries(MCM_unit_tests PRIVATE gtest gtest_main ${MP_LIB})
target_include_directories(MCM_unit_tests PUBLIC
target_link_libraries(mcm_unit_tests PRIVATE gtest gtest_main ${MP_LIB})
target_include_directories(mcm_unit_tests PUBLIC
${CMAKE_SOURCE_DIR}/media-proxy/include
# Include generated *.pb.h files
${CMAKE_BINARY_DIR}/media-proxy/
)

# Add tests to CTest
add_test(NAME MCM_unit_tests COMMAND MCM_unit_tests)
add_test(NAME mcm_unit_tests COMMAND mcm_unit_tests)

0 comments on commit 122b471

Please sign in to comment.