Skip to content

Commit

Permalink
Add gtests as submodule (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
ovysotska authored Sep 13, 2022
1 parent 225361a commit 7325220
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@
*.exe
*.out
*.app


.cache
.vscode
build/
*__pycache__/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "src/external/googletest"]
path = src/external/googletest
url = https://github.com/google/googletest.git
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.10)

project(image_sequence_localizer)

include(GoogleTest)
include(cmake/UpdateSubmodules.cmake)

option(PACKAGE_TESTS "Build the tests" ON)
if(PACKAGE_TESTS)
enable_testing()
add_subdirectory(src/external/googletest)
endif()

add_subdirectory(src)

15 changes: 15 additions & 0 deletions cmake/UpdateSubmodules.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
option(UPDATE_SUBMODULES "Check submodules during build" ON)
if(UPDATE_SUBMODULES)
message(STATUS "Updating submodules")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
message(STATUS "All sobmodules updated")
endif()
endif()
12 changes: 6 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
cmake_minimum_required(VERSION 3.10)

project(image_sequence_localizer)

find_package(Protobuf REQUIRED)

# TODO: is opencv really required?
Expand All @@ -16,7 +12,7 @@ target_compile_features(cxx_flags INTERFACE cxx_std_17)
include_directories(${Protobuf_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS localization_protos.proto)
protobuf_generate_python(PROTO_PY localization_protos.proto PROTOC_OUT_DIR ${CMAKE_SOURCE_DIR}/python/protos)
protobuf_generate_python(PROTO_PY localization_protos.proto PROTOC_OUT_DIR ${CMAKE_SOURCE_DIR}/src/python/protos)

add_library(protos ${PROTO_SRCS} ${PROTO_HDRS})
target_link_libraries(protos ${Protobuf_LIBRARIES})
Expand All @@ -26,4 +22,8 @@ add_subdirectory(localization)
add_subdirectory(apps)

# # Generate the python proto files
add_custom_target(proto_python ALL DEPENDS ${PROTO_PY})
add_custom_target(proto_python ALL DEPENDS ${PROTO_PY})

if(PACKAGE_TESTS)
add_subdirectory(test)
endif()
1 change: 1 addition & 0 deletions src/external/googletest
Submodule googletest added at 154609
6 changes: 6 additions & 0 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set(TESTNAME test_${PROJECT_NAME})

add_executable(${TESTNAME} dummy_test.cpp dummy_test_2.cpp)
target_link_libraries(${TESTNAME} gtest gtest_main)

gtest_discover_tests(${TESTNAME})
3 changes: 3 additions & 0 deletions src/test/dummy_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <gtest/gtest.h>

TEST(Dummy, Dummy) { SUCCEED(); }
3 changes: 3 additions & 0 deletions src/test/dummy_test_2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <gtest/gtest.h>

TEST(Dummy2, Dummy) { FAIL(); }

0 comments on commit 7325220

Please sign in to comment.