Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize build system, README, and add Github Actions CI/CD #50

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
70 changes: 70 additions & 0 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Github Actions CI CD

on: [push, pull_request]

jobs:
ci_cd:
name: CI/CD

strategy:
matrix:
os: [ubuntu-20.04, ubuntu-18.04, windows-2019, macos-11, macos-10.15]
openssl: ["ON", "OFF"]
pthreads: ["ON", "OFF"]
fail-fast: false

runs-on: ${{ matrix.os }}

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Windows - setup MSYS2/UCRT64
if: matrix.os == 'windows-2019'
uses: msys2/setup-msys2@v2
with:
release: true
msystem: UCRT64
update: true
install: >-
git
ucrt64/mingw-w64-ucrt-x86_64-toolchain
ucrt64/mingw-w64-ucrt-x86_64-ninja
ucrt64/mingw-w64-ucrt-x86_64-cmake
ucrt64/mingw-w64-ucrt-x86_64-openssl

# statically link OpenSSL on macOS CI/CD binaries
- name: macOS - setup OpenSSL
if: matrix.os == 'macos-10.15'
run: |
echo "OPENSSL_ROOT_DIR=/usr/local/opt/openssl" >> $GITHUB_ENV
echo "MACOS_STATIC_OPENSSL=-DOPENSSL_USE_STATIC_LIBS=ON" >> $GITHUB_ENV

- name: Linux, macOS - build
if: matrix.os != 'windows-2019'
run: |
cmake -S . -B build $MACOS_STATIC_OPENSSL -DMKTORRENT_LONG_OPTIONS=ON -DMKTORRENT_PTHREADS=${{ matrix.pthreads }} -DMKTORRENT_OPENSSL=${{ matrix.openssl }} -DMKTORRENT_USE_GITREV_VERSION=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_EXPORT_COMPILE_COMMANDS=ON --graphviz=build/target_graph.dot
cmake --build build

- name: Windows - build with MSYS2/UCRT64
if: matrix.os == 'windows-2019'
shell: msys2 {0}
run: |
cmake -S . -B build -G "Ninja" -DOPENSSL_USE_STATIC_LIBS=ON -DMKTORRENT_LONG_OPTIONS=ON -DMKTORRENT_PTHREADS=${{ matrix.pthreads }} -DMKTORRENT_OPENSSL=${{ matrix.openssl }} -DMKTORRENT_USE_GITREV_VERSION=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_EXPORT_COMPILE_COMMANDS=ON --graphviz=build/target_graph.dot
cmake --build build

- name: Get short commit hash for artifact name
shell: bash
run: |
short_hash=$(echo ${{ github.sha }} | cut -c1-7)
echo "MKTORRENT_SHORT_HASH=$short_hash" >> $GITHUB_ENV

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: mktorrent-${{ env.MKTORRENT_SHORT_HASH }}_${{ matrix.os }}_openssl-${{ matrix.openssl }}_pthreads-${{ matrix.pthreads }}
path: |
build/mktorrent
build/mktorrent.exe
build/compile_commands.json
build/target_graph.dot
12 changes: 3 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# git-ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
*.[oa]
*~
mktorrent
prefix
*.torrent
# assuming out-of-tree builds inside ./build/, this is enough
build/
compile_commands.json
67 changes: 0 additions & 67 deletions BSDmakefile

This file was deleted.

3 changes: 3 additions & 0 deletions CMakeGraphVizOptions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set(GRAPHVIZ_CUSTOM_TARGETS ON)
set(GRAPHVIZ_GENERATE_PER_TARGET OFF)
set(GRAPHVIZ_GENERATE_DEPENDERS OFF)
172 changes: 172 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
cmake_minimum_required(VERSION 3.20 FATAL_ERROR) # Configurable policies: <= CMP0120

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")

project(mktorrent
VERSION 1.1
DESCRIPTION "A simple command-line utility to create BitTorrent metainfo files, written in C"
HOMEPAGE_URL "https://github.com/Rudde/mktorrent"
LANGUAGES C
)

# set a default build type when none is specified for single-config generators
include(DefaultBuildType)
set_default_build_type(DEFAULT_BUILD_TYPE "Release")

get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(isMultiConfig)
set(MKTORRENT_BUILD_CONFIG "$<CONFIG>")
else()
set(MKTORRENT_BUILD_CONFIG "${CMAKE_BUILD_TYPE}")
endif()

# use CONFIG mode first in find_package
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
# dependency version requirements
set(requiredOpenSSLVersion "1.1.1")

# feature definition and setup
include(FeatureSummary)
include(OptionUtils)

