diff --git a/CMakeLists.txt b/CMakeLists.txt index 35eeaaa..69c4454 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,19 @@ project(serial_cpp VERSION ${SERIAL_CPP_MAJOR_VERSION}.${SERIAL_CPP_MINOR_VERSIO option(BUILD_SHARED_LIBS "Build libraries as shared as opposed to static" OFF) option(BUILD_TESTING "Build tests" OFF) option(serial_cpp_INSTALL "Enable generation of serial_cpp install targets" ON) +mark_as_advanced(serial_cpp_INSTALL) +option(serial_cpp_FORCE_RESPECT_BUILD_TESTING "If also BUILD_TESTING is ON, enable tests even if project was included via add_subdirectory/FetchContent" OFF) +mark_as_advanced(serial_cpp_FORCE_RESPECT_BUILD_TESTING) + +# Detect if project is top level or not (fall back for CMake < 3.21) +if(CMAKE_VERSION VERSION_LESS "3.21.0") + if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + set(PROJECT_IS_TOP_LEVEL ON) + else() + set(PROJECT_IS_TOP_LEVEL OFF) + endif() +endif() + # Default install locations include(GNUInstallDirs) @@ -120,6 +133,10 @@ endif() ## Tests include(CTest) -if(BUILD_TESTING) +# Tests are enabled if BUILD_TESTING is enabled and PROJECT_IS_TOP_LEVEL is ON, +# or if serial_cpp_FORCE_RESPECT_BUILD_TESTING is ON, so if you include the project +# via FetchContent or add_subdirectory and if you want to compile tests, you +# need to set both BUILD_TESTING and serial_cpp_FORCE_RESPECT_BUILD_TESTING to ON +if(BUILD_TESTING OR (PROJECT_IS_TOP_LEVEL OR serial_cpp_FORCE_RESPECT_BUILD_TESTING)) add_subdirectory(tests) endif() diff --git a/package.xml b/package.xml index e772ab8..905abee 100644 --- a/package.xml +++ b/package.xml @@ -1,7 +1,7 @@ serial_cpp - 1.3.1 + 1.3.2 serial_cpp is a cross-platform, simple to use library for using serial ports on computers. This library provides a C++, object oriented interface for interacting with RS-232