Skip to content

Commit

Permalink
Merge pull request #37 from stephenswat/ci/gersemi
Browse files Browse the repository at this point in the history
Add gersemi formatting for CMake files
  • Loading branch information
stephenswat authored Nov 7, 2024
2 parents 7759659 + 439d6f4 commit f1732e6
Show file tree
Hide file tree
Showing 25 changed files with 300 additions and 462 deletions.
2 changes: 2 additions & 0 deletions .gersemirc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
line_length: 80
list_expansion: favour-expansion
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ repos:
language: system
entry: ci/check_license.py
files: \.(cpp|hpp|ipp|cu|cuh)$

- repo: https://github.com/BlankSpruce/gersemi
rev: "0.17.0"
hooks:
- id: gersemi
41 changes: 8 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,19 @@

cmake_minimum_required(VERSION 3.18)

project(
"covfie"
VERSION 0.10.0
)
project("covfie" VERSION 0.10.0)

# Declare options which control the parts of the code being built.
option(
COVFIE_BUILD_BENCHMARKS
"Build benchmark executables."
)
option(
COVFIE_BUILD_TESTS
"Build test executables."
)
option(
COVFIE_BUILD_EXAMPLES
"Build example executables."
)
option(COVFIE_BUILD_BENCHMARKS "Build benchmark executables.")
option(COVFIE_BUILD_TESTS "Build test executables.")
option(COVFIE_BUILD_EXAMPLES "Build example executables.")

# Declare option to enable header completeness tests.
option(
COVFIE_TEST_HEADERS
"Enable header completeness tests."
)
option(COVFIE_TEST_HEADERS "Enable header completeness tests.")

# Declare options for the different platforms that we wish to support.
option(
COVFIE_PLATFORM_CPU
"Enable building of CPU code."
On
)
option(
COVFIE_PLATFORM_CUDA
"Enable building of CUDA code."
)
option(COVFIE_PLATFORM_CPU "Enable building of CPU code." On)
option(COVFIE_PLATFORM_CUDA "Enable building of CUDA code.")

