From 3860039f3a911ebca5aa5492fc29b8b246a5d10f Mon Sep 17 00:00:00 2001 From: Florian Reimold <11774314+FlorianReimold@users.noreply.github.com> Date: Mon, 30 Oct 2023 09:53:59 +0100 Subject: [PATCH] Added option to not use the builtin googletest. This makes it easier to use code-coverage tools from the operating system --- CMakeLists.txt | 32 +++++++++++++++---- README.md | 8 +++-- cmake/{ => fineftp-module}/Findfineftp.cmake | 0 .../asio-module}/Findasio.cmake | 2 +- thirdparty/build-asio.cmake | 2 ++ thirdparty/build-gtest.cmake | 4 +-- .../FindGTest.cmake | 0 7 files changed, 36 insertions(+), 12 deletions(-) rename cmake/{ => fineftp-module}/Findfineftp.cmake (100%) rename {cmake => thirdparty/asio-module}/Findasio.cmake (92%) create mode 100644 thirdparty/build-asio.cmake rename thirdparty/{gtest-module => googletest-module}/FindGTest.cmake (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ba3e12..99c1394 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) @@ -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() diff --git a/README.md b/README.md index e867d2e..57eea0b 100644 --- a/README.md +++ b/README.md @@ -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`
_(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 diff --git a/cmake/Findfineftp.cmake b/cmake/fineftp-module/Findfineftp.cmake similarity index 100% rename from cmake/Findfineftp.cmake rename to cmake/fineftp-module/Findfineftp.cmake diff --git a/cmake/Findasio.cmake b/thirdparty/asio-module/Findasio.cmake similarity index 92% rename from cmake/Findasio.cmake rename to thirdparty/asio-module/Findasio.cmake index f7a958c..e2e12de 100644 --- a/cmake/Findasio.cmake +++ b/thirdparty/asio-module/Findasio.cmake @@ -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 ) diff --git a/thirdparty/build-asio.cmake b/thirdparty/build-asio.cmake new file mode 100644 index 0000000..823e44b --- /dev/null +++ b/thirdparty/build-asio.cmake @@ -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") diff --git a/thirdparty/build-gtest.cmake b/thirdparty/build-gtest.cmake index 4eed082..80a7e64 100644 --- a/thirdparty/build-gtest.cmake +++ b/thirdparty/build-gtest.cmake @@ -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") diff --git a/thirdparty/gtest-module/FindGTest.cmake b/thirdparty/googletest-module/FindGTest.cmake similarity index 100% rename from thirdparty/gtest-module/FindGTest.cmake rename to thirdparty/googletest-module/FindGTest.cmake