Skip to content

Commit

Permalink
Added gtest dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianReimold committed Nov 20, 2024
1 parent 55c9b15 commit 70d7e49
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 13 deletions.
11 changes: 7 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[submodule "thirdparty/asio"]
path = thirdparty/asio
[submodule "thirdparty/asio/asio"]
path = thirdparty/asio/asio
url = https://github.com/chriskohlhoff/asio.git
[submodule "thirdparty/recycle"]
path = thirdparty/recycle
[submodule "thirdparty/recycle/recycle"]
path = thirdparty/recycle/recycle
url = https://github.com/steinwurf/recycle.git
[submodule "thirdparty/gtest/googletest"]
path = thirdparty/gtest/googletest
url = https://github.com/google/googletest.git
58 changes: 54 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cmake_minimum_required(VERSION 3.5.1)
cmake_minimum_required(VERSION 3.13)

include(CMakeDependentOption)

# Project call
include("${CMAKE_CURRENT_LIST_DIR}/tcp_pubsub/version.cmake")
Expand All @@ -19,6 +21,25 @@ option(TCP_PUBSUB_BUILD_ECAL_SAMPLES
"Build eCAL-based project samples. Requires eCAL to be findable by CMake."
OFF)

option(TCP_PUBSUB_USE_BUILTIN_ASIO
"Use the builtin asio submodule. If set to OFF, asio must be available from somewhere else (e.g. system libs)."
ON)

option(TCP_PUBSUB_USE_BUILTIN_RECYCLE
"Use the builtin steinwurf::recycle submodule. If set to OFF, recycle must be available from somewhere else (e.g. system libs)."
ON)

option(TCP_PUBSUB_BUILD_TESTS
"Build the tcp_pubsub tests. Requires Gtest::GTest to be findable by CMake."
ON)

cmake_dependent_option(TCP_PUBSUB_USE_BUILTIN_GTEST
"Use the builtin GoogleTest submodule. Only needed if TCP_PUBSUB_BUILD_TESTS is ON. If set to OFF, GoogleTest must be available from somewhere else (e.g. system libs)."
ON # Default value if dependency is met
"TCP_PUBSUB_BUILD_TESTS" # Dependency
OFF) # Default value if dependency is not met


# Module path for finding asio
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/modules)

Expand All @@ -27,12 +48,34 @@ set(CMAKE_DEBUG_POSTFIX d)
set(CMAKE_MINSIZEREL_POSTFIX minsize)
set(CMAKE_RELWITHDEBINFO_POSTFIX reldbg)


# Use builtin asio
if (TCP_PUBSUB_USE_BUILTIN_ASIO)
include("${CMAKE_CURRENT_LIST_DIR}/thirdparty/asio/build-asio.cmake")
endif()

# Use builtin recycle
if (TCP_PUBSUB_USE_BUILTIN_RECYCLE)
include("${CMAKE_CURRENT_LIST_DIR}/thirdparty/recycle/build-recycle.cmake")
endif()

# Use builtin gtest
if (TCP_PUBSUB_USE_BUILTIN_GTEST)
include("${CMAKE_CURRENT_LIST_DIR}/thirdparty/gtest/build-gtest.cmake")
endif()

# For tests we need to make sure that all shared libraries and executables are
# put into the same directory. Otherwise the tests will fail on windows.
if(TCP_PUBSUB_BUILD_TESTS AND (BUILD_SHARED_LIBS OR (TCP_PUBSUB_LIBRARY_TYPE STREQUAL "SHARED")))
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif()

# Module path for finding tcp_pubsub
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/tcp_pubsub/Module)

# Add main tcp_pubsub library
add_subdirectory(tcp_pubsub)

# Recycle dependency. It's header only and not in the API, so we add it with EXCLUDE_FOR_ALL, so it won't be installed
add_subdirectory(thirdparty/recycle EXCLUDE_FROM_ALL)

# Generic samples
if (TCP_PUBSUB_BUILD_SAMPLES)
add_subdirectory(samples/performance_publisher)
Expand All @@ -47,5 +90,12 @@ if(TCP_PUBSUB_BUILD_ECAL_SAMPLES)
add_subdirectory(samples/tcp_to_ecal)
endif()


# Add Tests if enabled
if (TCP_PUBSUB_BUILD_TESTS)
enable_testing()
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/tests/tcp_pubsub_test")
endif()