# Additional options that may be useful in some cases, such as CI.
option(
Expand All @@ -56,10 +34,7 @@ option(
"Disable warnings about missing C++ features. Enabling this is strongly discouraged."
)

option(
COVFIE_FAIL_ON_WARNINGS
"Treat compiler warnings as errors."
)
option(COVFIE_FAIL_ON_WARNINGS "Treat compiler warnings as errors.")

# Make the CMake modules in the cmake/ directory visible to the project.
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
Expand Down
6 changes: 1 addition & 5 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
find_package(benchmark CONFIG REQUIRED)

# All of these benchmarks rely on the Boost MP11 library.
find_package(
Boost
1.71.0
REQUIRED
)
find_package(Boost 1.71.0 REQUIRED)

# Set up the C++ compiler flags for the benchmarks.
include(covfie-compiler-options-cpp)
Expand Down
23 changes: 4 additions & 19 deletions benchmarks/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,10 @@
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at http://mozilla.org/MPL/2.0/.

add_library(
benchmark
test_field.cpp
)
add_library(benchmark test_field.cpp)

target_include_directories(
benchmark
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
target_include_directories(benchmark PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(
benchmark
PUBLIC
core
)
target_link_libraries(benchmark PUBLIC core)

target_compile_definitions(
benchmark
PRIVATE
_CRT_SECURE_NO_WARNINGS
)
target_compile_definitions(benchmark PRIVATE _CRT_SECURE_NO_WARNINGS)
17 changes: 6 additions & 11 deletions benchmarks/cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,15 @@
# obtain one at http://mozilla.org/MPL/2.0/.

# Create the benchmark executable from the individual files.
add_executable(
benchmark_cpu

benchmark_cpu.cpp
)
add_executable(benchmark_cpu benchmark_cpu.cpp)

# Ensure that the tests are linked against the required libraries.
target_link_libraries(
benchmark_cpu

PUBLIC
core
cpu
benchmark
benchmark::benchmark
Boost::headers
core
cpu
benchmark
benchmark::benchmark
Boost::headers
)
17 changes: 6 additions & 11 deletions benchmarks/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,15 @@ enable_language(CUDA)
include(covfie-compiler-options-cuda)

# Create the benchmark executable from the individual files.
add_executable(
benchmark_cuda

benchmark_cuda.cu
)
add_executable(benchmark_cuda benchmark_cuda.cu)

# Ensure that the tests are linked against the required libraries.
target_link_libraries(
benchmark_cuda

PUBLIC
core
cuda
benchmark
benchmark::benchmark
Boost::headers
core
cuda
benchmark
benchmark::benchmark
Boost::headers
)
19 changes: 7 additions & 12 deletions benchmarks/openmp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,16 @@
find_package(OpenMP COMPONENTS CXX REQUIRED)

# Create the benchmark executable from the individual files.
add_executable(
benchmark_openmp

benchmark_openmp.cpp
)
add_executable(benchmark_openmp benchmark_openmp.cpp)

# Ensure that the tests are linked against the required libraries.
target_link_libraries(
benchmark_openmp

PUBLIC
core
cpu
benchmark
OpenMP::OpenMP_CXX
benchmark::benchmark
Boost::headers
core
cpu
benchmark
OpenMP::OpenMP_CXX
benchmark::benchmark
Boost::headers
)
71 changes: 38 additions & 33 deletions cmake/covfie-compiler-options-cpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,44 @@
# obtain one at http://mozilla.org/MPL/2.0/.

# Include the helper function(s).
include( covfie-functions )
include(covfie-functions)

# Turn on a number of warnings for the "known compilers".
if( ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" ) OR
( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) )

# Basic flags for all build modes.
covfie_add_flag( CMAKE_CXX_FLAGS "-Wall" )
covfie_add_flag( CMAKE_CXX_FLAGS "-Wextra" )
covfie_add_flag( CMAKE_CXX_FLAGS "-Wshadow" )
covfie_add_flag( CMAKE_CXX_FLAGS "-Wunused-local-typedefs" )
covfie_add_flag( CMAKE_CXX_FLAGS "-pedantic" )
covfie_add_flag( CMAKE_CXX_FLAGS "-Wfloat-conversion" )
covfie_add_flag( CMAKE_CXX_FLAGS "-Wconversion" )

# Fail on warnings, if asked for that behaviour.
if( COVFIE_FAIL_ON_WARNINGS )
covfie_add_flag( CMAKE_CXX_FLAGS "-Werror" )
endif()

elseif( "${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC" )

# Basic flags for all build modes.
string( REGEX REPLACE "/W[0-9]" "" CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS}" )
covfie_add_flag( CMAKE_CXX_FLAGS "/W4" )

# Fail on warnings, if asked for that behaviour.
if( COVFIE_FAIL_ON_WARNINGS )
covfie_add_flag( CMAKE_CXX_FLAGS "/WX" )
endif()

# Turn on the correct setting for the __cplusplus macro with MSVC.
covfie_add_flag( CMAKE_CXX_FLAGS "/Zc:__cplusplus" )

if(
(
"${CMAKE_CXX_COMPILER_ID}"
MATCHES
"GNU"
)
OR (
"${CMAKE_CXX_COMPILER_ID}"
MATCHES
"Clang"
)
)
# Basic flags for all build modes.
covfie_add_flag( CMAKE_CXX_FLAGS "-Wall" )
covfie_add_flag( CMAKE_CXX_FLAGS "-Wextra" )
covfie_add_flag( CMAKE_CXX_FLAGS "-Wshadow" )
covfie_add_flag( CMAKE_CXX_FLAGS "-Wunused-local-typedefs" )
covfie_add_flag( CMAKE_CXX_FLAGS "-pedantic" )
covfie_add_flag( CMAKE_CXX_FLAGS "-Wfloat-conversion" )
covfie_add_flag( CMAKE_CXX_FLAGS "-Wconversion" )

# Fail on warnings, if asked for that behaviour.
if(COVFIE_FAIL_ON_WARNINGS)
covfie_add_flag( CMAKE_CXX_FLAGS "-Werror" )
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
# Basic flags for all build modes.
string(REGEX REPLACE "/W[0-9]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
covfie_add_flag( CMAKE_CXX_FLAGS "/W4" )

# Fail on warnings, if asked for that behaviour.
if(COVFIE_FAIL_ON_WARNINGS)
covfie_add_flag( CMAKE_CXX_FLAGS "/WX" )
endif()

# Turn on the correct setting for the __cplusplus macro with MSVC.
covfie_add_flag( CMAKE_CXX_FLAGS "/Zc:__cplusplus" )
endif()
55 changes: 34 additions & 21 deletions cmake/covfie-compiler-options-cuda.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,54 @@
# obtain one at http://mozilla.org/MPL/2.0/.

# FindCUDAToolkit needs at least CMake 3.17.
cmake_minimum_required( VERSION 3.17 )
cmake_minimum_required(VERSION 3.17)

# Include the helper function(s).
include( covfie-functions )
include(covfie-functions)

# Figure out the properties of CUDA being used.
find_package( CUDAToolkit REQUIRED )
find_package(CUDAToolkit REQUIRED)

# Set the architecture to build code for.
set( CMAKE_CUDA_ARCHITECTURES "52" CACHE STRING
"CUDA architectures to build device code for" )
set(CMAKE_CUDA_ARCHITECTURES
"52"
CACHE STRING
"CUDA architectures to build device code for"
)

# Turn on the correct setting for the __cplusplus macro with MSVC.
if( "${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC" )
covfie_add_flag( CMAKE_CUDA_FLAGS "-Xcompiler /Zc:__cplusplus" )
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
covfie_add_flag( CMAKE_CUDA_FLAGS "-Xcompiler /Zc:__cplusplus" )
endif()

if( "${CMAKE_CUDA_COMPILER_ID}" MATCHES "NVIDIA" )
# Make CUDA generate debug symbols for the device code as well in a debug
# build.
covfie_add_flag( CMAKE_CUDA_FLAGS_DEBUG "-G" )
# Allow to use functions in device code that are constexpr, even if they are
# not marked with __device__.
covfie_add_flag( CMAKE_CUDA_FLAGS "--expt-relaxed-constexpr" )
if("${CMAKE_CUDA_COMPILER_ID}" MATCHES "NVIDIA")
# Make CUDA generate debug symbols for the device code as well in a debug
# build.
covfie_add_flag( CMAKE_CUDA_FLAGS_DEBUG "-G" )
# Allow to use functions in device code that are constexpr, even if they are
# not marked with __device__.
covfie_add_flag( CMAKE_CUDA_FLAGS "--expt-relaxed-constexpr" )
endif()

covfie_add_flag( CMAKE_CUDA_FLAGS "-Wfloat-conversion" )
covfie_add_flag( CMAKE_CUDA_FLAGS "-Wconversion" )

# Fail on warnings, if asked for that behaviour.
if( COVFIE_FAIL_ON_WARNINGS )
if( ( "${CUDAToolkit_VERSION}" VERSION_GREATER_EQUAL "10.2" ) AND
( "${CMAKE_CUDA_COMPILER_ID}" MATCHES "NVIDIA" ) )
covfie_add_flag( CMAKE_CUDA_FLAGS "-Werror all-warnings" )
elseif( "${CMAKE_CUDA_COMPILER_ID}" MATCHES "Clang" )
covfie_add_flag( CMAKE_CUDA_FLAGS "-Werror" )
endif()
if(COVFIE_FAIL_ON_WARNINGS)
if(
(
"${CUDAToolkit_VERSION}"
VERSION_GREATER_EQUAL
"10.2"
)
AND (
"${CMAKE_CUDA_COMPILER_ID}"
MATCHES
"NVIDIA"
)
)
covfie_add_flag( CMAKE_CUDA_FLAGS "-Werror all-warnings" )
elseif("${CMAKE_CUDA_COMPILER_ID}" MATCHES "Clang")
covfie_add_flag( CMAKE_CUDA_FLAGS "-Werror" )
endif()
endif()
Loading

0 comments on commit f1732e6

Please sign in to comment.