diff --git a/.cmake-format.yml b/.cmake-format.yml new file mode 100644 index 00000000..5a4eb98e --- /dev/null +++ b/.cmake-format.yml @@ -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: {} diff --git a/CMakeLists.txt b/CMakeLists.txt index c98bb817..67c29523 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") @@ -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 @@ -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 diff --git a/examples/diagnostic_protocol/CMakeLists.txt b/examples/diagnostic_protocol/CMakeLists.txt index a619ca91..81d4c0f5 100644 --- a/examples/diagnostic_protocol/CMakeLists.txt +++ b/examples/diagnostic_protocol/CMakeLists.txt @@ -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) diff --git a/examples/nmea2000/CMakeLists.txt b/examples/nmea2000/CMakeLists.txt index de18d600..80c959ab 100644 --- a/examples/nmea2000/CMakeLists.txt +++ b/examples/nmea2000/CMakeLists.txt @@ -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) diff --git a/examples/pgn_requests/CMakeLists.txt b/examples/pgn_requests/CMakeLists.txt index 0989184c..cfb1d24c 100644 --- a/examples/pgn_requests/CMakeLists.txt +++ b/examples/pgn_requests/CMakeLists.txt @@ -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) diff --git a/examples/transport_layer/CMakeLists.txt b/examples/transport_layer/CMakeLists.txt index ec5031a4..854b0acf 100644 --- a/examples/transport_layer/CMakeLists.txt +++ b/examples/transport_layer/CMakeLists.txt @@ -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) diff --git a/examples/vt_aux_n/CMakeLists.txt b/examples/vt_aux_n/CMakeLists.txt index 506b7088..d981c8d4 100644 --- a/examples/vt_aux_n/CMakeLists.txt +++ b/examples/vt_aux_n/CMakeLists.txt @@ -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 $/vtpooldata.iop) diff --git a/examples/vt_version_3_object_pool/CMakeLists.txt b/examples/vt_version_3_object_pool/CMakeLists.txt index e4b9d5ba..e157ad3a 100644 --- a/examples/vt_version_3_object_pool/CMakeLists.txt +++ b/examples/vt_version_3_object_pool/CMakeLists.txt @@ -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) @@ -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) diff --git a/hardware_integration/CMakeLists.txt b/hardware_integration/CMakeLists.txt index 68e9c5f4..22c467b4 100644 --- a/hardware_integration/CMakeLists.txt +++ b/hardware_integration/CMakeLists.txt @@ -8,7 +8,7 @@ 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") @@ -16,7 +16,7 @@ if(NOT CAN_DRIVER) message( AUTHOR_WARNING - "No CAN driver specified, choosing ${CAN_DRIVER} by default. Set the CAN_DRIVER variable with -DCAN_DRIVER= to specify another driver. or -DCAN_DRIVER=\";\" to specify multiple drivers." + "No CAN driver specified, choosing ${CAN_DRIVER} by default. Set the CAN_DRIVER variable with -DCAN_DRIVER= to specify another driver. or -DCAN_DRIVER=\";\" to specify multiple drivers." ) endif() @@ -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") @@ -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 @@ -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 @@ -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