Skip to content

Commit

Permalink
Added option to not use the builtin googletest.
Browse files Browse the repository at this point in the history
This makes it easier to use code-coverage tools from the operating system
  • Loading branch information
FlorianReimold committed Oct 30, 2023
1 parent 6117e1a commit 3860039
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 12 deletions.
32 changes: 26 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 3.5.1)

include(CMakeDependentOption)

# Project call
include("${CMAKE_CURRENT_LIST_DIR}/fineftp-server/version.cmake")
project(fineftp VERSION ${FINEFTP_SERVER_VERSION_MAJOR}.${FINEFTP_SERVER_VERSION_MINOR}.${FINEFTP_SERVER_VERSION_PATCH})
Expand All @@ -15,33 +17,51 @@ option(FINEFTP_SERVER_BUILD_SAMPLES
"Build project samples."
ON)
option(FINEFTP_SERVER_BUILD_TESTS
"Build the GoogleTest submodule and the fineftp-server tests. Requires C++17. For executing the tests, curl must be available from the PATH."
"Build the the fineftp-server tests. Requires C++17. For executing the tests, curl must be available from the PATH."
OFF)

# Module path for finding asio
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
option(FINEFTP_SERVER_USE_BUILTIN_ASIO
"Use the builtin asio submodule. If set to OFF, asio must be available from somewhere else (e.g. system libs)."
ON)
cmake_dependent_option(FINEFTP_SERVER_USE_BUILTIN_GTEST
"Use the builtin GoogleTest submodule. Only needed if FINEFTP_SERVER_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
"FINEFTP_SERVER_BUILD_TESTS" # Dependency
OFF) # Default value if dependency is not met

# Set Debug postfix
set(CMAKE_DEBUG_POSTFIX d)
set(CMAKE_MINSIZEREL_POSTFIX minsize)
set(CMAKE_RELWITHDEBINFO_POSTFIX reldbg)

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

# Use builtin gtest
if (FINEFTP_SERVER_USE_BUILTIN_GTEST)
include("${CMAKE_CURRENT_LIST_DIR}/thirdparty/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(FINEFTP_SERVER_BUILD_TESTS AND BUILD_SHARED_LIBS)
if(FINEFTP_SERVER_BUILD_TESTS AND BUILD_SHARED_LIBS AND FINEFTP_SERVER_USE_BUILTIN_GTEST)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif()


# Add main fineftp::server library
add_subdirectory(fineftp-server)

# Add the fineftp::server dummy module
# Module path for finding asio
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/fineftp-module)

if (FINEFTP_SERVER_BUILD_SAMPLES)
add_subdirectory(samples/fineftp_example)
endif()

if (FINEFTP_SERVER_BUILD_TESTS)
include("${CMAKE_CURRENT_LIST_DIR}/thirdparty/build-gtest.cmake")
enable_testing()
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/tests/fineftp_test")
endif()
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ You can set the following CMake Options to control how fineFTP Server is built:

**Option** | **Type** | **Default** | **Explanation** |
|--------------------------------|----------|-------------|-----------------------------------------------------------------------------------------------------------------|
| `FINEFTP_SERVER_BUILD_SAMPLES` | `BOOL` | `ON` | Build the fineFTP Server sample project. |
| `FINEFTP_SERVER_BUILD_TESTS` | `BOOL` | `OFF` | Build the GoogleTest submodule and the fineftp-server tests. Requires C++17. For executing the tests, `curl` must be available from the `PATH`. |
| `BUILD_SHARED_LIBS` | `BOOL` | | Not a fineFTP Server option, but use this to control whether you want to have a static or shared library. |
| `FINEFTP_SERVER_BUILD_SAMPLES` | `BOOL` | `ON` | Build the fineFTP Server sample project. |
| `FINEFTP_SERVER_BUILD_TESTS` | `BOOL` | `OFF` | Build the the fineftp-server tests. Requires C++17. For executing the tests, `curl` must be available from the `PATH`. |
| `FINEFTP_SERVER_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). |
| `FINEFTP_SERVER_USE_BUILTIN_GTEST`| `BOOL`| `ON` <br>_(when building tests)_ | Use the builtin GoogleTest submodule. Only needed if `FINEFTP_SERVER_BUILD_TESTS` is `ON`. If set to `OFF`, GoogleTest must be available from somewhere else (e.g. system libs). |
| `BUILD_SHARED_LIBS` | `BOOL` | | Not a fineFTP Server option, but use this to control whether you want to have a static or shared library. |

## How to integrate in your project

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
find_path(asio_INCLUDE_DIR
NAMES asio.hpp
HINTS
"${CMAKE_CURRENT_LIST_DIR}/../thirdparty/asio/asio/include"
"${CMAKE_CURRENT_LIST_DIR}/../asio/asio/include"
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)
Expand Down
2 changes: 2 additions & 0 deletions thirdparty/build-asio.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Prepend asio-module/Fineasio.cmake to the module path
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/asio-module")
4 changes: 2 additions & 2 deletions thirdparty/build-gtest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ if(NOT TARGET GTest::gtest_main)
add_library(GTest::gtest_main ALIAS gtest_main)
endif()

# Prepend gtest-module/FindGTest.cmake to Module Path
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/gtest-module")
# Prepend googletest-module/FindGTest.cmake to Module Path
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/googletest-module")
File renamed without changes.

0 comments on commit 3860039

Please sign in to comment.