From d9ed0d606ffbc3aa66c8b8cf19388844bb7dff80 Mon Sep 17 00:00:00 2001 From: Jan Christoph Uhde Date: Tue, 21 Mar 2023 04:09:25 +0100 Subject: [PATCH] chore: improve CMake files (#85) --- .travis.yml | 2 +- CMakeLists.txt | 21 ++++++++++++--------- test/CMakeLists.txt | 5 ++--- test/test_cat.cc | 2 +- test/test_env.cc | 2 +- test/test_err_redirection.cc | 2 +- test/test_ret_code.cc | 2 +- test/test_subprocess.cc | 2 +- 8 files changed, 20 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 223d0d2..c5c1338 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,6 @@ compiler: script: - mkdir -p build && cd build - - cmake -DCMAKE_BUILD_TYPE=Debug .. + - cmake -DCMAKE_BUILD_TYPE=Debug -DSUBPROCESS_TESTS=ON .. - cmake --build . --config Debug -- -j $(nproc) - ctest -j $(nproc) --output-on-failure \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 39951e4..0f4128a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,18 @@ cmake_minimum_required(VERSION 3.1) +project(subprocess VERSION 0.0.1 LANGUAGES CXX) -project(subprocess CXX) +set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard to use") +option(EXPORT_COMPILE_COMMANDS "create clang compile database" ON) +option(SUBPROCESS_TESTS "enalbe subprocess tests" OFF) -set(CMAKE_CXX_STANDARD 11) - -include(CTest) -if(BUILD_TESTING) - add_subdirectory(test) -endif() +find_package(Threads REQUIRED) add_library(subprocess INTERFACE) -target_include_directories(subprocess INTERFACE .) - +target_link_libraries(subprocess INTERFACE Threads::Threads) +target_include_directories(subprocess INTERFACE . ) install(FILES subprocess.hpp DESTINATION include/cpp-subprocess/) + +if(SUBPROCESS_TESTS) + include(CTest) + add_subdirectory(test) +endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3c4d24c..ffc4eab 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,16 +1,15 @@ set(test_names test_subprocess test_cat test_env test_err_redirection test_split test_main test_ret_code) set(test_files env_script.sh write_err.sh write_err.txt) -find_package(Threads REQUIRED) foreach(test_name IN LISTS test_names) add_executable(${test_name} ${test_name}.cc) - target_link_libraries(${test_name} PRIVATE Threads::Threads) + target_link_libraries(${test_name} PRIVATE subprocess) add_test( NAME ${test_name} COMMAND $ - ) + ) endforeach() foreach(test_file IN LISTS test_files) diff --git a/test/test_cat.cc b/test/test_cat.cc index 76ca6a4..b33021c 100755 --- a/test/test_cat.cc +++ b/test/test_cat.cc @@ -1,5 +1,5 @@ #include -#include "../subprocess.hpp" +#include namespace sp = subprocess; diff --git a/test/test_env.cc b/test/test_env.cc index 51f6029..8b041fa 100644 --- a/test/test_env.cc +++ b/test/test_env.cc @@ -1,5 +1,5 @@ #include -#include "../subprocess.hpp" +#include using namespace subprocess; diff --git a/test/test_err_redirection.cc b/test/test_err_redirection.cc index 24cbb91..e01e15e 100644 --- a/test/test_err_redirection.cc +++ b/test/test_err_redirection.cc @@ -1,5 +1,5 @@ #include -#include "../subprocess.hpp" +#include using namespace subprocess; diff --git a/test/test_ret_code.cc b/test/test_ret_code.cc index f2c0c3a..301a091 100644 --- a/test/test_ret_code.cc +++ b/test/test_ret_code.cc @@ -1,5 +1,5 @@ #include -#include "../subprocess.hpp" +#include namespace sp = subprocess; diff --git a/test/test_subprocess.cc b/test/test_subprocess.cc index 64ef998..efd721d 100755 --- a/test/test_subprocess.cc +++ b/test/test_subprocess.cc @@ -1,5 +1,5 @@ #include -#include "../subprocess.hpp" +#include using namespace subprocess;