diff --git a/.clang-tidy b/.clang-tidy index 6c5b018..c28ac39 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -11,8 +11,9 @@ Checks: > portability-*, readability-*, -cppcoreguidelines-macro-usage, - -hicpp-signed-bitwise, + -google-runtime-references -hicpp-exception-baseclass, + -hicpp-signed-bitwise, -readability-function-cognitive-complexity, - -google-runtime-references + -used-but-marked-unused, HeaderFilterRegex: ".*/[common|logging]/.*" diff --git a/CMakeLists.txt b/CMakeLists.txt index 600cbd2..064233b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,7 +109,6 @@ set(${PROJECT_NAME}_BUILD_EXAMPLES ${ASAP_BUILD_EXAMPLES}) include(AsapTargets) include(BuildHelpers) include(GenerateExportHeader) -include(CompileOptions) # Override the ${META_PROJECT_ID}_INSTALL option to ON/OFF to respectively force # install/no-install behavior for this project. This is particularly useful when diff --git a/cmake/AsapTargets.cmake b/cmake/AsapTargets.cmake index 92ce110..514bf9d 100644 --- a/cmake/AsapTargets.cmake +++ b/cmake/AsapTargets.cmake @@ -5,8 +5,10 @@ # ===-----------------------------------------------------------------------===# include(CMakePackageConfigHelpers) +include(common/CompileOptions) include(common/SwiftTargets) include(CompileDefinitions) +include(CompileOptions) # ------------------------------------------------------------------------------ # Meta information about the this module @@ -113,6 +115,8 @@ function(asap_add_library target) if(NOT ${type} STREQUAL "INTERFACE_LIBRARY") # Set some common private compiler defines asap_set_compile_definitions(${target}) + # Set some common compiler options + asap_set_compile_options(${target}) # Generate export headers for the library asap_generate_export_headers(${target} ${META_MODULE_NAME}) @@ -129,19 +133,28 @@ endfunction() function(asap_add_executable target) swift_add_executable("${target}" ${ARGN}) + # Set some common private compiler defines asap_set_compile_definitions(${target}) + # Set some common compiler options + asap_set_compile_options(${target}) set_target_properties(${target} PROPERTIES FOLDER "Executables") endfunction() function(asap_add_tool target) swift_add_tool("${target}" ${ARGN}) + # Set some common private compiler defines asap_set_compile_definitions(${target}) + # Set some common compiler options + asap_set_compile_options(${target}) set_target_properties(${target} PROPERTIES FOLDER "Tools") endfunction() function(asap_add_tool_library target) swift_add_tool_library("${target}" ${ARGN}) + # Set some common private compiler defines asap_set_compile_definitions(${target}) + # Set some common compiler options + asap_set_compile_options(${target}) set_target_properties( ${target} PROPERTIES FOLDER "Tool Libraries" @@ -149,14 +162,3 @@ function(asap_add_tool_library target) SOVERSION ${META_MODULE_VERSION_MAJOR} DEBUG_POSTFIX "d") endfunction() - -function(asap_add_test_library target) - swift_add_test_library("${target}" ${ARGN}) - asap_set_compile_definitions(${target}) - set_target_properties( - ${target} - PROPERTIES FOLDER "Test Libraries" - VERSION ${META_MODULE_VERSION} - SOVERSION ${META_MODULE_VERSION_MAJOR} - DEBUG_POSTFIX "d") -endfunction() diff --git a/cmake/BuildHelpers.cmake b/cmake/BuildHelpers.cmake index 7f87e5a..77ff436 100644 --- a/cmake/BuildHelpers.cmake +++ b/cmake/BuildHelpers.cmake @@ -8,30 +8,6 @@ # Build Helpers to simplify target creation. # ------------------------------------------------------------------------------ -function(asap_compile_definitions target) - # - # Compile definitions - # - # ones we use for every single target - target_compile_definitions( - ${target} - PRIVATE $<$: - ASAP_CONTRACT_DEFAULT - > - $<$: - ASAP_CONTRACT_OFF - > - $<$: - ASAP_CONTRACT_AUDIT - > - $<$: - NOMINMAX - WIN32_LEAN_AND_MEAN=1 - _WIN32_WINNT=0x0600 - >) -endfunction() - -include(GenerateTemplateExportHeader) function(asap_generate_export_headers target include_dir) # Set API export file and macro string(MAKE_C_IDENTIFIER ${target} TEMPLATE_TARGET_ID) @@ -44,6 +20,4 @@ function(asap_generate_export_headers target include_dir) # Create API export headers generate_export_header(${target} EXPORT_FILE_NAME ${export_file} EXPORT_MACRO_NAME ${TEMPLATE_TARGET_ID}_API) - generate_template_export_header(${target} ${TEMPLATE_TARGET_ID} - ${template_export_file}) endfunction() diff --git a/cmake/CompileOptions.cmake b/cmake/CompileOptions.cmake index 4b1be30..c29a760 100644 --- a/cmake/CompileOptions.cmake +++ b/cmake/CompileOptions.cmake @@ -5,232 +5,57 @@ # ===-----------------------------------------------------------------------===# # ------------------------------------------------------------------------------ -# Set a common set of compiler options and warning flags +# Set additional common compiler options and warning flags # ------------------------------------------------------------------------------ - -# -# Call swift_set_compile_options() for any target to set the Swift default set -# of compiler options. This includes -# ~~~ -# - exceptions disabled -# - rtti disabled -# - strict aliasing disabled -# - Warnings as errors (-Werror) -# - Extensive set of enabled warnings -# ~~~ -# -# Exceptions and/or RTTI can be selectively enabled for a target be passing -# EXCEPTIONS and/or RTTI as a parameter, eg -# -# ~~~ -# swift_set_compile_options(sample-target EXCEPTIONS RTTI) -# ~~~ -# -# will enable exceptions and rtti for sample-target only -# -# Warning flags can be removed from the default set by passing REMOVE followed -# by a list of warning flags, eg -# -# ~~~ -# swift_set_compile_options(sample-target REMOVE -Wconversion) -# ~~~ -# -# will prevent -Wconversion from being passed to the compiler for sample-target -# only -# -# Similarly extra options can be given by passing ADD followed by a list of -# warning flags (or other compiler options), eg -# -# ~~~ -# swift_set_compile_options(sample-target ADD -Wformat=2) -# ~~~ -# -# will pass -Wformat=2 to the compiler for sample-target only -# -# By default -Werror is set, but this can be prevented by passing WARNING as a -# parameter, eg # -# ~~~ -# swift_set_compile_options(sample-target WARNING) -# ~~~ +# Refer to swift_set_compile_options() for additional detailed information on +# accepted options for this function, which forwards all options. # -# will disable warnings-as-errors for sample-target only -# -# All flags will be checked for suitability with the in-use compilers before -# being selected. This is important since Swift code tends to be compiled with a -# wide variety of compilers which may not support the same set of flags and -# options. Therefore, it should be preferred to use this function to set -# compiler flags and options rather than target_compile_options() -# -# NOTE: user's can call on EXTRA_FLAGS to augment the default list of flags -# before flags are removed with REMOVE and subsequently added with ADD. -# - -include(CheckCCompilerFlag) -include(CheckCXXCompilerFlag) - -function(swift_set_compile_options) - set(argOption "WARNING" "NO_EXCEPTIONS" "EXCEPTIONS" "NO_RTTI" "RTTI") - set(argSingle "") - set(argMulti "ADD" "REMOVE" "EXTRA_FLAGS") - - unset(x_WARNING) - unset(x_ADD) - unset(x_REMOVE) - unset(x_EXTRA_FLAGS) - - cmake_parse_arguments(x "${argOption}" "${argSingle}" "${argMulti}" ${ARGN}) - set(targets ${x_UNPARSED_ARGUMENTS}) - - if(x_RTTI AND x_NO_RTTI) - message(FATAL_ERROR "RTTI and NO_RTTI can't be used together") - endif() - - if(x_EXCEPTIONS AND x_NO_EXCEPTIONS) - message(FATAL_ERROR "EXCEPTIONS and NO_EXCEPTIONS can't be used together") - endif() +# In addition to relaying the call, this function adds common compiler options +# and overrides the default behavior of swift with regard to exceptions and +# RTTI. By default, both are enabled. - foreach(flag ${x_ADD} ${x_REMOVE}) - if(${flag} STREQUAL "-Werror") - message( - FATAL_ERROR - "Do not specify -Werror directly, use WARNING to disable -Werror") - endif() - if(${flag} STREQUAL "-Wno-error") - message( - FATAL_ERROR - "Do not specify -Wno-error directly, use WARNING to disable -Werror") - endif() - endforeach() - - if(DEFINED SWIFT_COMPILER_WARNING_ARE_ERROR) - if(SWIFT_COMPILER_WARNING_ARE_ERROR) - if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - set(all_flags /WX) - else() - set(all_flags -Werror -Wno-error=deprecated-declarations) - endif() - else() - set(all_flags -Wno-error) - endif() - else() - if(NOT x_WARNING) - if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - set(all_flags /WX) - else() - set(all_flags -Werror -Wno-error=deprecated-declarations) - endif() - endif() - endif() +function(asap_set_compile_options) + swift_set_compile_options(EXCEPTIONS RTTI ${ARGV}) if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") # using Clang - list( - APPEND - all_flags + swift_set_compile_options( + ADD -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-c++98-c++11-compat-pedantic -Wno-padded - -Wno-documentation-unknown-command - -Wno-switch-enum - -Wno-unused-macros - -Wno-disabled-macro-expansion) + -Wno-documentation-unknown-command) + # -Wno-switch-enum -Wno-unused-macros -Wno-disabled-macro-expansion) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # using GCC - list( - APPEND - all_flags - -Wall - -Wextra - -Wcast-align - -Wcast-qual + swift_set_compile_options( + ADD -Wctor-dtor-privacy - -Wdisabled-optimization - -Wformat=2 -Winit-self -Wmissing-declarations - -Wmissing-include-dirs -Wold-style-cast -Woverloaded-virtual - -Wredundant-decls - -Wshadow -Wsign-conversion -Wsign-promo - -Wundef - -Werror - -Wno-unused) + -Wundef) if(NOT DEFINED CMAKE_CXX_CLANG_TIDY) - list(APPEND all_flags -Wlogical-op -Wstrict-null-sentinel) + swift_set_compile_options(ADD -Wlogical-op -Wstrict-null-sentinel) endif() elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") # using Visual Studio C++ - list(APPEND all_flags /EHsc /MP /W4) - endif() - - if(x_REMOVE) - foreach(flag ${x_REMOVE}) - list(FIND all_flags ${flag} found) - if(found EQUAL -1) - message( - FATAL_ERROR - "Compiler flag '${flag}' specified for removal is not part of the set of common compiler flags" - ) - endif() + set(argOption "WARNING" "NO_EXCEPTIONS" "EXCEPTIONS" "NO_RTTI" "RTTI") + set(argSingle "") + set(argMulti "ADD" "REMOVE" "EXTRA_FLAGS") + cmake_parse_arguments(x "${argOption}" "${argSingle}" "${argMulti}" ${ARGN}) + set(targets ${x_UNPARSED_ARGUMENTS}) + foreach(target ${targets}) + target_compile_options(${target} PRIVATE /EHsc /MP /W4) endforeach() - list(REMOVE_ITEM all_flags ${x_REMOVE}) endif() - list(APPEND all_flags ${x_ADD}) - - unset(final_flags) - - get_property(enabled_languages GLOBAL PROPERTY ENABLED_LANGUAGES) - list(FIND enabled_languages "C" c_enabled) - list(FIND enabled_languages "CXX" cxx_enabled) - - foreach(flag ${all_flags}) - string(TOUPPER ${flag} sanitised_flag) - string(REPLACE "+" "X" sanitised_flag ${sanitised_flag}) - string(REGEX REPLACE "[^A-Za-z_0-9]" "_" sanitised_flag ${sanitised_flag}) - - set(c_supported HAVE_C_FLAG_${sanitised_flag}) - string(REGEX REPLACE "_+" "_" c_supported ${c_supported}) - set(cxx_supported HAVE_CXX_FLAG_${sanitised_flag}) - string(REGEX REPLACE "_+" "_" cxx_supported ${cxx_supported}) - - if(${c_enabled} GREATER -1) - if(MSVC) - check_c_compiler_flag("/WX ${flag}" ${c_supported}) - else() - check_c_compiler_flag("-Werror ${flag}" ${c_supported}) - endif() - if(${${c_supported}}) - list(APPEND final_flags $<$:${flag}>) - endif() - endif() - - if(${cxx_enabled} GREATER -1) - if(MSVC) - check_cxx_compiler_flag("/WX ${flag}" ${cxx_supported}) - else() - check_cxx_compiler_flag("-Werror ${flag}" ${cxx_supported}) - endif() - if(${${cxx_supported}}) - list(APPEND final_flags $<$:${flag}>) - endif() - endif() - endforeach() - - foreach(target ${targets}) - target_compile_options(${target} PRIVATE ${final_flags}) - endforeach() - -endfunction() - -function(asap_set_compile_options) - swift_set_compile_options(${ARGV}) endfunction() # ------------------------------------------------------------------------------ diff --git a/cmake/GenerateTemplateExportHeader.cmake b/cmake/GenerateTemplateExportHeader.cmake deleted file mode 100644 index ad244f6..0000000 --- a/cmake/GenerateTemplateExportHeader.cmake +++ /dev/null @@ -1,25 +0,0 @@ -# ===-----------------------------------------------------------------------===# -# Distributed under the 3-Clause BSD License. See accompanying file LICENSE or -# copy at https://opensource.org/licenses/BSD-3-Clause). -# SPDX-License-Identifier: BSD-3-Clause -# ===-----------------------------------------------------------------------===# - -# ------------------------------------------------------------------------------ -# Generate export header for template classes/functions. -# ------------------------------------------------------------------------------ - -# Creates an export header similar to generate_export_header, but for templates. -# The main difference is that for MSVC, templates must not get exported. When -# the file ${export_file} is included in source code, the macro -# ${target_id}_TEMPLATE_API may get used to define public visibility for -# templates on GCC and Clang platforms. -# -function(generate_template_export_header target target_id export_file) - if("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC") - configure_file(${PROJECT_SOURCE_DIR}/templates/template_msvc_api.h.in - ${CMAKE_CURRENT_BINARY_DIR}/${export_file}) - else() - configure_file(${PROJECT_SOURCE_DIR}/templates/template_api.h.in - ${CMAKE_CURRENT_BINARY_DIR}/${export_file}) - endif() -endfunction() diff --git a/cmake/TestTargets.cmake b/cmake/TestTargets.cmake index 017225c..27ee346 100644 --- a/cmake/TestTargets.cmake +++ b/cmake/TestTargets.cmake @@ -8,14 +8,20 @@ include(common/TestTargets) macro(asap_add_test target) swift_add_test("${target}" ${ARGN}) - - asap_set_compile_options(${target} WARNING) + # Set some common private compiler defines asap_set_compile_definitions(${target}) + # Set some common compiler options + asap_set_compile_options(${target}) if(TARGET gtest AND BUILD_SHARED_LIBS) target_compile_definitions(${target} PRIVATE GTEST_LINKED_AS_SHARED_LIBRARY) if(MSVC) target_compile_options(${target} PRIVATE /wd4251) endif() + if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + asap_set_compile_options( + ${target} ADD "-Wno-used-but-marked-unused" "-Wno-global-constructors" + "-Wno-unused-member-function") + endif() endif() set_target_properties(${target} PROPERTIES FOLDER "Unit Tests") endmacro() @@ -23,3 +29,17 @@ endmacro() macro(asap_add_test_runner target) swift_add_test_runner("${target}" ${ARGN}) endmacro() + +function(asap_add_test_library target) + swift_add_test_library("${target}" ${ARGN}) + # Set some common private compiler defines + asap_set_compile_definitions(${target}) + # Set some common compiler options + asap_set_compile_options(${target}) + set_target_properties( + ${target} + PROPERTIES FOLDER "Test Libraries" + VERSION ${META_MODULE_VERSION} + SOVERSION ${META_MODULE_VERSION_MAJOR} + DEBUG_POSTFIX "d") +endfunction() diff --git a/cmake/common b/cmake/common index ea15fa9..2ab46ff 160000 --- a/cmake/common +++ b/cmake/common @@ -1 +1 @@ -Subproject commit ea15fa9b1e5dd296d932866ee0b9a1d2eab9296c +Subproject commit 2ab46ff99ba8f95986bdceab74befd59f9163800 diff --git a/doxygen/doxygen-awesome-css b/doxygen/doxygen-awesome-css index a5efba0..74b4250 160000 --- a/doxygen/doxygen-awesome-css +++ b/doxygen/doxygen-awesome-css @@ -1 +1 @@ -Subproject commit a5efba07a3d4fd6317d95657b3095b97e134b791 +Subproject commit 74b42503df7e314dd66f508edca3c3ccfd611b72 diff --git a/fsm/include/fsm/fsm.h b/fsm/include/fsm/fsm.h index 7b37ac9..a140827 100644 --- a/fsm/include/fsm/fsm.h +++ b/fsm/include/fsm/fsm.h @@ -17,7 +17,7 @@ #pragma once -#include +#include #include #include @@ -193,7 +193,7 @@ class ASAP_FSM_API StateMachineError { * * \snippet fsm_example_test.cpp Full State Machine Example */ -template class ASAP_FSM_TEMPLATE_API StateMachine { +template class StateMachine { public: /*! * \brief Construct a new State Machine object with the given states, starting @@ -307,7 +307,7 @@ template class ASAP_FSM_TEMPLATE_API StateMachine { * * \snippet fsm_test.cpp TransitionTo with data example */ -template struct ASAP_FSM_TEMPLATE_API TransitionTo { +template struct TransitionTo { public: // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) TransitionTo(std::any data = {}) : data_{std::move(data)} { @@ -515,7 +515,7 @@ constexpr auto supports_alternative() -> bool { * * \snippet fsm_test.cpp OneOf example */ -template struct ASAP_FSM_TEMPLATE_API OneOf { +template struct OneOf { template ::type>::value> * = nullptr> @@ -593,8 +593,7 @@ template constexpr bool is_one_of_v = is_one_of::value; * * \snippet fsm_test.cpp OneOf example */ -template -struct ASAP_FSM_TEMPLATE_API Maybe : public OneOf { +template struct Maybe : public OneOf { using OneOf::OneOf; }; @@ -615,7 +614,7 @@ struct is_one_of> : std::true_type {}; * * \snippet fsm_test.cpp ByDefault example */ -template struct ASAP_FSM_TEMPLATE_API ByDefault { +template struct ByDefault { template auto Handle(const Event & /*unused*/) const -> Action { return Action{}; @@ -630,7 +629,7 @@ template struct ASAP_FSM_TEMPLATE_API ByDefault { * * \snippet fsm_test.cpp On example */ -template struct ASAP_FSM_TEMPLATE_API On { +template struct On { auto Handle(const Event & /*event*/) const -> Action { return {}; } @@ -644,8 +643,7 @@ template struct ASAP_FSM_TEMPLATE_API On { * * \snippet fsm_test.cpp Will example */ -template -struct ASAP_FSM_TEMPLATE_API Will : Handlers... { +template struct Will : Handlers... { using Handlers::Handle...; }; diff --git a/fsm/test/fsm_test.cpp b/fsm/test/fsm_test.cpp index 6000fd5..ec16ad3 100644 --- a/fsm/test/fsm_test.cpp +++ b/fsm/test/fsm_test.cpp @@ -166,7 +166,7 @@ TEST(StateMachine, MachineHandleEventCatchesUnhandledExceptions) { EXPECT_CALL(*mock_state, Handle).Times(1).WillOnce(Throw(ByRef(error))); auto status = machine.Handle(test_event); // NOLINTNEXTLINE - ASSERT_NO_THROW(std::get<2>(status)); + ASSERT_NO_THROW([[maybe_unused]] auto val = std::get<2>(status)); TestAction test_action{mock_action}; EXPECT_CALL(*mock_state, Handle) @@ -178,7 +178,7 @@ TEST(StateMachine, MachineHandleEventCatchesUnhandledExceptions) { .WillOnce(Throw(ByRef(error))); status = machine.Handle(test_event); // NOLINTNEXTLINE - ASSERT_NO_THROW(std::get<2>(status)); + ASSERT_NO_THROW([[maybe_unused]] auto val = std::get<2>(status)); } // NOLINTNEXTLINE diff --git a/templates/template_api.h.in b/templates/template_api.h.in deleted file mode 100644 index 9db3061..0000000 --- a/templates/template_api.h.in +++ /dev/null @@ -1,29 +0,0 @@ -//===----------------------------------------------------------------------===// -// Distributed under the 3-Clause BSD License. See accompanying file LICENSE or -// copy at https://opensource.org/licenses/BSD-3-Clause). -// SPDX-License-Identifier: BSD-3-Clause -//===----------------------------------------------------------------------===// - -#pragma once - -// NOLINTBEGIN(cppcoreguidelines-macro-usage) - -#include <${TEMPLATE_INCLUDE_DIR}/${TEMPLATE_TARGET}_export.h> - -// clang-format off -#ifdef ${target_id}_STATIC_DEFINE -# define ${target_id}_TEMPLATE_API -#else -# ifndef ${TEMPLATE_TARGET_ID}_TEMPLATE_API -# ifdef ${TEMPLATE_TARGET_ID}_EXPORTS - /* We are building this library */ -# define ${TEMPLATE_TARGET_ID}_TEMPLATE_API __attribute__((visibility("default"))) -# else - /* We are using this library */ -# define ${TEMPLATE_TARGET_ID}_TEMPLATE_API __attribute__((visibility("default"))) -# endif -# endif -#endif -// clang-format on - -// NOLINTEND(cppcoreguidelines-macro-usage) diff --git a/templates/template_msvc_api.h.in b/templates/template_msvc_api.h.in deleted file mode 100644 index 5e50a5b..0000000 --- a/templates/template_msvc_api.h.in +++ /dev/null @@ -1,29 +0,0 @@ -//===----------------------------------------------------------------------===// -// Distributed under the 3-Clause BSD License. See accompanying file LICENSE or -// copy at https://opensource.org/licenses/BSD-3-Clause). -// SPDX-License-Identifier: BSD-3-Clause -//===----------------------------------------------------------------------===// - -#pragma once - -// NOLINTBEGIN(cppcoreguidelines-macro-usage) - -#include <${TEMPLATE_INCLUDE_DIR}/${TEMPLATE_TARGET}_export.h> - -// clang-format off -#ifdef ${TEMPLATE_TARGET_ID}_STATIC_DEFINE -# define ${target_id}_TEMPLATE_API -#else -# ifndef ${TEMPLATE_TARGET_ID}_TEMPLATE_API -# ifdef ${TEMPLATE_TARGET_ID}_EXPORTS - /* We are building this library */ -# define ${TEMPLATE_TARGET_ID}_TEMPLATE_API -# else - /* We are using this library */ -# define ${TEMPLATE_TARGET_ID}_TEMPLATE_API -# endif -# endif -#endif -// clang-format on - -// NOLINTBEGIN(cppcoreguidelines-macro-usage)