From d02cdeedc2d09e94021bddb59ee9375dfb370cf3 Mon Sep 17 00:00:00 2001 From: Haowen Liu Date: Mon, 28 Apr 2025 20:00:41 -0400 Subject: [PATCH 1/5] Support CMake 4 CMake 4 has removed compatibility with CMake < 3.5 Bumping minimum required version to 3.5 enables CMake 4 to build this code. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5acf5f8..fcbb029 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(subprocess VERSION 0.0.1 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard to use") From cbb57fff5f3f6028a37cf4bc9ae558fb558d2f36 Mon Sep 17 00:00:00 2001 From: Haowen Liu Date: Mon, 28 Apr 2025 21:02:00 -0400 Subject: [PATCH 2/5] Move header into subdir --- CMakeLists.txt | 9 +++++++-- subprocess.hpp => cpp-subprocess/subprocess.hpp | 0 2 files changed, 7 insertions(+), 2 deletions(-) rename subprocess.hpp => cpp-subprocess/subprocess.hpp (100%) mode change 100755 => 100644 diff --git a/CMakeLists.txt b/CMakeLists.txt index fcbb029..32d3851 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.5) -project(subprocess VERSION 0.0.1 LANGUAGES CXX) +project(subprocess VERSION 0.1.0 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard to use") option(EXPORT_COMPILE_COMMANDS "create clang compile database" ON) @@ -10,7 +10,12 @@ find_package(Threads REQUIRED) add_library(subprocess INTERFACE) target_link_libraries(subprocess INTERFACE Threads::Threads) -target_include_directories(subprocess INTERFACE . ) +target_sources(subprocess PUBLIC + FILE_SET HEADERS + FILES + subprocess/subprocess.hpp + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/ +) if(SUBPROCESS_INSTALL) install(FILES subprocess.hpp DESTINATION include/cpp-subprocess/) diff --git a/subprocess.hpp b/cpp-subprocess/subprocess.hpp old mode 100755 new mode 100644 similarity index 100% rename from subprocess.hpp rename to cpp-subprocess/subprocess.hpp From 7b63681cc220d743bbf22770bfdabef2e8434210 Mon Sep 17 00:00:00 2001 From: Haowen Liu Date: Tue, 29 Apr 2025 20:53:13 -0400 Subject: [PATCH 3/5] Improve CMake setup This commit configures and installs CMake metadata files. This also provides the namespaced ALIAS target `cpp-subprocess::subprocess`. --- CMakeLists.txt | 42 ++++++++++++++++++++++++++++++++--- cmake/subprocess-config.cmake | 7 ++++++ 2 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 cmake/subprocess-config.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 32d3851..c21809e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.5) -project(subprocess VERSION 0.1.0 LANGUAGES CXX) +project(subprocess VERSION 2.2 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard to use") option(EXPORT_COMPILE_COMMANDS "create clang compile database" ON) @@ -13,12 +13,48 @@ target_link_libraries(subprocess INTERFACE Threads::Threads) target_sources(subprocess PUBLIC FILE_SET HEADERS FILES - subprocess/subprocess.hpp + cpp-subprocess/subprocess.hpp BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/ ) +add_library(cpp-subprocess::subprocess ALIAS subprocess) if(SUBPROCESS_INSTALL) - install(FILES subprocess.hpp DESTINATION include/cpp-subprocess/) + install( + TARGETS subprocess COMPONENT subprocess + EXPORT subprocess + FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + ) + + include(CMakePackageConfigHelpers) + + configure_package_config_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/subprocess-config.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/subprocess-config.cmake" + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/subprocess" + PATH_VARS PROJECT_NAME PROJECT_VERSION + ) + + write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/beman.exemplar-version.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY ExactVersion + ) + + install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/subprocess-config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/subprocess-version.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/subprocess" + COMPONENT subprocess + ) + + install( + EXPORT subprocess + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/beman.exemplar" + NAMESPACE cpp-subprocess:: + FILE subprocess-targets.cmake + COMPONENT subprocess + ) endif() if(SUBPROCESS_TESTS) diff --git a/cmake/subprocess-config.cmake b/cmake/subprocess-config.cmake new file mode 100644 index 0000000..004d900 --- /dev/null +++ b/cmake/subprocess-config.cmake @@ -0,0 +1,7 @@ +set(SUBPROCESS_VERSION @PROJECT_VERSION@) + +@PACKAGE_INIT@ + +include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake) + +check_required_components(@PROJECT_NAME@) From 0003cac2f15fe751e04a4454a9d34a3e22f44bd4 Mon Sep 17 00:00:00 2001 From: Haowen Liu Date: Sun, 4 May 2025 10:24:45 -0400 Subject: [PATCH 4/5] Update README with CMake instructions --- README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a27e68c..ab0dcc2 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ and they will be fixed as they are reported. Subprocess library has just a single source `subprocess.hpp` present at the top directory of this repository. All you need to do is add ```cpp -#inlcude "cpp-subprocess/subprocess.hpp" +#include "cpp-subprocess/subprocess.hpp" using namespace subprocess; // OR @@ -33,6 +33,20 @@ to the files where you want to make use of subprocessing. Make sure to add neces Checkout http://templated-thoughts.blogspot.in/2016/03/sub-processing-with-modern-c.html as well. +## CMake Projects + +```cmake +include(FetchContent) +FetchContent_Declare( + cpp-subprocess + GIT_REPOSITORY https://github.com/arun11299/cpp-subprocess.git + GIT_TAG v2.2 +) +FetchContent_MakeAvailable(cpp-subprocess) + +target_link_libraries( PRIVATE cpp-subprocess::subprocess) +``` + ## Compiler Support Linux - g++ 4.8 and above Mac OS - Clang 3.4 and later From ab2d49a4451e8bd8767a8b6ac835b5e4e7e90bd2 Mon Sep 17 00:00:00 2001 From: Haowen Liu Date: Sun, 4 May 2025 10:41:39 -0400 Subject: [PATCH 5/5] Update include paths in tests --- test/test_cat.cc | 2 +- test/test_double_quotes.cc | 2 +- test/test_env.cc | 2 +- test/test_err_redirection.cc | 2 +- test/test_exception.cc | 2 +- test/test_redirection.cc.in | 2 +- test/test_ret_code.cc | 2 +- test/test_subprocess.cc | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/test_cat.cc b/test/test_cat.cc index 1c2ac54..7077d28 100755 --- a/test/test_cat.cc +++ b/test/test_cat.cc @@ -1,5 +1,5 @@ #include -#include +#include namespace sp = subprocess; diff --git a/test/test_double_quotes.cc b/test/test_double_quotes.cc index 0378822..d90e6d0 100644 --- a/test/test_double_quotes.cc +++ b/test/test_double_quotes.cc @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/test/test_env.cc b/test/test_env.cc index 8a561d5..11cbc7e 100644 --- a/test/test_env.cc +++ b/test/test_env.cc @@ -1,5 +1,5 @@ #include -#include +#include using namespace subprocess; diff --git a/test/test_err_redirection.cc b/test/test_err_redirection.cc index 97c1459..eac109d 100644 --- a/test/test_err_redirection.cc +++ b/test/test_err_redirection.cc @@ -1,5 +1,5 @@ #include -#include +#include using namespace subprocess; diff --git a/test/test_exception.cc b/test/test_exception.cc index 51f4fb1..09d2678 100644 --- a/test/test_exception.cc +++ b/test/test_exception.cc @@ -1,6 +1,6 @@ #include #include -#include +#include namespace sp = subprocess; diff --git a/test/test_redirection.cc.in b/test/test_redirection.cc.in index 787ecc9..d0b2eec 100644 --- a/test/test_redirection.cc.in +++ b/test/test_redirection.cc.in @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/test/test_ret_code.cc b/test/test_ret_code.cc index e589653..332079b 100644 --- a/test/test_ret_code.cc +++ b/test/test_ret_code.cc @@ -1,5 +1,5 @@ #include -#include +#include namespace sp = subprocess; diff --git a/test/test_subprocess.cc b/test/test_subprocess.cc index 01d258d..f6ea520 100755 --- a/test/test_subprocess.cc +++ b/test/test_subprocess.cc @@ -1,5 +1,5 @@ #include -#include +#include using namespace subprocess;