diff --git a/.github/workflows/cmake-single-platform.yml b/.github/workflows/cmake-single-platform.yml new file mode 100644 index 00000000..1fb975bc --- /dev/null +++ b/.github/workflows/cmake-single-platform.yml @@ -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 diff --git a/.gitignore b/.gitignore index c44db863..2d0fd521 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ linenoise-example linenoise-test *.dSYM history.txt +build/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..c871ea33 --- /dev/null +++ b/CMakeLists.txt @@ -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) \ No newline at end of file diff --git a/Makefile b/Makefile index 9688de30..80653e77 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/Testing/Temporary/CTestCostData.txt b/Testing/Temporary/CTestCostData.txt new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/Testing/Temporary/CTestCostData.txt @@ -0,0 +1 @@ +--- diff --git a/Testing/Temporary/LastTest.log b/Testing/Temporary/LastTest.log new file mode 100644 index 00000000..091c42a8 --- /dev/null +++ b/Testing/Temporary/LastTest.log @@ -0,0 +1,3 @@ +Start testing: May 15 10:03 WEST +---------------------------------------------------------- +End testing: May 15 10:03 WEST diff --git a/linenoise.pc.in b/linenoise.pc.in new file mode 100644 index 00000000..b7919c5f --- /dev/null +++ b/linenoise.pc.in @@ -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} \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 00000000..9232c88d --- /dev/null +++ b/test/CMakeLists.txt @@ -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 $) \ No newline at end of file diff --git a/test/test_1.c b/test/test_1.c new file mode 100644 index 00000000..81cf2236 --- /dev/null +++ b/test/test_1.c @@ -0,0 +1,5 @@ +#include + +int main() { + return 0; +} \ No newline at end of file