Skip to content

Commit

Permalink
Formatting updates (#24)
Browse files Browse the repository at this point in the history
* Formatting updates

- formatting workflow
- cmake-format
- updated clang-format version

* remove debug printing

* formatting workflow fix
  • Loading branch information
jrmadsen authored Dec 4, 2021
1 parent 32f9a3c commit 20fcd28
Show file tree
Hide file tree
Showing 25 changed files with 580 additions and 610 deletions.
74 changes: 74 additions & 0 deletions .cmake-format.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
parse:
additional_commands:
ptl_build_library:
flags:
- RECURSIVE
kwargs:
TYPE: '*'
TARGET_NAME: '*'
OUTPUT_NAME: '*'
SOURCES: '*'
EXTRA_ARGS: '*'
override_spec: {}
vartags: []
proptags: []
format:
disable: false
line_width: 90
tab_size: 4
use_tabchars: false
fractional_tab_policy: use-space
max_subgroups_hwrap: 2
max_pargs_hwrap: 8
max_rows_cmdline: 2
separate_ctrl_name_with_space: false
separate_fn_name_with_space: false
dangle_parens: false
dangle_align: child
min_prefix_chars: 4
max_prefix_chars: 10
max_lines_hwrap: 2
line_ending: unix
command_case: lower
keyword_case: upper
always_wrap: []
enable_sort: true
autosort: false
require_valid_layout: false
layout_passes: {}
markup:
bullet_char: '*'
enum_char: .
first_comment_is_literal: false
literal_comment_pattern: null
fence_pattern: ^\s*([`~]{3}[`~]*)(.*)$
ruler_pattern: ^\s*[^\w\s]{3}.*[^\w\s]{3}$
explicit_trailing_pattern: '#<'
hashruler_min_length: 10
canonicalize_hashrulers: true
enable_markup: true
lint:
disabled_codes: []
function_pattern: '[0-9a-z_]+'
macro_pattern: '[0-9A-Z_]+'
global_var_pattern: '[A-Z][0-9A-Z_]+'
internal_var_pattern: _[A-Z][0-9A-Z_]+
local_var_pattern: '[a-z][a-z0-9_]+'
private_var_pattern: _[0-9a-z_]+
public_var_pattern: '[A-Z][0-9A-Z_]+'
argument_var_pattern: '[a-z][a-z0-9_]+'
keyword_pattern: '[A-Z][0-9A-Z_]+'
max_conditionals_custom_parser: 2
min_statement_spacing: 1
max_statement_spacing: 2
max_returns: 6
max_branches: 12
max_arguments: 5
max_localvars: 15
max_statements: 50
encode:
emit_byteorder_mark: false
input_encoding: utf-8
output_encoding: utf-8
misc:
per_command: {}
64 changes: 64 additions & 0 deletions .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# This handles formatting for C/C++ source code and cmake code
name: formatting

on:
push:
branches: [ master, develop ]
pull_request:
branches: [ master, develop ]

jobs:
cxx-formatting:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y clang-format-9 cmake
- name: clang-format
run: |
cmake -B build-PTL -DPTL_USE_TBB=OFF .
cmake --build build-PTL --target format-source
rm -rf build-PTL
if [ $(git diff | wc -l) -gt 0 ]; then
echo -e "\nError! Source code not formatted. Run clang-format-9...\n"
echo -e "\nFiles:\n"
git diff --name-only
echo -e "\nFull diff:\n"
git diff
exit 1
fi
cmake-formatting:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.8]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake
python -m pip install --upgrade pip
pip install cmake-format pyyaml
- name: cmake format
run: |
cmake -B build-PTL -DPTL_USE_TBB=OFF .
cmake --build build-PTL --target format-cmake
rm -rf build-PTL
if [ $(git diff | wc -l) -gt 0 ]; then
echo -e "\nError! CMake code not formatted. Run cmake-format...\n"
echo -e "\nFiles:\n"
git diff --name-only
echo -e "\nFull diff:\n"
git diff
exit 1
fi
54 changes: 31 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
################################################################################
# cmake settings
# -------------------------------------------------------------------------------------- #
# cmake settings
#
cmake_minimum_required(VERSION 3.8...3.20)
if(${CMAKE_VERSION} VERSION_LESS 3.12)
Expand Down Expand Up @@ -28,15 +28,19 @@ string(REGEX REPLACE "(\n|\r)" "" VERSION_STRING "${VERSION_STRING}")
string(REGEX REPLACE "[A-Za-z].*" "" VERSION_STRING "${VERSION_STRING}")
set(PTL_VERSION "${VERSION_STRING}")