# Make this package available for packing with CPack
include("${CMAKE_CURRENT_LIST_DIR}/cpack_config.cmake")
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ int main()
}
```

## CMake Options

You can set the following CMake Options to control how tcp_pubsub is built:

| Option | Type | Default | Explanation |
|------------------------------------|-------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------|
| `TCP_PUBSUB_BUILD_SAMPLES` | `BOOL`| `ON` | Build project samples. |
| `TCP_PUBSUB_BUILD_ECAL_SAMPLES` | `BOOL`| `OFF` | Build eCAL-based project samples. Requires eCAL to be findable by CMake. |
| `TCP_PUBSUB_USE_BUILTIN_ASIO` | `BOOL`| `ON` | Use the builtin asio submodule. If set to `OFF`, asio must be available from somewhere else (e.g. system libs). |
| `TCP_PUBSUB_USE_BUILTIN_RECYCLE` | `BOOL`| `ON` | Use the builtin `steinwurf::recycle` submodule. If set to `OFF`, recycle must be available from somewhere else (e.g. system libs). |
| `TCP_PUBSUB_BUILD_TESTS` | `BOOL`| `OFF` | Build the tcp_pubsub tests. Requires Gtest::GTest to be findable by CMake. |
| `TCP_PUBSUB_USE_BUILTIN_GTEST` | `BOOL`| `ON` (if building tests) | Use the builtin GoogleTest submodule. Only needed if `TCP_PUBSUB_BUILD_TESTS` is `ON`. If set to `OFF`, GoogleTest must be available from elsewhere. |
| `TCP_PUBSUB_LIBRARY_TYPE` | `STRING` | | Controls the library type of tcp_pubsub by injecting the string into the `add_library` call. Can be set to STATIC / SHARED / OBJECT. If set, this will override the regular `BUILD_SHARED_LIBS` CMake option. If not set, CMake will use the default setting, which is controlled by `BUILD_SHARED_LIBS`. |

## How to checkout and build

There are several examples provided that aim to show you the functionality.
Expand Down
1 change: 0 additions & 1 deletion thirdparty/asio
Submodule asio deleted from dc6737
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ if(asio_FOUND)
INTERFACE_COMPILE_DEFINITIONS ASIO_STANDALONE)
mark_as_advanced(asio_INCLUDE_DIR)
endif()
endif()
endif()
1 change: 1 addition & 0 deletions thirdparty/asio/asio
Submodule asio added at 03ae83
1 change: 1 addition & 0 deletions thirdparty/asio/build-asio.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/Module")
1 change: 1 addition & 0 deletions thirdparty/gtest/Module/FindGTest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(GTest_FOUND TRUE CACHE BOOL "Found Google Test" FORCE)
19 changes: 19 additions & 0 deletions thirdparty/gtest/build-gtest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Googletest automatically forces MT instead of MD if we do not set this option.
if(MSVC)
set(gtest_force_shared_crt ON CACHE BOOL "My option" FORCE)
set(BUILD_GMOCK OFF CACHE BOOL "My option" FORCE)
set(INSTALL_GTEST OFF CACHE BOOL "My option" FORCE)
endif()

add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/googletest" EXCLUDE_FROM_ALL)

if(NOT TARGET GTest::gtest)
add_library(GTest::gtest ALIAS gtest)
endif()

if(NOT TARGET GTest::gtest_main)
add_library(GTest::gtest_main ALIAS gtest_main)
endif()

# Prepend googletest-module/FindGTest.cmake to Module Path
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/Module")
1 change: 1 addition & 0 deletions thirdparty/gtest/googletest
Submodule googletest added at d14403
2 changes: 0 additions & 2 deletions thirdparty/modules/Findrecycle.cmake

This file was deleted.

1 change: 1 addition & 0 deletions thirdparty/recycle/Module/Findrecycle.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(recycle_FOUND TRUE CACHE BOOL "Found steinwurf::recycle" FORCE)
5 changes: 5 additions & 0 deletions thirdparty/recycle/build-recycle.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/recycle" EXCLUDE_FROM_ALL)
add_library(steinwurf::recycle ALIAS recycle)

# Prepend asio-module/Findrecycle.cmake to the module path
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/Module")
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Stub find script for in-source build of samples
set(tcp_pubsub_FOUND True)
set(tcp_pubsub_FOUND True)

0 comments on commit 70d7e49

Please sign in to comment.