Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4edf622
ci modifications (partial)
Feb 18, 2026
40a8a10
adding clang tidy and clang format files
Feb 18, 2026
6a8ebe1
bumped clang format to 21
Feb 21, 2026
d2bfc4f
adding clang tidy and clang format files
Feb 18, 2026
92ec4af
Merge branch '_master/add_ci_clang_format_enforcement' of https://git…
Feb 21, 2026
5d15c93
Merge branch 'master' into _master/add_ci_clang_format_enforcement
codethinki Feb 21, 2026
9c4a6d6
added the clang format target
Feb 22, 2026
d95ab79
moved clang format version to 19 (maybe that works)
Feb 22, 2026
3f19fe0
updated the check-clang-format away from jidicula bc it just didnt work
Feb 22, 2026
482d739
added files per thread to hopefully speed up the formatting check
Feb 22, 2026
6e8ac15
updated the "on" to only run for pr's and pushes to master
Feb 22, 2026
02f5276
Merge branch 'master' into _master/add_ci_clang_format_enforcement
codethinki Feb 22, 2026
7b4b8e4
Merge branch '_master/add_ci_clang_format_enforcement' of https://git…
Feb 22, 2026
86d412f
a few changes to formatting and added the format target
Feb 22, 2026
906c05d
added uncrustify to try
Feb 22, 2026
fbdf445
some corrections and uncrustify file added
Feb 22, 2026
1b705b8
now using uncrustify
Feb 23, 2026
a3d14c0
formatted everything with uncrustify
Feb 23, 2026
40551e0
added .cu files to cpp globber
Feb 23, 2026
8198ad5
formatted .cu files
Feb 23, 2026
470c33a
One liner ifs and fors now are broken but omit braces
Feb 23, 2026
9742f51
more formatting improvements
Feb 23, 2026
c8c65e5
formatted more code according to style
Feb 23, 2026
02fcd2c
for some reason something else was formatted again
Feb 23, 2026
5606612
fixed cout indenting
Feb 23, 2026
e6db0d6
using arch instead of ubuntu
Feb 23, 2026
1b30dfd
forgot to make uncrustify target optional
Feb 23, 2026
75adc94
fixed another formatting bug
Feb 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
94 changes: 0 additions & 94 deletions .clang-format

This file was deleted.

7 changes: 6 additions & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
.github/workflows/ @codethinki
ci/docker/ @codethinki

CITATION @codethinki
LICENSE @codethinki
.clang-format @codethinki
FLASHLIGHT_LICENSE @codethinki

.clang_tidy @codethinki
uncrustify.cfg @codethinki

40 changes: 40 additions & 0 deletions .github/workflows/check-formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Uncrustify Format

on:
push: { branches: ["master", "_master/add_ci"] }
pull_request: { branches: ["master"] }

permissions: { contents: read }

# ---------------------------------------------------------
# CONFIG
# ---------------------------------------------------------
env:
UNCRUSTIFY_CONFIG: "uncrustify.cfg"
CHECK_PATH: "flashlight"
FILE_EXTENSIONS: "c|cpp|h|hpp|cu"

# ---------------------------------------------------------
# JOB
# ---------------------------------------------------------
jobs:
formatting-check:
name: Format check
runs-on: ubuntu-latest
container: archlinux:latest
steps:
- name: Install Git and Uncrustify
run: pacman -Syu --noconfirm git uncrustify

- uses: actions/checkout@v4

- name: Run uncrustify style check
run: |
# Print the version to confirm you are on the absolute latest version
uncrustify --version

find ${{ env.CHECK_PATH }} \
-type f \
-regextype posix-extended \
-regex ".*\.(${{ env.FILE_EXTENSIONS }})$" \
| uncrustify -q -c ${{ env.UNCRUSTIFY_CONFIG }} --check -F -
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,9 @@ include(${FL_ROOT_DIR}/pkg/CMakeLists.txt)

# --------------------------- Cleanup ---------------------------
setup_install_targets(INSTALL_TARGETS ${INSTALLABLE_TARGETS})

# --------------------------- Other ------------------------------
include(fm_target_utilities)
fm_glob_cpp(FM_CPP "flashlight/*")

fm_add_uncrustify_target(uncrustify-format OPTIONAL ${FM_CPP})
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ flashmini is still under development; we appreciate any contributions.
## Pull Requests
We actively welcome your pull requests.

