diff --git a/docs/installation/cmake_variables.rst b/docs/installation/cmake_variables.rst index 20a9aae9..0f297d84 100644 --- a/docs/installation/cmake_variables.rst +++ b/docs/installation/cmake_variables.rst @@ -25,6 +25,7 @@ CMake variables - `UNITS_DOMAIN`: Specify a default domain to use for string conversions. Can be either a name from the domains namespace such as `domains::surveying` or one of 'COOKING', 'ASTRONOMY', 'NUCLEAR', 'SURVEYING', 'USE_CUSTOMARY', 'CLIMATE', or 'UCUM'. - `UNITS_DEFAULT_MATCH_FLAGS`: Specify an integer value for the default match flags to be used for conversion - `UNITS_DISABLE_NON_ENGLISH_UNITS`: the library includes a number of non-english units that can be converted from strings, these can be disabled by setting `UNITS_DISABLE_NON_ENGLISH_UNITS` to ON or setting the definition in the C++ code. +- `UNITS_DISABLE_EXTRA_UNIT_STANDARDS`: If set to `ON` disables UN recommendation 12, X12(not implemented yet), DOD(not implemented yet), from being included in the compilation and generated from strings. - `UNITS_NAMESPACE`: The top level namespace of the library, defaults to `units`. When compiling with C++17 (or higher), this can be set to, e.g., `mynamespace::units` to avoid name clashes with other libraries defining `units`. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c7b3b7c0..4af5a239 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -23,11 +23,14 @@ set(UNITS_TESTS test_commodities test_siunits test_defined_units - test_r20 test_math test_google_units ) +if (NOT UNITS_DISABLE_EXTRA_UNIT_STANDARDS) + list(APPEND UNITS_TESTS test_r20) +endif() + set(TEST_FILE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/files) # /wd4459 is for a warning of a global m in google test. They won't interfere so ignore @@ -69,6 +72,11 @@ else() target_compile_definitions( test_unit_strings PUBLIC -DENABLE_UNIT_TESTING=1 -DENABLE_UNIT_MAP_ACCESS=1 ) + if (NOT UNITS_DISABLE_EXTRA_UNIT_STANDARDS) + target_compile_definitions ( + test_r20 PUBLIC -DENABLE_UNIT_MAP_ACCESS=1 + ) + endif() add_unit_test(test_leadingNumbers.cpp) target_link_libraries( @@ -83,6 +91,7 @@ else() endif() endif() + target_compile_definitions( test_conversions2 PUBLIC -DTEST_FILE_FOLDER="${TEST_FILE_FOLDER}" ) diff --git a/test/test_r20.cpp b/test/test_r20.cpp index 33157407..0e3e4163 100644 --- a/test/test_r20.cpp +++ b/test/test_r20.cpp @@ -11,12 +11,12 @@ SPDX-License-Identifier: BSD-3-Clause #include using unitD = std::tuple; - +#ifdef ENABLE_UNIT_MAP_ACCESS // Check the order of the array make sure it is order for searching TEST(r20, order) { std::size_t unit_count{0}; - const void* r20 = units::detail::testing::r20rawData(unit_count); + const void* r20 = units::detail::r20rawData(unit_count); auto* r20data = reinterpret_cast(r20); for (size_t ii = 1; ii < unit_count; ++ii) { EXPECT_LT( @@ -29,7 +29,7 @@ TEST(r20, order) TEST(r20, conversions) { std::size_t unit_count{0}; - const void* r20 = units::detail::testing::r20rawData(unit_count); + const void* r20 = units::detail::r20rawData(unit_count); auto* r20data = reinterpret_cast(r20); int missed{0}; int correct{0}; @@ -124,3 +124,5 @@ TEST(r20, conversions) std::cout << convertible << " r20 unit are convertible to eachother\n"; std::cout << correct << " r20 units correctly translated\n"; } + +#endif \ No newline at end of file diff --git a/units/CMakeLists.txt b/units/CMakeLists.txt index c330cc11..225367cb 100644 --- a/units/CMakeLists.txt +++ b/units/CMakeLists.txt @@ -4,7 +4,13 @@ # See the top-level NOTICE for additional details. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -set(units_source_files units.cpp x12_conv.cpp r20_conv.cpp commodities.cpp) + + +if (UNITS_DISABLE_EXTRA_UNIT_STANDARDS) + set(units_source_files units.cpp commodities.cpp) +else() + set(units_source_files units.cpp commodities.cpp x12_conv.cpp r20_conv.cpp) +endif() set(units_header_files units.hpp @@ -60,6 +66,9 @@ if(UNITS_BUILD_SHARED_LIBRARY) if(UNITS_DISABLE_NON_ENGLISH_UNITS) target_compile_definitions(units PUBLIC -DUNITS_DISABLE_NON_ENGLISH_UNITS=1) endif() + if (UNITS_DISABLE_EXTRA_UNIT_STANDARDS) + target_compile_definitions(units PUBLIC -DUNITS_DISABLE_EXTRA_UNIT_STANDARDS=1) + endif() if(UNITS_DEFAULT_DOMAIN) target_compile_definitions( units PRIVATE -DUNITS_DEFAULT_DOMAIN=${UNITS_DEFAULT_DOMAIN} @@ -106,6 +115,9 @@ elseif(UNITS_BUILD_OBJECT_LIBRARY) if(UNITS_DISABLE_NON_ENGLISH_UNITS) target_compile_definitions(units PUBLIC -DUNITS_DISABLE_NON_ENGLISH_UNITS=1) endif() + if (UNITS_DISABLE_EXTRA_UNIT_STANDARDS) + target_compile_definitions(units PUBLIC -DUNITS_DISABLE_EXTRA_UNIT_STANDARDS=1) + endif() if(${CMAKE_CXX_STANDARD} GREATER 16) target_compile_definitions(units PRIVATE -DUNITS_CONSTEXPR_IF_SUPPORTED=1) endif() @@ -130,6 +142,9 @@ elseif(UNITS_BUILD_STATIC_LIBRARY) if(UNITS_BASE_TYPE) target_compile_definitions(units PUBLIC -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE}) endif() + if (UNITS_DISABLE_EXTRA_UNIT_STANDARDS) + target_compile_definitions(units PUBLIC -DUNITS_DISABLE_EXTRA_UNIT_STANDARDS=1) + endif() if(UNITS_DEFAULT_DOMAIN) target_compile_definitions( units PRIVATE -DUNITS_DEFAULT_DOMAIN=${UNITS_DEFAULT_DOMAIN} diff --git a/units/r20_conv.cpp b/units/r20_conv.cpp index 38c83c83..07de977b 100644 --- a/units/r20_conv.cpp +++ b/units/r20_conv.cpp @@ -3138,13 +3138,16 @@ precise_unit r20_unit(const std::string& r20_string) } return precise::error; } + +#ifdef ENABLE_UNIT_MAP_ACCESS namespace detail { - namespace testing { const void* r20rawData(size_t& array_size) { array_size = precise::r20_units.size(); return precise::r20_units.data(); } - } // namespace testing } // namespace detail + +#endif + } // namespace units diff --git a/units/units.hpp b/units/units.hpp index a08889a1..487e8af6 100644 --- a/units/units.hpp +++ b/units/units.hpp @@ -2269,10 +2269,6 @@ namespace detail { const char* unit, int power, std::uint64_t flags); -#ifdef EXTRA_UNIT_STANDARDS - // get the raw array for testing the r20 database - const void* r20rawData(size_t& array_size); -#endif } // namespace testing } // namespace detail #endif @@ -2282,6 +2278,11 @@ namespace detail { UNITS_EXPORT const std::unordered_map& getUnitStringMap(); UNITS_EXPORT const std::unordered_map& getUnitNameMap(); + +#ifdef EXTRA_UNIT_STANDARDS + // get the raw array for testing the r20 database + const void* r20rawData(size_t& array_size); +#endif } // namespace detail #endif