feature_option_setup(
NAME MKTORRENT_LONG_OPTIONS
DESCRIPTION "Enable long options, started with two dashes"
DEFAULT ON
)
feature_option_setup(
NAME MKTORRENT_NO_HASH_CHECK
DESCRIPTION "Disable checking if amount of bytes read for file hashing matches initially reported sizes\n(useless unless, for some strange reason, you change files yet to be hashed while mktorrent is running)"
DEFAULT OFF
)
feature_option_setup(
NAME MKTORRENT_OPENSSL
DESCRIPTION "Use OpenSSL's SHA-1 implementation instead of compiling our own"
DEFAULT ON
)
feature_option_setup(
NAME MKTORRENT_PTHREADS
DESCRIPTION "Use multiple POSIX threads for calculating hashes - should be much faster in systems with multiple CPU cores and fast storage"
DEFAULT ON
)
feature_option_setup(
NAME MKTORRENT_USE_GITREV_VERSION
DESCRIPTION "Use a version string with git revision information, if available\n(note that git revision information is only updated on re-configure)"
DEFAULT OFF
)
feature_option_setup(
NAME MKTORRENT_VERBOSE_CONFIGURE
DESCRIPTION "Show information about PACKAGES_FOUND and PACKAGES_NOT_FOUND in the configure output\n(only useful for debugging the CMake build scripts)"
DEFAULT OFF
)
feature_tunable_setup(
NAME MKTORRENT_MAX_OPENFD
DESCRIPTION "Maximum number of simultaneously opened files descriptors when scanning a directory"
DEFAULT 100
LIST TUNABLES_LIST
)
feature_tunable_setup(
NAME MKTORRENT_PROGRESS_PERIOD
DESCRIPTION "Progress report update interval when hashing multithreaded, in μs"
DEFAULT 200000
LIST TUNABLES_LIST
)

if(MKTORRENT_OPENSSL)
find_package(OpenSSL "${requiredOpenSSLVersion}" REQUIRED)
endif()

if(MKTORRENT_PTHREADS)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
endif()

if(MKTORRENT_USE_GITREV_VERSION)
include(GitRevisionString)
make_git_revision_string(
BASE_VERSION "${PROJECT_VERSION}"
OUT_VAR MKTORRENT_GITREV_VERSION
)
endif()

add_executable(mktorrent)

target_sources(mktorrent
PRIVATE
# headers
src/export.h
src/ftw.h
src/hash.h
src/init.h
src/ll.h
src/mktorrent.h
src/msg.h
src/output.h
$<$<NOT:$<BOOL:${MKTORRENT_OPENSSL}>>:src/sha1.h>

# sources
src/ftw.c
src/init.c
src/ll.c
src/main.c
src/msg.c
src/output.c
$<IF:$<BOOL:${MKTORRENT_PTHREADS}>,src/hash_pthreads.c,src/hash.c>
$<$<NOT:$<BOOL:${MKTORRENT_OPENSSL}>>:src/sha1.c>
)

target_compile_features(mktorrent
PRIVATE
c_std_99
c_function_prototypes
c_variadic_macros
)

target_compile_definitions(mktorrent
PRIVATE
_FILE_OFFSET_BITS=64
$<IF:$<BOOL:${MKTORRENT_USE_GITREV_VERSION}>,VERSION="${MKTORRENT_GITREV_VERSION}",VERSION="${PROJECT_VERSION}">
$<$<BOOL:${MKTORRENT_PTHREADS}>:USE_PTHREADS>
$<$<BOOL:${MKTORRENT_OPENSSL}>:USE_OPENSSL>
$<$<BOOL:${MKTORRENT_LONG_OPTIONS}>:USE_LONG_OPTIONS>
$<$<BOOL:${MKTORRENT_NO_HASH_CHECK}>:NO_HASH_CHECK>
$<IF:$<EQUAL:${MKTORRENT_MAX_OPENFD},100>,MAX_OPENFD=100,MAX_OPENFD="${MKTORRENT_MAX_OPENFD}">
$<IF:$<EQUAL:${MKTORRENT_PROGRESS_PERIOD},200000>,PROGRESS_PERIOD=200000,PROGRESS_PERIOD="${MKTORRENT_PROGRESS_PERIOD}">
BUILD_CFG="${MKTORRENT_BUILD_CONFIG}"
)

target_compile_options(mktorrent
PRIVATE
-Wall
-Wextra
-Wpedantic
$<$<BOOL:${MKTORRENT_PTHREADS}>:-pthread>
)

target_link_libraries(mktorrent
PRIVATE
$<$<BOOL:${MKTORRENT_OPENSSL}>:OpenSSL::Crypto>
$<$<BOOL:${MKTORRENT_PTHREADS}>:Threads::Threads>
)

target_link_options(mktorrent
PRIVATE
$<$<OR:$<BOOL:${MINGW}>,$<BOOL:${MSYS}>>:-static>
$<$<BOOL:${MKTORRENT_PTHREADS}>:-pthread>
)

include(GNUInstallDirs)
install(TARGETS mktorrent RUNTIME COMPONENT runtime)

set(VERSION_MSG "${PROJECT_VERSION}")
if(MKTORRENT_USE_GITREV_VERSION)
set(VERSION_MSG "${MKTORRENT_GITREV_VERSION}")
endif()
message(STATUS "Project version string: \"${VERSION_MSG}\"")

if(MKTORRENT_VERBOSE_CONFIGURE)
feature_summary(WHAT ALL)
else()
feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES)
endif()
print_tunables(LIST TUNABLES_LIST)
64 changes: 0 additions & 64 deletions GNUmakefile

This file was deleted.

Loading