1. Fork the repo and create your branch from `master`.
1. Fork the repo and create your branch from `master`. Naming style of `_master/your_feature` is preferred
2. If you've added code that should be tested, add tests.
3. If you've changed APIs, update [and build](docs/README.md) the documentation (to check correctness - don't submit built documentation).
4. Ensure the test suite passes.
5. Make sure your code lints and run `clang-format` given the provided configuration.
5. Make sure your code lints and run `uncrustify format` given the provided configuration. Alternatively you can build the `uncrustify-format` target.

## Issues
We use [GitHub issues](https://github.com/flashmini/flashmini/issues) to track public bugs. When filing, a bug, please make sure your description is clear and include sufficient instructions to reproduce the issue (for instance, your OS, compiler version, and selected backend).
Expand Down
File renamed without changes.
File renamed without changes.
115 changes: 89 additions & 26 deletions cmake/utils/fm_target_utilities.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ endfunction()

#]]
function(fm_glob_cpp OUT_VAR)
fm_glob(${OUT_VAR} ${ARGN} PATTERNS "*.cpp" "*.hpp" "*.inl")
fm_glob(${OUT_VAR} ${ARGN} PATTERNS "*.cpp" "*.hpp" "*.inl" "*.h" "*.cu" "*.cuh")
set(${OUT_VAR} ${${OUT_VAR}} PARENT_SCOPE)
endfunction()

Expand Down Expand Up @@ -366,58 +366,121 @@ endfunction()

.. code-block:: cmake

fm_add_clang_format_target(<files...>)
fm_add_clang_format_target(<target_name> [OPTIONAL] <files...>)

Creates a custom target named "format" that runs clang-format on specified files.
Creates a custom target that runs clang-format on specified files.
If OPTIONAL is specified, does not error and skips target creation if clang-format is not found.

:param target_name: Name of the custom target to create
:param OPTIONAL: If specified, do not raise FATAL_ERROR if clang-format is not found
:param files: List of source files to format
:type files: list of file paths

:pre: clang-format executable is available in PATH
:post: A custom target named "format" is created that formats the specified files in-place
:post: A custom target is created if found, or configuration terminates with FATAL_ERROR if not found (unless OPTIONAL)

.. note::
- The format target uses ``-i`` flag to format files in-place
- The ``-style=file`` flag means clang-format will look for a .clang-format configuration file
- Files are formatted relative to CMAKE_SOURCE_DIR

.. warning::
This function will fail if clang-format is not found in PATH.
.. seealso::
- ``fm_find_clang_format(OPTIONAL)`` from fm_tool_utilities to locate clang-format optionally

#]]
function(fm_add_clang_format_target TARGET_NAME)
cmake_parse_arguments(PARSE_ARGV 1 ARG "OPTIONAL" "" "")

# Use a different variable name to avoid conflicts with the parsed ARG_OPTIONAL boolean
if(ARG_OPTIONAL)
set(FIND_OPTIONAL_ARG "OPTIONAL")
else()
set(FIND_OPTIONAL_ARG "")
endif()

fm_assert_not_empty("${TARGET_NAME}" REASON "add_clang_format_target requires a target name")

# Use ARG_UNPARSED_ARGUMENTS instead of ARGN so "OPTIONAL" isn't treated as a file
set(FILES_TO_FORMAT ${ARG_UNPARSED_ARGUMENTS})
fm_assert_not_empty("${FILES_TO_FORMAT}" REASON "no files provided")

include(fm_tool_utilities)

**Example usage:**
# Pass the safely stored string to the find function
fm_find_clang_format(${FIND_OPTIONAL_ARG})
if(NOT CLANG_FORMAT_EXECUTABLE)
return()
endif()

set(FILE_LIST_PATH "${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}_files.txt")
string(REPLACE ";" "\n" FILES_TO_FORMAT_STR "${FILES_TO_FORMAT}")
file(WRITE "${FILE_LIST_PATH}" "${FILES_TO_FORMAT_STR}\n")

add_custom_target(
${TARGET_NAME}
COMMAND ${CLANG_FORMAT_EXECUTABLE} -i -style=file --files=${FILE_LIST_PATH}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Formatting all source files with clang-format..."
VERBATIM
)
endfunction()

#[[.rst:
.. command:: fm_add_uncrustify_target

.. code-block:: cmake

# Format specific files
fm_add_clang_format_target(
src/main.cpp
src/utils.cpp
include/header.hpp
)
fm_add_uncrustify_target(<target_name> [OPTIONAL] <files...>)

Creates a custom target that runs uncrustify on specified files.
If OPTIONAL is specified, does not error and skips target creation if uncrustify is not found.

# Then run: cmake --build . --target format
:param target_name: Name of the custom target to create
:param OPTIONAL: If specified, do not raise FATAL_ERROR if uncrustify is not found
:param files: List of source files to format

:pre expects uncrustify.cfg in root directory
:post: A custom target is created if found, or configuration terminates with FATAL_ERROR if not found (unless OPTIONAL)

.. note::
- The format target uses ``--replace`` and ``--no-backup`` flags to format files in-place
- The ``-F`` flag is used to pass the text file containing the list of files to format
- Files are formatted relative to CMAKE_SOURCE_DIR
- Uncrustify will look for an uncrustify.cfg file in the working directory or rely on the UNCRUSTIFY_CONFIG environment variable.

.. seealso::
- ``fm_find_clang_format()`` from fm_tool_utilities to locate clang-format
- Create a .clang-format file in your project root to define formatting style
- ``fm_find_uncrustify(OPTIONAL)`` from fm_tool_utilities to locate uncrustify optionally

#]]
function(fm_add_clang_format_target TARGET_NAME)
fm_assert_not_empty(${TARGET_NAME} REASON "add_clang_format_target requires a target name")
function(fm_add_uncrustify_target TARGET_NAME)
cmake_parse_arguments(PARSE_ARGV 1 ARG "OPTIONAL" "" "")

# Use a different variable name to avoid being overwritten by cmake_parse_arguments
if(ARG_OPTIONAL)
set(FIND_OPTIONAL_ARG "OPTIONAL")
else()
set(FIND_OPTIONAL_ARG "")
endif()

include(fm_tool_utilities)
fm_find_clang_format()
fm_assert_not_empty("${TARGET_NAME}" REASON "add_uncrustify_target requires a target name")

set(FILES_TO_FORMAT ${ARG_UNPARSED_ARGUMENTS})
fm_assert_not_empty("${FILES_TO_FORMAT}" REASON "no files provided")

set(FILES_TO_FORMAT ${ARGN})
include(fm_tool_utilities)


fm_find_uncrustify(${FIND_OPTIONAL_ARG})
if(NOT UNCRUSTIFY_EXECUTABLE)
return()
endif()

set(FILE_LIST_PATH "${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}_files.txt")
string(REPLACE ";" "\n" FILES_TO_FORMAT_STR "${FILES_TO_FORMAT}")
file(WRITE "${FILE_LIST_PATH}" "${FILES_TO_FORMAT_STR}\n")

add_custom_target(
${TARGET_NAME}
COMMAND ${CLANG_FORMAT_EXECUTABLE} -i -style=file ${FILES_TO_FORMAT}
COMMAND ${UNCRUSTIFY_EXECUTABLE} --replace --no-backup -c uncrustify.cfg -q -F ${FILE_LIST_PATH}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Formatting all source files with clang-format..."
COMMENT "Formatting all source files with uncrustify..."
VERBATIM
)
endfunction()
Expand Down
28 changes: 28 additions & 0 deletions cmake/utils/fm_tool_utilities.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,31 @@ function(fm_find_clang_format)

set(CLANG_FORMAT_EXECUTABLE ${CLANG_FORMAT_EXECUTABLE} PARENT_SCOPE)
endfunction()

#[[.rst:
.. command:: fm_find_uncrustify

.. code-block:: cmake

fm_find_uncrustify([OPTIONAL])

Locates a required uncrustify executable and exports its path to the parent scope.
If OPTIONAL is specified, does not error if uncrustify is not found.

:post: UNCRUSTIFY_EXECUTABLE is set in PARENT_SCOPE with the full path to uncrustify, or configuration terminates with FATAL_ERROR if not found and not OPTIONAL

.. seealso::
Use ``fm_add_uncrustify_target()`` from fm_target_utilities to create a format target.

#]]
function(fm_find_uncrustify)
cmake_parse_arguments(PARSE_ARGV 0 ARG "OPTIONAL" "" "")

if(ARG_OPTIONAL)
fm_find_program(UNCRUSTIFY_EXECUTABLE uncrustify OPTIONAL)
else()
fm_find_program(UNCRUSTIFY_EXECUTABLE uncrustify)
endif()

set(UNCRUSTIFY_EXECUTABLE ${UNCRUSTIFY_EXECUTABLE} PARENT_SCOPE)
endfunction()
Loading
Loading