From 4709f68b7de63284973bf8c9555e460b1ff38452 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Mon, 7 Apr 2025 11:09:12 +0200 Subject: [PATCH 1/5] Do not add tests if PROJECT_IS_TOP_LEVEL is OFF --- CMakeLists.txt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 35eeaaa..b5a9deb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,17 @@ 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) +option(serial_cpp_FORCE_BUILD_TESTING "Enable tests even if project is the project was included via add_subdirectory/FetchContent" OFF) + +# 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 +131,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_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 serial_cpp_FORCE_BUILD_TESTING to ON +if((BUILD_TESTING OR PROJECT_IS_TOP_LEVEL) serial_cpp_FORCE_BUILD_TESTING) add_subdirectory(tests) endif() From bbc1ccc678e0de1476bae3716e7ffe1dc2c54701 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Mon, 7 Apr 2025 11:13:52 +0200 Subject: [PATCH 2/5] Set serial_cpp_* CMake options as advanced --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b5a9deb..55706f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,9 @@ 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_BUILD_TESTING "Enable tests even if project is the project was included via add_subdirectory/FetchContent" OFF) +mark_as_advanced(serial_cpp_FORCE_BUILD_TESTING) # Detect if project is top level or not (fall back for CMake < 3.21) if(CMAKE_VERSION VERSION_LESS "3.21.0") From cfd64d0b5a5daf3bc75d776f5963150826707669 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Mon, 7 Apr 2025 11:16:58 +0200 Subject: [PATCH 3/5] Update CMakeLists.txt --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 55706f8..f69bc80 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,7 +136,7 @@ include(CTest) # Tests are enabled if BUILD_TESTING is enabled and PROJECT_IS_TOP_LEVEL is ON, # or if serial_cpp_FORCE_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 serial_cpp_FORCE_BUILD_TESTING to ON -if((BUILD_TESTING OR PROJECT_IS_TOP_LEVEL) serial_cpp_FORCE_BUILD_TESTING) +# need to set both BUILD_TESTING and serial_cpp_FORCE_BUILD_TESTING to ON +if(BUILD_TESTING OR (PROJECT_IS_TOP_LEVEL OR serial_cpp_FORCE_BUILD_TESTING)) add_subdirectory(tests) endif() From 0012402f391a39778bb8e4599876fa49da2ee99a Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Mon, 7 Apr 2025 11:18:39 +0200 Subject: [PATCH 4/5] Update CMakeLists.txt --- CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f69bc80..69c4454 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,8 +16,8 @@ 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_BUILD_TESTING "Enable tests even if project is the project was included via add_subdirectory/FetchContent" OFF) -mark_as_advanced(serial_cpp_FORCE_BUILD_TESTING) +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") @@ -134,9 +134,9 @@ endif() ## Tests include(CTest) # Tests are enabled if BUILD_TESTING is enabled and PROJECT_IS_TOP_LEVEL is ON, -# or if serial_cpp_FORCE_BUILD_TESTING is ON, so if you include the project +# 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_BUILD_TESTING to ON -if(BUILD_TESTING OR (PROJECT_IS_TOP_LEVEL OR serial_cpp_FORCE_BUILD_TESTING)) +# 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() From 9d9b1e96e44b3c5fad92cd9f3a1b542f7a587af6 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Mon, 7 Apr 2025 11:20:45 +0200 Subject: [PATCH 5/5] Bump version to 1.3.2 --- package.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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