################################################################################
# project setup
# -------------------------------------------------------------------------------------- #
# -------------------------------------------------------------------------------------- #
# project setup
#
project(PTL LANGUAGES C CXX VERSION ${PTL_VERSION})
project(
PTL
LANGUAGES C CXX
VERSION ${PTL_VERSION})

# Postprocess version info to create variables for export to Version.hh
set(PTL_VERSION_STRING "${PTL_VERSION_MAJOR}.${PTL_VERSION_MINOR}.${PTL_VERSION_PATCH}")
math(EXPR PTL_VERSION_CODE
"10000 * ${PTL_VERSION_MAJOR} + 100 * ${PTL_VERSION_MINOR} + ${PTL_VERSION_PATCH}")
"10000 * ${PTL_VERSION_MAJOR} + 100 * ${PTL_VERSION_MINOR} + ${PTL_VERSION_PATCH}")

# Project-local CMake settings
set(CMAKE_DIRECTORY_LABELS "PTL")
Expand All @@ -47,47 +51,51 @@ set(CMAKE_LINK_DEPENDS_NO_SHARED ON)
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_LIST_DIR}/cmake/Modules)
include(PTLCMakeUtilities)

################################################################################
# -------------------------------------------------------------------------------------- #
# Build/Install settings and options
include(PTLInstallDirs)
include(PTLBuildSettings)

################################################################################
# -------------------------------------------------------------------------------------- #
# User options
ptl_add_option(PTL_USE_TBB "Enable TBB" ON)
ptl_add_option(PTL_USE_LOCKS "Enable mutex locking in task subqueues for extra safety" OFF)
ptl_add_option(PTL_USE_LOCKS "Enable mutex locking in task subqueues for extra safety"
OFF)
ptl_add_option(PTL_INSTALL_HEADERS "Install the headers" ON)
ptl_add_option(PTL_INSTALL_CONFIG "Install the cmake configuration" ON)

if(DEFINED PTL_DEVELOPER_INSTALL)
set(PTL_INSTALL_HEADERS ${PTL_DEVELOPER_INSTALL} CACHE BOOL "Set via PTL_DEVELOPER_INSTALL" FORCE)
set(PTL_INSTALL_CONFIG ${PTL_DEVELOPER_INSTALL} CACHE BOOL "Set via PTL_DEVELOPER_INSTALL" FORCE)
set(PTL_INSTALL_HEADERS
${PTL_DEVELOPER_INSTALL}
CACHE BOOL "Set via PTL_DEVELOPER_INSTALL" FORCE)
set(PTL_INSTALL_CONFIG
${PTL_DEVELOPER_INSTALL}
CACHE BOOL "Set via PTL_DEVELOPER_INSTALL" FORCE)
endif()

################################################################################
# Build Dependencies
# - Threads
# -------------------------------------------------------------------------------------- #
# Build Dependencies - Threads
if(NOT WIN32)
set(CMAKE_THREAD_PREFER_PTHREAD ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
endif()
find_package(Threads REQUIRED)

# - TBB
# * TBB
if(PTL_USE_TBB)
find_package(TBB 2017 REQUIRED)
endif()

################################################################################
# PTL Primary Build
# -------------------------------------------------------------------------------------- #
# PTL Primary Build
add_subdirectory(source)

################################################################################
# CMake/PkgConfig Support files
# -------------------------------------------------------------------------------------- #
# CMake/PkgConfig Support files
include(PTLPackageConfigHelpers)

################################################################################
# Examples build/test
# -------------------------------------------------------------------------------------- #
# Examples build/test
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/examples)
ptl_add_option(PTL_BUILD_EXAMPLES "Build examples" OFF)
if(PTL_BUILD_EXAMPLES)
Expand All @@ -96,8 +104,8 @@ if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/examples)
endif()
endif()

################################################################################
# Reporting if master project
# -------------------------------------------------------------------------------------- #
# Reporting if master project
if(PTL_MASTER_PROJECT)
ptl_print_features()
endif()
Loading

0 comments on commit 20fcd28

Please sign in to comment.