Skip to content

Commit

Permalink
init sample project - clist
Browse files Browse the repository at this point in the history
  • Loading branch information
luanhui committed Dec 21, 2020
0 parents commit 9a6a7ab
Show file tree
Hide file tree
Showing 18 changed files with 1,269 additions and 0 deletions.
167 changes: 167 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
name: build-and-package

on:
#push:
#branches: test
# Sequence of patterns matched against refs/tags
#tags:
# - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
create:
ref_type: tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
job1:
name: Build and Package on Linux
runs-on: ubuntu-16.04

steps:
- name: Checkout Repository
uses: actions/checkout@v2
with:
ref: ${{github.ref}}

- name: Create Build Environment
# Some projects don't allow in-source building, so create a separate build directory
# We'll use this as our working directory for all subsequent commands
run: cmake -E make_directory ${{runner.workspace}}/build

- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment variable
# access regardless of the host operating system
shell: bash
working-directory: ${{runner.workspace}}/build
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE

- name: Build
working-directory: ${{runner.workspace}}/build
shell: bash
# Execute the build. You can specify a specific target with "--target <NAME>"
run: cmake --build . --config $BUILD_TYPE

- name: Package
if: ${{ success() }}
working-directory: ${{github.workspace}}
shell: bash
run: |
tar -Jcf linux-bin.tar.xz ./bin/
- name: Upload Artifact for Stage
if: ${{ success() }}
uses: actions/upload-artifact@v2
with:
name: linux-bin-package
path: linux-bin.tar.xz
retention-days: 1

job2:
name: Build and Package on Windows
runs-on: windows-2019

steps:
- uses: actions/checkout@v2
with:
ref: ${{github.ref}}

- name: Create Build Environment
run: cmake -E make_directory ${{runner.workspace}}/build

- name: Configure CMake
shell: bash
working-directory: ${{runner.workspace}}/build
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE

- name: Build
working-directory: ${{runner.workspace}}/build
shell: bash
run: cmake --build . --config $BUILD_TYPE

- name: Package
if: ${{ success() }}
working-directory: ${{github.workspace}}
shell: bash
run: |
echo zip -r windows-bin.zip ./bin/
tar -Jcf windows-bin.tar.xz ./bin/
- name: Upload Artifact for Stage
if: ${{ success() }}
uses: actions/upload-artifact@v2
with:
name: windows-bin-package
path: windows-bin.tar.xz
retention-days: 1

job3:
name: Create Release and Upload Packages
needs: [job1, job2]
runs-on: ubuntu-latest
steps:
- name: Download Windows Artifacts
id: download-artifacts-win
uses: actions/download-artifact@v2
with:
name: windows-bin-package

- name: Download Linux Artifacts
id: download-artifacts-linux
uses: actions/download-artifact@v2
with:
name: linux-bin-package

- name: Truncate SHA
id: truncate-sha
uses: tangm421/[email protected]
#with:
# sha: ${{github.sha}}
# field-width: 7

- name: Create Release
if: ${{ steps.download-artifacts-win.conclusion == 'success' && steps.download-artifacts-linux.conclusion == 'success' && steps.truncate-sha.conclusion=='success' }}
id: create_release
uses: actions/create-release@v1
with:
tag_name: ${{ github.ref }}-${{steps.truncate-sha.outputs.sha-short}}
release_name: ${{ github.ref }}-${{steps.truncate-sha.outputs.sha-short}}
body: |
# Summary
This is a create release demo
# Changes in this Release
- First Change
- Second Change
draft: false
prerelease: false

- name: Upload Windows Release Asset
id: upload-win-release-asset
if: ${{ steps.create_release.conclusion == 'success' }}
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./windows-bin.tar.xz
asset_name: windows-bin.tar.xz
asset_content_type: application/form

- name: Upload Linux Release Asset
id: upload-linux-release-asset
if: ${{ steps.create_release.conclusion == 'success' }}
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./linux-bin.tar.xz
asset_name: linux-bin.tar.xz
asset_content_type: application/form

- name: Clean Artifacts
uses: geekyeggo/delete-artifact@v1
with:
name: |
windows-bin-package
linux-bin-package
59 changes: 59 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

build/
/m4/
!/m4/.gitignore

