Skip to content

Commit

Permalink
[Meta]: Add cmake-format config
Browse files Browse the repository at this point in the history
Also used it to format all the CMakeLists.txt files
  • Loading branch information
GwnDaan authored and ad3154 committed Jan 23, 2023
1 parent 4962116 commit 7b378c3
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 29 deletions.
60 changes: 60 additions & 0 deletions .cmake-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
format:
disable: false
line_width: 80
tab_size: 2
use_tabchars: false
fractional_tab_policy: use-space
max_subgroups_hwrap: 2
max_pargs_hwrap: 6
max_rows_cmdline: 2
separate_ctrl_name_with_space: false
separate_fn_name_with_space: false
dangle_parens: false
dangle_align: prefix
min_prefix_chars: 4
max_prefix_chars: 10
max_lines_hwrap: 2
line_ending: unix
command_case: canonical
keyword_case: unchanged
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: [C0301]
function_pattern: "[0-9a-z_]+"
macro_pattern: "[0-9A-Z_]+"
global_var_pattern: "[a-zA-Z][0-9a-zA-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: {}
23 changes: 13 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,22 @@ endif()

# Find packages required for Socket CAN
set(THREADS_PREFER_PTHREAD_FLAG ON)
if(NOT ESP_PLATFORM) # ESP-IDF doesn't implement find_package(Threads) correctly (dec 2022)
# ESP-IDF doesn't implement find_package(Threads) correctly (dec 2022)
if(NOT ESP_PLATFORM)
find_package(Threads REQUIRED)
endif()

# A handy function to PREPEND text to all elements in a list (useful for
# A handy function to prepend text to all elements in a list (useful for
# subdirectories)
function(PREPEND var prefix)
function(prepend var prefix)
set(listVar "")
foreach(f ${ARGN})
list(APPEND listVar "${prefix}/${f}")
endforeach(f)
foreach(arg ${ARGN})
list(APPEND listVar "${prefix}/${arg}")
endforeach(arg)
set(${var}
"${listVar}"
PARENT_SCOPE)
endfunction(PREPEND)
endfunction(prepend)

# Add subdirectories
add_subdirectory("utility")
Expand Down Expand Up @@ -72,6 +73,7 @@ if(BUILD_TESTING)
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.12.1)

# For Windows: Prevent overriding the parent project's compiler/linker
# settings
set(gtest_force_shared_crt
Expand All @@ -95,9 +97,10 @@ if(BUILD_TESTING)

if("SocketCAN" IN_LIST CAN_DRIVER)
add_executable(
unit_tests test/address_claim_test.cpp test/test_CAN_glue.cpp
test/identifier_tests.cpp test/dm_13_tests.cpp
test/core_network_management_tests.cpp)
unit_tests
test/address_claim_test.cpp test/test_CAN_glue.cpp
test/identifier_tests.cpp test/dm_13_tests.cpp
test/core_network_management_tests.cpp)
target_link_libraries(
unit_tests
PRIVATE GTest::gtest_main ${PROJECT_NAME}::Isobus
Expand Down
5 changes: 3 additions & 2 deletions examples/diagnostic_protocol/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ cmake_minimum_required(VERSION 3.16)
project(diagnostic_protocol_example)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(isobus CONFIG) # Normally, you set REQUIRED, however if building
# from top level, it already exists
if(NOT BUILD_EXAMPLES)
find_package(isobus REQUIRED)
endif()
find_package(Threads REQUIRED)

add_executable(DiagnosticProtocolExampleTarget main.cpp)
Expand Down
5 changes: 3 additions & 2 deletions examples/nmea2000/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ cmake_minimum_required(VERSION 3.16)
project(nmea2000_example)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(isobus CONFIG) # Normally, you set REQUIRED, however if building
# from top level, it already exists
if(NOT BUILD_EXAMPLES)
find_package(isobus REQUIRED)
endif()
find_package(Threads REQUIRED)

add_executable(NMEA2KExampleTarget main.cpp)
Expand Down
5 changes: 3 additions & 2 deletions examples/pgn_requests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ project(pgn_requests_example)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(isobus CONFIG) # Normally, you set REQUIRED, however if building
# from top level, it already exists
if(NOT BUILD_EXAMPLES)
find_package(isobus REQUIRED)
endif()
find_package(Threads REQUIRED)

add_executable(PGNRequestExampleTarget main.cpp)
Expand Down
5 changes: 3 additions & 2 deletions examples/transport_layer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ project(transport_layer_example)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(isobus CONFIG) # Normally, you set REQUIRED, however if building
# from top level, it already exists
if(NOT BUILD_EXAMPLES)
find_package(isobus REQUIRED)
endif()
find_package(Threads REQUIRED)

add_executable(TransportLayerExampleTarget main.cpp)
Expand Down
8 changes: 5 additions & 3 deletions examples/vt_aux_n/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ project(vt_aux_n_example)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(isobus CONFIG) # Normally, you set REQUIRED, however if building
# from top level, it already exists
if(NOT BUILD_EXAMPLES)
find_package(isobus REQUIRED)
endif()
find_package(Threads REQUIRED)

add_executable(VTAuxNExample main.cpp object_pool_ids.h)
target_link_libraries(
VTAuxNExample PRIVATE isobus::Isobus isobus::HardwareIntegration
Threads::Threads isobus::Utility)
Threads::Threads isobus::Utility)

