Skip to content

Commit

Permalink
Merge branch 'release/v0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
gmarcais committed Jun 16, 2023
2 parents 245a72d + d7dd335 commit 2597800
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 13 deletions.
17 changes: 12 additions & 5 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,29 @@ jobs:
steps:
- uses: ConorMacBride/install-package@v1
with:
apt: libgtest-dev strace
apt: libgtest-dev
- uses: actions/checkout@v3
- name: autoconf

- name: Build and test with autotools
run: autoreconf -fi
- name: configure
run: ./configure
- name: make
run: make
run: make -j
- name: make check
run: make check
run: make -j check
- name: make distcheck
run: make distcheck
run: make -j distcheck
- name: Archive testing logs
if: '!cancelled()'
uses: actions/upload-artifact@v3
with:
name: gtest-logs
path: '**/*.log'
retention-days: 1

- name: Build and test with CMake
uses: threeal/cmake-action@latest
with:
args: -DNOSHELL_BUILD_TESTS=ON
run-test: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ install-sh
ltmain.sh
missing
test-driver

/build/
115 changes: 115 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
cmake_minimum_required(VERSION 3.10)
set(project_name noshell)

set(NOSHELL_MASTER_PROJECT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(NOSHELL_MASTER_PROJECT ON)
endif()

option(NOSHELL_BUILD_TESTS "Set to ON to build tests" ${NOSHELL_MASTER_PROJECT})
option(NOSHELL_ENABLE_INSTALL "Generate the install target" ${NOSHELL_MASTER_PROJECT})

# get version
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/configure.ac" configure_ac)
string(REGEX MATCH "AC_INIT\\\(\\\[noshell\\\],\\\[(.*)\\\],\\\[gmarcais@cmu.edu\\\]\\\)" _ "${configure_ac}")
if(NOT CMAKE_MATCH_COUNT EQUAL 1)
message(FATAL_ERROR "Could not extract major version number from configure.ac")
endif()
set(noshell_version ${CMAKE_MATCH_1})
message(STATUS "noshell version: ${noshell_version}")


project(${project_name} VERSION "${noshell_version}" LANGUAGES CXX)

include(GNUInstallDirs)

set(NOSHELL_SRCS lib/noshell.cc lib/setters.cc lib/utils.cc)

add_library(${project_name} SHARED ${NOSHELL_SRCS})
add_library(${project_name}-static STATIC ${NOSHELL_SRCS})
add_library(${project_name}::${project_name} ALIAS ${project_name})
add_library(${project_name}::${project_name}-static ALIAS ${project_name}-static)

target_include_directories(${project_name}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/noshell-${noshell_version}>)
target_include_directories(${project_name}-static
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/noshell-${noshell_version}>)
set_target_properties(${project_name}
PROPERTIES
CXX_STANDARD 11)
set_target_properties(${project_name}-static
PROPERTIES
CXX_STANDARD 11
POSITION_INDEPENDENT_CODE 1
OUTPUT_NAME ${project_name})

if(NOSHELL_ENABLE_INSTALL)
set(project_config_in "${CMAKE_CURRENT_LIST_DIR}/noshellConfig.cmake.in")
set(project_config_out "${CMAKE_CURRENT_BINARY_DIR}/noshellConfig.cmake")
set(config_targets_file "noshellConfigTargets.cmake")
set(version_config_file "${CMAKE_CURRENT_BINARY_DIR}/noshellConfigVersion.cmake")
set(export_dest_dir "${CMAKE_INSTALL_LIBDIR}/cmake/noshell")
set(pkgconfig_install_dir "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
set(pkgconfig "${CMAKE_CURRENT_BINARY_DIR}/noshell.pc")

set(prefix "${CMAKE_INSTALL_PREFIX}")
set(exec_prefix "\${prefix}")
if (IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
set(libdir "${CMAKE_INSTALL_LIBDIR}")
else()
set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
endif()
if (IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}")
set(includedir "${CMAKE_INSTALL_INCLUDEDIR}")
else()
set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
endif()
set(PACKAGE_VERSION "${noshell_version}")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/noshell.pc.in"
"${pkgconfig}"
@ONLY)

install(FILES "${pkgconfig}"
DESTINATION "${pkgconfig_install_dir}")

install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/noshell-${noshell_version}")

install(TARGETS ${project_name} ${project_name}-static
EXPORT ${project_name}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

export(
TARGETS ${project_name}
NAMESPACE ${project_name}::
FILE "${CMAKE_CURRENT_BINARY_DIR}/${config_targets_file}")

install(EXPORT ${project_name}
DESTINATION ${export_dest_dir}
NAMESPACE ${project_name}::
FILE ${config_targets_file})

include(CMakePackageConfigHelpers)
configure_package_config_file("${project_config_in}" "${project_config_out}"
INSTALL_DESTINATION ${export_dest_dir})


write_basic_package_version_file("${version_config_file}"
VERSION "${noshell_version}"
COMPATIBILITY ExactVersion)

install(FILES "${project_config_out}" "${version_config_file}" DESTINATION "${export_dest_dir}")
endif()


if(NOSHELL_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ dist_sub_HEADERS = $(INCDIR)/noshell.hpp $(INCDIR)/handle.hpp \
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = noshell.pc


# For CMake support
EXTRA_DIST = CMakeLists.txt noshellConfig.cmake.in
56 changes: 51 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![CI](https://github.com/github/docs/actions/workflows/c-cpp.yml/badge.svg)
![CI](https://github.com/gmarcais/NoShell/actions/workflows/c-cpp.yml/badge.svg)

# NoShell library

Expand Down Expand Up @@ -66,23 +66,69 @@ arguments to the exec call.

## Installation

It is recommended to install using the release tarball `noshel-x.x.x.tar.gz` available from [Github releases](https://github.com/gmarcais/NoShell/releases) rather than from the git tree.

For development, use the git tree, use the `develop` branch and initialize autotools with `autoreconf -i`.


### Autotools

For installation, use autoconf/automake:

```sh
autoreconf -i
# autoreconf -i # Only if running from git tree
./configure
make
sudo make install
```

At this point, this library has only been tested on Linux, with `g++`
version 4.7 or newer and `clang++` version 3.2.
Run the unit tests (requires Google `gtest``) with:

``` shell
make check
```


### CMake

Alternatively, you can use CMake to build the library:

```sh
mkdir build
cmake -S . -B build -DNOSHELL_BUILD_TESTS=OFF
cmake --build build
sudo cmake --install build
```

To compile the unit tests (requires Google `gtest`), do not include `-DNOSHELL_BUILD_TESTS=OFF` in the `cmake` command above and run the tests with:

```sh
cd build && ctest
```

## Using the library

Add the following to your make file:
### Pkg-config

Add the following to your `Makefile`:

```make
CXXFLAGS = $(shell pkg-config --cflags noshell)
LDFLAGS = $(shell pkg-config --libs noshell)
```

This method works with autotools and cmake installation.

### CMake

Add the following to your `CMakeLists.txt`:

```cmake
find_package(noshell REQUIRED)
# link shared library
target_link_libraries(mytarget noshell::noshell)
# link static library
target_link_libraries(mytarget noshell::noshell-static)
```
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([noshell],[0.2.0],[gmarcais@cmu.edu])
AC_INIT([noshell],[0.3.0],[gmarcais@cmu.edu])
AC_CANONICAL_HOST
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([subdir-objects foreign parallel-tests color-tests])
Expand Down
2 changes: 1 addition & 1 deletion include/noshell/handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class Exit {
void wait() { for(auto& h : handles) h.wait(); }
};

std::ostream& operator<<(std::ostream& os, const Exit& exit) {
inline std::ostream& operator<<(std::ostream& os, const Exit& exit) {
auto it = exit.begin();
if(it != exit.end()) {
os << *it;
Expand Down
6 changes: 6 additions & 0 deletions noshellConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@PACKAGE_INIT@

set(config_targets_file @config_targets_file@)
include("${CMAKE_CURRENT_LIST_DIR}/${config_targets_file}")

check_required_components(noshell)
36 changes: 36 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
cmake_minimum_required(VERSION 3.10)
project(noshell_tests CXX)

if(NOT TARGET noshell)
# Stand-alone build
find_package(noshell REQUIRED)
endif()

list(APPEND NOSHELL_TESTS_HELPER
check_open_fd.cc
kill_self.cc
puts_to.cc)

list(APPEND NOSHELL_TESTS_LIST
libtest_misc.cc
test_cmd_redirection.cc
test_error.cc
test_extra_fds.cc
test_fd_type.cc
test_literal.cc
test_pipeline.cc
test_resources.cc
test_simple_command.cc)

find_package(GTest REQUIRED)
find_package(Threads REQUIRED)

foreach(src ${NOSHELL_TESTS_HELPER})
GET_FILENAME_COMPONENT(target_name ${src} NAME_WE)
add_executable(${target_name} ${src})
endforeach()

add_executable(noshell_tests ${NOSHELL_TESTS_LIST})
target_link_libraries(noshell_tests GTest::Main GTest::GTest Threads::Threads noshell::noshell)

add_test(noshell_tests noshell_tests)
3 changes: 3 additions & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ clean-local: clean-local-check
.PHONY: clean-local-check
clean-local-check:
rm -f *_tmp

# CMake support
EXTRA_DIST += CMakeLists.txt

0 comments on commit 2597800

Please sign in to comment.