!/.github/workflows/*.yml

24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
sudo: required
language: c
os: linux

branches:
only:
- master

jobs:
include:
- name: cmake
script:
- echo -------------------------------------------
- mkdir build
- cd build
- cmake ../
- make
- name: automake
script:
- echo -------------------------------------------
- autoreconf --install
- ./configure
- make

58 changes: 58 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
cmake_minimum_required(VERSION 2.8.12.2)
project(clist)

set(PROJECT_VERSION_MAJOR 1)
set(PROJECT_VERSION_MINOR 0)
set(PROJECT_VERSION_PATCH 1)
set(PROJECT_VERSION_TWEAK 1114)
set(PACKAGE_VERSION \"${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_TWEAK}\")

if(NOT MSVC)
set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/clist/")
endif()

set (_DEFAULT_LIBRARY_INSTALL_DIR lib)
if (EXISTS "${CMAKE_INSTALL_PREFIX}/lib32/" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
set (_DEFAULT_LIBRARY_INSTALL_DIR lib32)
elseif (EXISTS "${CMAKE_INSTALL_PREFIX}/lib64/" AND CMAKE_SIZEOF_VOID_P EQUAL 8)
set (_DEFAULT_LIBRARY_INSTALL_DIR lib64)
endif ()

set(LIBRARY_INSTALL_DIR "${_DEFAULT_LIBRARY_INSTALL_DIR}" CACHE PATH "Library installation directory")
if(NOT IS_ABSOLUTE "${LIBRARY_INSTALL_DIR}")
set(LIBRARY_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${LIBRARY_INSTALL_DIR}")
endif()

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)

set(COMPILE_STATIC ON CACHE BOOL "Flag indicating if a static library should be built, or a dynamic one")
set(CLIST_DEBUG_ON OFF CACHE BOOL "Flag indicating if enable to print clist debug info")

if(NOT MSVC OR COMPILE_STATIC)
set(PROJECT_IMPORT "")
set(PROJECT_EXPORT "")
else()
set(PROJECT_IMPORT "__declspec(dllimport)")
set(PROJECT_EXPORT "__declspec(dllexport)")
endif()

if(NOT MSVC)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -Wall -g -ggdb")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -Wall")
endif()

set(PROJECT_LIB optimized "${LIBRARY_INSTALL_DIR}/clist.lib"
debug "${LIBRARY_INSTALL_DIR}/clist_d.lib")

configure_file(
"${PROJECT_SOURCE_DIR}/clist/config.h.in"
"${PROJECT_BINARY_DIR}/clist/config.h"
)
add_definitions(-DHAVE_CONFIG_H)

set(CLIST_INTERNAL_INCLUDES "${PROJECT_SOURCE_DIR}/clist" "${PROJECT_BINARY_DIR}/clist")

add_subdirectory(clist)
add_subdirectory(samples)
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2017 tangm

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 changes: 11 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

AUTOMAKE_OPTIONS = foreign
ACLOCAL_AMFLAGS = -I m4

SUBDIRS = clist
SUBDIRS += samples

cmakedatadir = $(datadir)/cmake
nobase_dist_cmakedata_DATA = ./CMakeLists.txt
nobase_dist_cmakedata_DATA += clist/CMakeLists.txt
nobase_dist_cmakedata_DATA += ./samples/CMakeLists.txt
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 1. clist

A simple test project for study

- how to use cmake
- how to use automake
- how to use Travis-CI
- how to use jsDelivr
- how to use badges
- how to use Github Actions
- how to use git commit with signature verification

---

[![Website](https://img.shields.io/website?down_message=offline&label=explore%20my%20blog&logo=Internet%20Explorer&style=for-the-badge&up_message=online&url=https%3A%2F%2Fblog.luanhui.cf "Welcome to my blog")](https://blog.luanhui.cf)
31 changes: 31 additions & 0 deletions clist/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

add_definitions(-DPROJECT_COMPILING)

if(CLIST_DEBUG_ON)
add_definitions(-DCLIST_DEBUG)
endif()

set(HEADERS
clist.h)

set(SOURCES
clist.c)

include_directories(${CLIST_INTERNAL_INCLUDES})

if(COMPILE_STATIC)
add_library(clist-static STATIC ${HEADERS} ${SOURCES})
set_target_properties(clist-static PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
set_target_properties(clist-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
set(CLIST_INSTALLTARGETS clist-static)
else()
add_library(clist-shared SHARED ${SOURCES} ${HEADERS})
set_target_properties(clist-shared PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
set_target_properties(clist-shared PROPERTIES CLEAN_DIRECT_OUTPUT 1)
set_target_properties(clist-shared PROPERTIES VERSION ${PACKAGE_VERSION})
set(CLIST_INSTALLTARGETS clist-shared)
endif()

install(FILES ${PROJECT_BINARY_DIR}/clist/config.h DESTINATION include)
install(FILES ${HEADERS} DESTINATION include)
install(TARGETS ${CLIST_INSTALLTARGETS} DESTINATION ${LIBRARY_INSTALL_DIR})
Loading

0 comments on commit 9a6a7ab

Please sign in to comment.