Skip to content

Commit

Permalink
Introduce cmake-format in CI (#229)
Browse files Browse the repository at this point in the history
* Introduce gersemi

* improve gersemircests and format CMakeLists.txt

* apply format

* apply cmake-format

* use cmake-format instead of gersemi in CI

* Add docstrings for formatting actions

---------

Co-authored-by: Yuuichi Asahi <y.asahi@nr.titech.ac.jp>
  • Loading branch information
yasahi-hpc and Yuuichi Asahi authored Feb 22, 2025
1 parent 1be955f commit 77161f5
Show file tree
Hide file tree
Showing 24 changed files with 592 additions and 642 deletions.
32 changes: 32 additions & 0 deletions .cmake-format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SPDX-FileCopyrightText: (C) The kokkos-fft development team, see COPYRIGHT.md file
#
# SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception

# -----------------------------
# Options affecting formatting.
# -----------------------------
with section("format"):

# How wide to allow formatted cmake files
line_width = 120

# If an argument group contains more than this many sub-groups (parg or kwarg
# groups) then force it to a vertical layout.
max_subgroups_hwrap = 3

# If a statement is wrapped to more than one line, than dangle the closing
# parenthesis on its own line.
dangle_parens = True

# If the trailing parenthesis must be 'dangled' on its on line, then align it
# to this reference: `prefix`: the start of the statement, `prefix-indent`:
# the start of the statement, plus one indentation level, `child`: align to
# the column of the arguments
dangle_align = 'prefix'

# ------------------------------------------------
# Options affecting comment reflow and formatting.
# ------------------------------------------------
with section("markup"):
# enable comment markup parsing and reflow
enable_markup = False
27 changes: 27 additions & 0 deletions .github/workflows/__clang-format-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# SPDX-FileCopyrightText: (C) The kokkos-fft development team, see COPYRIGHT.md file
#
# SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception

# This job verifies the code formatting of C++ source files using the clang-format lint action.
# If any formatting inconsistencies are found compared to the expected style, the job will fail
# and the differences will be displayed in the job log.
# See https://github.com/DoozyX/clang-format-lint-action for more details.

name: clang-format check

on:
workflow_call:

permissions: read-all

jobs:
clang-formatting-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DoozyX/clang-format-lint-action@v0.18
with:
source: 'common/ fft/ examples/ install_test/'
exclude: ''
extensions: 'hpp,cpp'
clangFormatVersion: 17
28 changes: 28 additions & 0 deletions .github/workflows/__cmake-format-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# SPDX-FileCopyrightText: (C) The kokkos-fft development team, see COPYRIGHT.md file
#
# SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception

# This job checks the CMake formatting using the cmake-format lint action.
# If any formatting inconsistencies are found compared to the expected style, the job will fail
# and the differences will be displayed in the job log.
# See https://github.com/puneetmatharu/cmake-format-lint-action for more details.

name: cmake-format check

on:
workflow_call:

permissions: read-all

jobs:
cmake-formatting-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: cmake-format lint action
uses: puneetmatharu/cmake-format-lint-action@2ac346e79e7ceac958bc637c1391285fb335ed7c # v1.0.5
with:
args: --config-files .cmake-format.py --in-place
file-regex: '(.*\.cmake$|.*\.cmake\.in$|CMakeLists.txt$)'
- name: check
run: git diff --exit-code
21 changes: 10 additions & 11 deletions .github/workflows/build_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@ env:
DOCKER_BUILDKIT: 1

jobs:
# [TO DO] Modularize the small actions for better readability
# of the main workflow file

# run linter on the code
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DoozyX/clang-format-lint-action@v0.18
with:
source: 'common/ fft/ examples/ install_test/'
exclude: ''
extensions: 'hpp,cpp'
clangFormatVersion: 17
clang-format-check:
uses: ./.github/workflows/__clang-format-check.yaml

# run cmake format check
cmake-format-check:
uses: ./.github/workflows/__cmake-format-check.yaml

# run typos for spell check
spell_check:
spell-check:
name: spell check with typos
runs-on: ubuntu-latest
steps:
Expand Down
127 changes: 51 additions & 76 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ cmake_minimum_required(VERSION 3.22)
set(KOKKOSFFT_TOP_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})

# Set project
project(
KokkosFFT
VERSION 0.2.1
LANGUAGES CXX
)
project(KokkosFFT VERSION 0.2.1 LANGUAGES CXX)

# Add cmake helpers
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
Expand All @@ -34,16 +30,16 @@ set(KOKKOSFFT_VERSION_PATCH ${PROJECT_VERSION_PATCH})

set(KOKKOS_REQUIRED_VERSION 4.4.0)

if (NOT KokkosFFT_ENABLE_INTERNAL_KOKKOS)
# First check, Kokkos is added as subdirectory or not
if(NOT TARGET Kokkos::kokkos)
find_package(Kokkos ${KOKKOS_REQUIRED_VERSION} REQUIRED)
# Check the alignment of complex numbers
kokkos_check(OPTIONS COMPLEX_ALIGN)
endif()
else ()
add_subdirectory(tpls/kokkos)
endif ()
if(NOT KokkosFFT_ENABLE_INTERNAL_KOKKOS)
# First check, Kokkos is added as subdirectory or not
if(NOT TARGET Kokkos::kokkos)
find_package(Kokkos ${KOKKOS_REQUIRED_VERSION} REQUIRED)
# Check the alignment of complex numbers
kokkos_check(OPTIONS COMPLEX_ALIGN)
endif()
else()
add_subdirectory(tpls/kokkos)
endif()

