Skip to content
Open

Merge #251

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/cmake-single-platform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# This starter workflow is for a CMake project running on a single platform. There is a different starter workflow if you need cross-platform coverage.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml
name: linenoise

on:
push:
branches: [ "master" ]
tags: [ "v*" ]
pull_request:
branches: [ "master" ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}}

release:
# Creates binary packages
runs-on: ubuntu-latest
needs: [ build ]
if: github.ref == 'refs/heads/releng' || startsWith(github.ref, 'refs/tags/')
steps:
- name: Define the release name
id: release_name
run: |
if [ ${GITHUB_REF/refs\/tags\//} != ${GITHUB_REF} ]; then
echo "RELEASE_NAME=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
elif [ ${GITHUB_REF/refs\/heads\//} = "releng" ]; then
echo "RELEASE_NAME=releng" >> $GITHUB_OUTPUT
else
echo "RELEASE_NAME=${GITHUB_REF/refs\/heads\//}" >> $GITHUB_OUTPUT
fi
- name: Create release with releng image
if: github.ref == 'refs/heads/releng'
uses: "marvinpinto/action-automatic-releases@v1.2.1"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "latest"
prerelease: true
draft: true
title: "Prerelease"
files: linenoise-${{ steps.release_name.outputs.RELEASE_NAME }}-*.zip

- name: Create release with release image
if: startsWith(github.ref, 'refs/tags/')
uses: "marvinpinto/action-automatic-releases@v1.2.1"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: ${{ steps.release_name.outputs.RELEASE_NAME }}
prerelease: false
draft: true
title: ${{ steps.release_name.outputs.RELEASE_NAME }}
files: linenoise-${{ steps.release_name.outputs.RELEASE_NAME }}-*.zip
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ linenoise-example
linenoise-test
*.dSYM
history.txt
build/
66 changes: 66 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
cmake_minimum_required (VERSION 3.10)
project (LINENOISE DESCRIPTION "A shell library")

# Configuration specific to being the main project
if(PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(LINENOISE_NOT_SUBPROJECT ON)
endif(PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME)

if(CMAKE_BUILD_TYPE)
message("Building ${PROJECT_NAME} in ${CMAKE_BUILD_TYPE} build.")
elseif(NOT CMAKE_BUILD_TYPE)
message(FATAL_ERROR "No build type specified. Use -DCMAKE_BUILD_TYPE=[DEBUG|RELEASE] to specify.")
endif(CMAKE_BUILD_TYPE)

option(LINENOISE_BUILD_EXAMPLES "Build examples" OFF)
option(LINENOISE_BUILD_TESTS "Build unit tests" OFF)

# set the version of our library
# MAJOR, is significant breaking changes, MINOR, is when we might have changed signatures of existing functions, PATCH, is just bug fixes and no breaking changes
set(LINENOISE_VERSION_MAJOR 1)
set(LINENOISE_VERSION_MINOR 0)
set(LINENOISE_VERSION_PATCH 1)
set(LINENOISE_VERSION_STRING ${LINENOISE_VERSION_MAJOR}.${LINENOISE_VERSION_MINOR}.${LINENOISE_VERSION_PATCH})

file(GLOB LINENOISE_SOURCE_FILES "linenoise.c")
file(GLOB LINENOISE_HEADER_FILES "linenoise.h")

set(LINENOISE_SOURCES ${LINENOISE_SOURCE_FILES})
set(LINENOISE_HEADERS ${LINENOISE_HEADER_FILES})

# where the library will be built to
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/libs)

add_library(linenoise SHARED ${LINENOISE_SOURCES} ${LINENOISE_HEADERS})
target_link_libraries(linenoise)

target_include_directories(linenoise PUBLIC ".")
# sets the shared library version
# http://cmake.3232098.n2.nabble.com/Version-in-name-of-shared-library-td7581530.html
set_target_properties(linenoise PROPERTIES VERSION ${LINENOISE_VERSION_STRING} SOVERSION ${LINENOISE_VERSION_MAJOR})
set_target_properties(linenoise PROPERTIES LINKER_LANGUAGE C)

# create pkg-config files for configuration in non-cmake projects
# configure_file(linenoise.pc.in linenoise.pc @ONLY)

# only offer install option if they compiled with release mode
if(CMAKE_BUILD_TYPE MATCHES "^(RELEASE|Release)")
# adds the 'make install' targets to copy the shared library to /usr/local/lib/ directory
install(TARGETS linenoise DESTINATION ${CMAKE_INSTALL_LIBDIR} )
# adds all the relevant headers to /usr/local/include/gphoto2pp when ``make install`` is executed
install(FILES ${LINENOISE_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/linenoise )
# install the pkg-config config to system folder
install(FILES ${CMAKE_BINARY_DIR}/linenoise.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
endif(CMAKE_BUILD_TYPE MATCHES "^(RELEASE|Release)")

if(LINENOISE_BUILD_EXAMPLES)
message(STATUS "Building examples")
add_executable(example example.c)
target_link_libraries(example linenoise)
endif(LINENOISE_BUILD_EXAMPLES)

if(LINENOISE_BUILD_TESTS)
message(STATUS "Building tests")
add_subdirectory(test)
endif(LINENOISE_BUILD_TESTS)
26 changes: 13 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
all: linenoise-example linenoise-test

linenoise-example: linenoise.h linenoise.c example.c
$(CC) -Wall -W -Os -g -o linenoise-example linenoise.c example.c

linenoise-test: linenoise-test.c linenoise-example
$(CC) -Wall -W -Os -g -o linenoise-test linenoise-test.c

test: linenoise-test linenoise-example
./linenoise-test

clean:
rm -f linenoise-example linenoise-test
all: linenoise-example linenoise-test
linenoise-example: linenoise.h linenoise.c example.c
$(CC) -Wall -W -Os -g -o linenoise-example linenoise.c example.c
linenoise-test: linenoise-test.c linenoise-example
$(CC) -Wall -W -Os -g -o linenoise-test linenoise-test.c
test: linenoise-test linenoise-example
./linenoise-test
clean:
rm -f linenoise-example linenoise-test
1 change: 1 addition & 0 deletions Testing/Temporary/CTestCostData.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
3 changes: 3 additions & 0 deletions Testing/Temporary/LastTest.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Start testing: May 15 10:03 WEST
----------------------------------------------------------
End testing: May 15 10:03 WEST
12 changes: 12 additions & 0 deletions linenoise.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=@CMAKE_INSTALL_PREFIX@
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@

Name: @PROJECT_NAME@
Description: @PROJECT_DESCRIPTION@
Version: @LINENOISE_VERSION_STRING@

Requires:
Libs: -L${libdir}
Cflags: -I${includedir}
7 changes: 7 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enable_testing()

# testing binary
add_executable(c_test_1 test_1.c)
target_link_libraries(c_test_1 linenoise)

add_test (NAME c_test_1 COMMAND $<TARGET_FILE:c_test_1>)
5 changes: 5 additions & 0 deletions test/test_1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <linenoise.h>

int main() {
return 0;
}