Skip to content

Commit

Permalink
allow CMake/compile option to DISABLE_GREASE (#377)
Browse files Browse the repository at this point in the history
* allow CMake/compile option to DISABLE_GREASE

* make the DISABLE_GREASE default explicit

* clang format cleanup
  • Loading branch information
birarda authored Oct 16, 2023
1 parent 7e19d51 commit a08b545
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ option(TESTING "Build tests" OFF)
option(CLANG_TIDY "Perform linting with clang-tidy" OFF)
option(SANITIZERS "Enable sanitizers" OFF)
option(MLS_NAMESPACE_SUFFIX "Namespace Suffix for CXX and CMake Export")
option(DISABLE_GREASE "Disables the inclusion of MLS protocol recommended GREASE values" OFF)

if(MLS_NAMESPACE_SUFFIX)
set(MLS_CXX_NAMESPACE "mls_${MLS_NAMESPACE_SUFFIX}" CACHE STRING "Top-level Namespace for CXX")
Expand Down Expand Up @@ -79,6 +80,10 @@ if("$ENV{MACOSX_DEPLOYMENT_TARGET}" STREQUAL "10.11")
add_compile_options(-DVARIANT_COMPAT)
endif()

if (DISABLE_GREASE)
add_compile_options(-DDISABLE_GREASE)
endif ()

###
### Enable testing
###
Expand Down
19 changes: 19 additions & 0 deletions src/grease.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@

namespace MLS_NAMESPACE {

#ifdef DISABLE_GREASE

Capabilities
grease(Capabilities&& capabilities,
[[maybe_unused]] const ExtensionList& extensions)
{
return capabilities;
}

ExtensionList
grease(ExtensionList&& extensions)
{
return extensions;
}

#else

// Randomness parmeters:
// * Given a list of N items, insert max(1, rand(p_grease * N)) GREASE values
// * Each GREASE value added is distinct, unless more than 15 values are needed
Expand Down Expand Up @@ -118,4 +135,6 @@ grease(ExtensionList&& extensions)
return { ext };
}

#endif // DISABLE_GREASE

} // namespace MLS_NAMESPACE

0 comments on commit a08b545

Please sign in to comment.