# Set tpls
set(KOKKOSFFT_TPL_LIST)
Expand All @@ -59,59 +55,52 @@ message("")
message(STATUS "KokkosFFT version: ${KOKKOSFFT_VERSION_MAJOR}.${KOKKOSFFT_VERSION_MINOR}.${KOKKOSFFT_VERSION_PATCH}")
message(STATUS "KokkosFFT TPLs:")
if(KOKKOSFFT_TPL_LIST)
include(KokkosFFT_utils)
foreach(BACKEND TPL IN ZIP_LISTS KOKKOSFFT_BACKEND_LIST KOKKOSFFT_TPL_LIST)
# [TO DO] show more information about the library (like location)
pad_string(BACKEND_PADDED "${BACKEND}" 13)
message(STATUS " ${BACKEND_PADDED}: ${TPL}")
endforeach()
include(KokkosFFT_utils)
foreach(BACKEND TPL IN ZIP_LISTS KOKKOSFFT_BACKEND_LIST KOKKOSFFT_TPL_LIST)
# [TO DO] show more information about the library (like location)
pad_string(BACKEND_PADDED "${BACKEND}" 13)
message(STATUS " ${BACKEND_PADDED}: ${TPL}")
endforeach()
else()
message(STATUS " (None)")
message(STATUS " (None)")
endif()
message("")

# Googletest
if(KokkosFFT_ENABLE_TESTS)
include(CTest)
find_package(GTest CONFIG)
if(NOT GTest_FOUND)
add_subdirectory(tpls/googletest)
endif()
include(CTest)
find_package(GTest CONFIG)
if(NOT GTest_FOUND)
add_subdirectory(tpls/googletest)
endif()
endif()

# Build documentation with Doxygen and Sphinx
if(KokkosFFT_ENABLE_DOCS)
find_package(Doxygen REQUIRED)
find_package(Sphinx REQUIRED)
add_subdirectory(docs)
find_package(Doxygen REQUIRED)
find_package(Sphinx REQUIRED)
add_subdirectory(docs)
endif()

# Benchmark
if(KokkosFFT_ENABLE_BENCHMARK)
option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." OFF)
add_subdirectory(tpls/benchmark)
include(KokkosFFT_Git_Hash)

# [TO DO] Fix this, it detects benchmark not a googlebench
#find_package(benchmark QUIET)
#if(NOT benchmark_FOUND)
# add_subdirectory(tpls/benchmark)
#endif()
option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." OFF)
add_subdirectory(tpls/benchmark)
include(KokkosFFT_Git_Hash)

# [TO DO] Fix this, it detects benchmark not a googlebench
#find_package(benchmark QUIET)
#if(NOT benchmark_FOUND)
# add_subdirectory(tpls/benchmark)
#endif()
endif()

# Configure files to display configuration
# Configure the library
set(
PACKAGE_NAME_CONFIG_FILES
KokkosFFT_config.h
KokkosFFT_Version_Info.hpp
)
set(PACKAGE_NAME_CONFIG_FILES KokkosFFT_config.h KokkosFFT_Version_Info.hpp)

foreach(CONFIG_FILE ${PACKAGE_NAME_CONFIG_FILES})
configure_file(
cmake/${CONFIG_FILE}.in
${CMAKE_BINARY_DIR}/${CONFIG_FILE}
)
configure_file(cmake/${CONFIG_FILE}.in ${CMAKE_BINARY_DIR}/${CONFIG_FILE})
endforeach()

# Set directories used for install
Expand All @@ -124,47 +113,33 @@ set(KokkosFFT_EXPORT_TARGET "${PROJECT_NAME}-Targets")
add_subdirectory(common)
add_subdirectory(fft)
if(KokkosFFT_ENABLE_EXAMPLES)
add_subdirectory(examples)
add_subdirectory(examples)
endif()

# Installation
include(CMakePackageConfigHelpers)

install(
TARGETS common fft
EXPORT ${KokkosFFT_EXPORT_TARGET}
)

install(
EXPORT ${KokkosFFT_EXPORT_TARGET}
NAMESPACE KokkosFFT::
DESTINATION ${INSTALL_LIBDIR}
)
install(TARGETS common fft EXPORT ${KokkosFFT_EXPORT_TARGET})
install(EXPORT ${KokkosFFT_EXPORT_TARGET} NAMESPACE KokkosFFT:: DESTINATION ${INSTALL_LIBDIR})

install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/common/src/ ${CMAKE_CURRENT_SOURCE_DIR}/fft/src/
DESTINATION ${INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp"
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/common/src/ ${CMAKE_CURRENT_SOURCE_DIR}/fft/src/
DESTINATION ${INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.hpp"
)

install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindFFTW.cmake
DESTINATION ${INSTALL_LIBDIR}
)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindFFTW.cmake DESTINATION ${INSTALL_LIBDIR})

configure_package_config_file(cmake/KokkosFFTConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/KokkosFFTConfig.cmake
INSTALL_DESTINATION ${INSTALL_LIBDIR}
configure_package_config_file(
cmake/KokkosFFTConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/KokkosFFTConfig.cmake
INSTALL_DESTINATION ${INSTALL_LIBDIR}
)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/KokkosFFTConfigVersion.cmake
VERSION ${KokkosFFT_VERSION}
COMPATIBILITY SameMajorVersion
${CMAKE_CURRENT_BINARY_DIR}/KokkosFFTConfigVersion.cmake VERSION ${KokkosFFT_VERSION} COMPATIBILITY SameMajorVersion
)

install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/KokkosFFTConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/KokkosFFTConfigVersion.cmake
DESTINATION ${INSTALL_LIBDIR}
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/KokkosFFTConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/KokkosFFTConfigVersion.cmake
DESTINATION ${INSTALL_LIBDIR}
)
Loading

0 comments on commit 77161f5

Please sign in to comment.