add_custom_command(
TARGET VTAuxNExample
POST_BUILD
COMMENT "Copying vtpooldata.iop to build directory"
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/vtpooldata.iop
$<TARGET_FILE_DIR:VTAuxNExample>/vtpooldata.iop)
6 changes: 4 additions & 2 deletions examples/vt_version_3_object_pool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ project(vt3_version_3_object_pool_example)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(isobus CONFIG) # Normally, you set REQUIRED, however if building
# from top level, it already exists
if(NOT BUILD_EXAMPLES)
find_package(isobus REQUIRED)
endif()
find_package(Threads REQUIRED)

add_executable(VT3ExampleTarget main.cpp objectPoolObjects.h)
Expand All @@ -15,5 +16,6 @@ target_link_libraries(
add_custom_command(
TARGET VT3ExampleTarget
POST_BUILD
COMMENT "Copying VT3TestPool.iop to build directory"
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/VT3TestPool.iop
${CMAKE_CURRENT_BINARY_DIR}/VT3TestPool.iop)
15 changes: 9 additions & 6 deletions hardware_integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ set(HARDWARE_INTEGRATION_SRC_DIR "src")
set(HARDWARE_INTEGRATION_INCLUDE_DIR "include/isobus/hardware_integration")

if(NOT CAN_DRIVER)
if (WIN32)
if(WIN32)
set(CAN_DRIVER "WindowsPCANBasic")
else()
set(CAN_DRIVER "SocketCAN")
endif()

message(
AUTHOR_WARNING
"No CAN driver specified, choosing ${CAN_DRIVER} by default. Set the CAN_DRIVER variable with -DCAN_DRIVER=<driver> to specify another driver. or -DCAN_DRIVER=\"<driver1>;<driver2>\" to specify multiple drivers."
"No CAN driver specified, choosing ${CAN_DRIVER} by default. Set the CAN_DRIVER variable with -DCAN_DRIVER=<driver> to specify another driver. or -DCAN_DRIVER=\"<driver1>;<driver2>\" to specify multiple drivers."
)
endif()

Expand All @@ -37,12 +37,12 @@ if("WindowsPCANBasic" IN_LIST CAN_DRIVER)
list(APPEND HARDWARE_INTEGRATION_INCLUDE "pcan_basic_windows_plugin.hpp")
endif()
if("TWAI" IN_LIST CAN_DRIVER)
list(APPEND HARDWARE_INTEGRATION_SRC "twai_plugin.cpp")
list(APPEND HARDWARE_INTEGRATION_INCLUDE "twai_plugin.hpp")
list(APPEND HARDWARE_INTEGRATION_SRC "twai_plugin.cpp")
list(APPEND HARDWARE_INTEGRATION_INCLUDE "twai_plugin.hpp")
endif()
if("MCP2515" IN_LIST CAN_DRIVER)
list(APPEND HARDWARE_INTEGRATION_SRC "mcp2515_can_interface.cpp")
list(APPEND HARDWARE_INTEGRATION_INCLUDE "mcp2515_can_interface.hpp")
list(APPEND HARDWARE_INTEGRATION_SRC "mcp2515_can_interface.cpp")
list(APPEND HARDWARE_INTEGRATION_INCLUDE "mcp2515_can_interface.hpp")
if(ESP_PLATFORM)
list(APPEND HARDWARE_INTEGRATION_SRC "spi_interface_esp.cpp")
list(APPEND HARDWARE_INTEGRATION_INCLUDE "spi_interface_esp.hpp")
Expand Down Expand Up @@ -79,6 +79,7 @@ if("WindowsPCANBasic" IN_LIST CAN_DRIVER)
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/lib/Windows/PCANBasic_x64.lib)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lib/Windows/PCANBasic_x64.lib
COMMENT "Copying PCANBasic_x64.lib to build directory"
COMMAND
${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_LIST_DIR}/lib/Windows/PCANBasic_x64.lib
Expand All @@ -90,6 +91,7 @@ if("WindowsPCANBasic" IN_LIST CAN_DRIVER)
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/lib/Windows/PCANBasic_ARM64.lib)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lib/Windows/PCANBasic_ARM64.lib
COMMENT "Copying PCANBasic_ARM64.lib to build directory"
COMMAND
${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_LIST_DIR}/lib/Windows/PCANBasic_ARM64.lib
Expand All @@ -102,6 +104,7 @@ if("WindowsPCANBasic" IN_LIST CAN_DRIVER)
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/lib/Windows/PCANBasic_x86.lib)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lib/Windows/PCANBasic_x86.lib
COMMENT "Copying PCANBasic_x86.lib to build directory"
COMMAND
${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_LIST_DIR}/lib/Windows/PCANBasic_x86.lib
Expand Down

0 comments on commit 7b378c3

Please sign in to comment.