From 444aa4e745bb033e728b44413abca00fe44a7c15 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Thu, 12 Aug 2021 09:37:06 -0700 Subject: [PATCH 01/20] Modify the cmake projects to only allow one library to be built at a time --- CMakeLists.txt | 6 +- test/find_package_tests/CMakeLists.txt | 38 ++++++ test/pkg_test_code/header_only.cpp | 18 +++ test/pkg_test_code/main.cpp | 18 +++ units/CMakeLists.txt | 153 ++++++++++++------------- 5 files changed, 150 insertions(+), 83 deletions(-) create mode 100644 test/find_package_tests/CMakeLists.txt create mode 100644 test/pkg_test_code/header_only.cpp create mode 100644 test/pkg_test_code/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c14e89c..b7af1af3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,16 +10,16 @@ cmake_minimum_required(VERSION 3.0) # Make sure users don't get warnings on a tested (3.0 to 3.16) version of CMake. For # most of the policies, the new version is better (hence the change). We don't use the # 3.0...3.17 syntax because of a bug in an older MSVC's built-in and modified CMake 3.11 -if(${CMAKE_VERSION} VERSION_LESS 3.18) +if(${CMAKE_VERSION} VERSION_LESS 3.20) cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) else() - cmake_policy(VERSION 3.18) + cmake_policy(VERSION 3.20) endif() project( UNITS LANGUAGES CXX - VERSION 0.4.1 + VERSION 0.5.0 ) include(CMakeDependentOption) include(CTest) diff --git a/test/find_package_tests/CMakeLists.txt b/test/find_package_tests/CMakeLists.txt new file mode 100644 index 00000000..a13f3b0d --- /dev/null +++ b/test/find_package_tests/CMakeLists.txt @@ -0,0 +1,38 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# Copyright (c) 2017-2020, Battelle Memorial Institute; Lawrence Livermore +# National Security, LLC; Alliance for Sustainable Energy, LLC. +# See the top-level NOTICE for additional details. +# All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +cmake_minimum_required(VERSION 3.10...3.17) + +project(units-find-package-test) + +include(CTest) + +# Test the HELICS CMake package config +find_package(UNITS 0.6 REQUIRED) + +# add some tests inside of the CMake + +message(STATUS "Binary location is ${PROJECT_BINARY_DIR}") +# Test the CXX shared library target +if(UNITS_BUILD_SHARED_LIBRARY) + add_executable(shared-library-test-exe ../pkg_test_code/main.cpp) + target_link_libraries(shared-library-test-exe UNITS::units) + + add_test(NAME shared-library-test COMMAND shared-library-test-exe) + set_property(TEST shared-library-test PROPERTY PASS_REGULAR_EXPRESSION "${HELICS_VERSION}") + +# Test the C and C++98 targets +elseif(UNITS_HEADER_ONLY) + add_executable(header_only-exe ../pkg_test_code/header_only.cpp) + target_link_libraries(header_only-exe UNITS::units) + + add_test(NAME header_only-exe COMMAND header_only-exe) + set_property(TEST c-shared-library-test PROPERTY PASS_REGULAR_EXPRESSION "${HELICS_VERSION}") + +endif() diff --git a/test/pkg_test_code/header_only.cpp b/test/pkg_test_code/header_only.cpp new file mode 100644 index 00000000..aedc18e3 --- /dev/null +++ b/test/pkg_test_code/header_only.cpp @@ -0,0 +1,18 @@ +/* +Copyright (c) 2019, +Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable +Energy, LLC. See the top-level NOTICE for additional details. All rights reserved. +SPDX-License-Identifier: BSD-3-Clause +*/ + +#include "helics/helics.h" + +#include +int main() +{ + volatile HelicsFederateInfo fedinfo = helicsCreateFederateInfo(); + helicsFederateInfoFree(fedinfo); + printf("%s\n", helicsGetVersion()); + helicsCloseLibrary(); + return (0); +} diff --git a/test/pkg_test_code/main.cpp b/test/pkg_test_code/main.cpp new file mode 100644 index 00000000..714ad357 --- /dev/null +++ b/test/pkg_test_code/main.cpp @@ -0,0 +1,18 @@ +/* +Copyright (c) 2021, +Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable +Energy, LLC. See the top-level NOTICE for additional details. All rights reserved. +SPDX-License-Identifier: BSD-3-Clause +*/ + +#include "units/units.hpp" + +#include + +int main(int /*argc*/, char* /*argv*/[]) +{ + auto u1 = units::measurement_from_string("10.7 meters per second"); + + std::cout << u1 << std::endl; + return 0; +} diff --git a/units/CMakeLists.txt b/units/CMakeLists.txt index f00772b9..b3bb4ee4 100644 --- a/units/CMakeLists.txt +++ b/units/CMakeLists.txt @@ -10,57 +10,109 @@ set(units_header_files units.hpp units_decl.hpp unit_definitions.hpp units_util. include(GenerateExportHeader) -if(UNITS_HEADER_ONLY) - add_library(units-header-only INTERFACE) +if(UNITS_BUILD_SHARED_LIBRARY OR BUILD_SHARED_LIBS) + add_library(units SHARED ${units_source_files} ${units_header_files}) + generate_export_header(units BASE_NAME units) + target_compile_definitions(units PUBLIC UNITS_EXPORT_HEADER) + target_include_directories( + units + PUBLIC $ + $ + $ + ) + target_link_libraries(units PRIVATE compile_flags_target) + if(NOT UNITS_BUILD_STATIC_LIBRARY) + add_library(units::units ALIAS units) + endif() + add_library(units::units ALIAS units) + if(UNITS_NAMESPACE) + target_compile_definitions( + units PUBLIC -DUNITS_NAMESPACE=${UNITS_NAMESPACE} + ) + endif() + if(UNITS_BASE_TYPE) + target_compile_definitions( + units PUBLIC -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE} + ) + endif() + if(UNITS_INSTALL) + install( + TARGETS units ${UNITS_LIBRARY_EXPORT_COMMAND} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} # INCLUDES DESTINATION + # include/units + ) + endif() + +elseif(UNITS_HEADER_ONLY) + add_library(units INTERFACE) target_include_directories( - units-header-only INTERFACE $ + units INTERFACE $ $ ) - target_compile_definitions(units-header-only INTERFACE UNITS_HEADER_ONLY) + target_compile_definitions(units INTERFACE UNITS_HEADER_ONLY) if(UNITS_INSTALL) - install(TARGETS units-header-only ${UNITS_LIBRARY_EXPORT_COMMAND}) + install(TARGETS units ${UNITS_LIBRARY_EXPORT_COMMAND}) endif() if(UNITS_NAMESPACE) target_compile_definitions( - units-header-only INTERFACE -DUNITS_NAMESPACE=${UNITS_NAMESPACE} + units INTERFACE -DUNITS_NAMESPACE=${UNITS_NAMESPACE} ) endif() if(UNITS_BASE_TYPE) target_compile_definitions( - units-header-only PUBLIC -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE} + units PUBLIC -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE} ) endif() - add_library(units::units-header-only ALIAS units-header-only) -else(UNITS_HEADER_ONLY) - if(UNITS_BUILD_STATIC_LIBRARY) - add_library(units-static STATIC ${units_source_files} ${units_header_files}) + add_library(units::units ALIAS units) + +elseif(UNITS_BUILD_OBJECT_LIBRARY) + add_library(units OBJECT ${units_source_files} ${units_header_files}) target_include_directories( - units-static + units PRIVATE $ + ) + + add_library(units::units ALIAS units) + if(UNITS_NAMESPACE) + target_compile_definitions( + units PUBLIC -DUNITS_NAMESPACE=${UNITS_NAMESPACE} + ) + + if(UNITS_BASE_TYPE) + target_compile_definitions( + units PUBLIC -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE} + ) + endif() + else() + add_library(units STATIC ${units_source_files} ${units_header_files}) + target_include_directories( + units PUBLIC $ $ $ ) - target_link_libraries(units-static PRIVATE compile_flags_target) + target_link_libraries(units PRIVATE compile_flags_target) if(UNITS_ENABLE_TESTS) target_compile_definitions( - units-static PUBLIC -DENABLE_UNIT_TESTING=1 -DENABLE_UNIT_MAP_ACCESS=1 + units PUBLIC -DENABLE_UNIT_TESTING=1 -DENABLE_UNIT_MAP_ACCESS=1 ) endif() if(UNITS_NAMESPACE) target_compile_definitions( - units-static PUBLIC -DUNITS_NAMESPACE=${UNITS_NAMESPACE} + units PUBLIC -DUNITS_NAMESPACE=${UNITS_NAMESPACE} ) endif() if(UNITS_BASE_TYPE) target_compile_definitions( - units-static PUBLIC -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE} + units PUBLIC -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE} ) endif() - add_library(units::units ALIAS units-static) - add_library(units::static ALIAS units-static) + add_library(units::units ALIAS units) + add_library(units ALIAS units) if(UNITS_INSTALL) - install(TARGETS units-static ${UNITS_LIBRARY_EXPORT_COMMAND} + install(TARGETS units ${UNITS_LIBRARY_EXPORT_COMMAND} DESTINATION ${CMAKE_INSTALL_LIBDIR} # INCLUDES DESTINATION # include/units ) @@ -69,68 +121,9 @@ else(UNITS_HEADER_ONLY) set_source_files_properties(foo.cpp PROPERTIES COMPILE_FLAGS -Wno-effc++) endif() if(UNITS_CLANG_TIDY) - set_property(TARGET units-static PROPERTY CXX_CLANG_TIDY "${DO_CLANG_TIDY}") - endif() - endif(UNITS_BUILD_STATIC_LIBRARY) - - if(UNITS_BUILD_SHARED_LIBRARY) - add_library(units-shared SHARED ${units_source_files} ${units_header_files}) - generate_export_header(units-shared BASE_NAME units) - target_compile_definitions(units-shared PUBLIC UNITS_EXPORT_HEADER) - target_include_directories( - units-shared - PUBLIC $ - $ - $ - ) - target_link_libraries(units-shared PRIVATE compile_flags_target) - if(NOT UNITS_BUILD_STATIC_LIBRARY) - add_library(units::units ALIAS units-shared) - endif() - add_library(units::shared ALIAS units-shared) - if(UNITS_NAMESPACE) - target_compile_definitions( - units-shared PUBLIC -DUNITS_NAMESPACE=${UNITS_NAMESPACE} - ) - endif() - if(UNITS_BASE_TYPE) - target_compile_definitions( - units-shared PUBLIC -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE} - ) - endif() - if(UNITS_INSTALL) - install( - TARGETS units-shared ${UNITS_LIBRARY_EXPORT_COMMAND} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} # INCLUDES DESTINATION - # include/units - ) + set_property(TARGET units PROPERTY CXX_CLANG_TIDY "${DO_CLANG_TIDY}") endif() - endif(UNITS_BUILD_SHARED_LIBRARY) - - if(UNITS_BUILD_OBJECT_LIBRARY) - add_library(units-object OBJECT ${units_source_files} ${units_header_files}) - target_include_directories( - units-object PRIVATE $ - ) - - add_library(units::object ALIAS units-object) - if(UNITS_NAMESPACE) - target_compile_definitions( - units-object PUBLIC -DUNITS_NAMESPACE=${UNITS_NAMESPACE} - ) - - if(UNITS_BASE_TYPE) - target_compile_definitions( - units-object PUBLIC -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE} - ) - endif() - endif() - - endif(UNITS_BUILD_OBJECT_LIBRARY) - -endif(UNITS_HEADER_ONLY) + endif() if(UNITS_INSTALL AND NOT UNITS_BINARY_ONLY_INSTALL) install(FILES ${units_header_files} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) From ee18a74f920a86c0f225c7eefd13ec47105fcadb Mon Sep 17 00:00:00 2001 From: Philip Top Date: Thu, 12 Aug 2021 12:36:36 -0700 Subject: [PATCH 02/20] update the cmake for building the test to run with the shared library --- CMakeLists.txt | 24 ++++++++++++++++++ test/CMakeLists.txt | 22 +++++++++++----- test/test_unit_strings.cpp | 5 ++++ units/CMakeLists.txt | 6 ++--- units/units.hpp | 52 +++++++++++++++++++++----------------- 5 files changed, 75 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b7af1af3..3265a41e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,30 @@ if(NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED) set(CMAKE_CXX_STANDARD_REQUIRED ON) endif() +# Set the build output paths +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" CACHE PATH + "Archive output dir." + ) + endif() + if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" CACHE PATH + "Library output dir." + ) + endif() + if(NOT CMAKE_PDB_OUTPUT_DIRECTORY) + set(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" + CACHE PATH "PDB (MSVC debug symbol)output dir." + ) + endif() + if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" + CACHE PATH "Executable/dll output dir." + ) + endif() +endif() + list(APPEND CMAKE_MODULE_PATH "${UNITS_SOURCE_DIR}/config") list(APPEND CMAKE_MODULE_PATH "${UNITS_SOURCE_DIR}/ThirdParty/cmake") diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 834b93a5..6c9dcc86 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -21,7 +21,6 @@ set(UNITS_TESTS test_unit_strings test_measurement_strings test_commodities - test_leadingNumbers test_siunits ) @@ -32,7 +31,7 @@ if(UNITS_HEADER_ONLY) foreach(T ${UNIT_TEST_HEADER_ONLY}) add_unit_test(${T}.cpp) - target_link_libraries(${T} units::units-header-only compile_flags_target) + target_link_libraries(${T} units::units compile_flags_target) endforeach() if(MSVC) @@ -52,10 +51,19 @@ else() test_unit_strings PUBLIC -DTEST_FILE_FOLDER="${TEST_FILE_FOLDER}" ) - target_compile_definitions( - test_unit_strings PUBLIC -DENABLE_UNIT_TESTING=1 -DENABLE_UNIT_MAP_ACCESS=1 - ) - target_compile_definitions(test_leadingNumbers PUBLIC -DENABLE_UNIT_TESTING=1) + + if (NOT UNITS_BUILD_SHARED_LIBRARY) + target_compile_definitions( + test_unit_strings PUBLIC -DENABLE_UNIT_TESTING=1 -DENABLE_UNIT_MAP_ACCESS=1 + ) + + add_unit_test(test_leadingNumbers.cpp) + target_link_libraries(test_leadingNumbers units::units compile_flags_target) + if(UNITS_CLANG_TIDY) + set_property(TARGET ${T} PROPERTY CXX_CLANG_TIDY "${DO_CLANG_TIDY}") + endif() + target_compile_definitions(test_leadingNumbers PUBLIC -DENABLE_UNIT_TESTING=1) + endif() target_compile_definitions( test_conversions2 PUBLIC -DTEST_FILE_FOLDER="${TEST_FILE_FOLDER}" @@ -102,7 +110,7 @@ else() target_link_libraries(examples_test PRIVATE units::units) target_compile_definitions(examples_test PRIVATE ${TARGET_SPECIAL_COMPILER_FLAGS}) set_target_properties(examples_test PROPERTIES FOLDER "Tests") - add_test(examples_test examples_test) + add_test(examples_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples_test) add_executable(test_all_unit_base test_all_unit_base.cpp) diff --git a/test/test_unit_strings.cpp b/test/test_unit_strings.cpp index 9b891388..a148dcaa 100644 --- a/test/test_unit_strings.cpp +++ b/test/test_unit_strings.cpp @@ -1011,6 +1011,7 @@ TEST(defaultUnits, singleCharacter) EXPECT_EQ(precise::K, default_unit("\xC8")); } +#ifdef ENABLE_UNIT_TESTING TEST(stringGeneration, test1) { auto res = detail::testing::testCleanUpString( @@ -1106,7 +1107,9 @@ TEST(stringCleanup, test_9strings) "10.7*999999999999999999999999lb", 0); EXPECT_EQ(res, "10.7*999999999999999999999999lb"); } +#endif +#ifdef ENABLE_UNIT_MAP_ACCESS TEST(mapTests, testRoundTrip) { const auto& map = detail::getUnitStringMap(); @@ -1188,6 +1191,8 @@ TEST(mapTests, testRoundTripFromUnit) } } } +#endif + namespace units { static std::ostream& operator<<(std::ostream& os, const units::precise_unit& u) diff --git a/units/CMakeLists.txt b/units/CMakeLists.txt index b3bb4ee4..7e4822de 100644 --- a/units/CMakeLists.txt +++ b/units/CMakeLists.txt @@ -21,9 +21,7 @@ if(UNITS_BUILD_SHARED_LIBRARY OR BUILD_SHARED_LIBS) $ ) target_link_libraries(units PRIVATE compile_flags_target) - if(NOT UNITS_BUILD_STATIC_LIBRARY) - add_library(units::units ALIAS units) - endif() + add_library(units::units ALIAS units) if(UNITS_NAMESPACE) target_compile_definitions( @@ -84,6 +82,7 @@ elseif(UNITS_BUILD_OBJECT_LIBRARY) units PUBLIC -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE} ) endif() + endif() else() add_library(units STATIC ${units_source_files} ${units_header_files}) target_include_directories( @@ -110,7 +109,6 @@ elseif(UNITS_BUILD_OBJECT_LIBRARY) ) endif() add_library(units::units ALIAS units) - add_library(units ALIAS units) if(UNITS_INSTALL) install(TARGETS units ${UNITS_LIBRARY_EXPORT_COMMAND} DESTINATION ${CMAKE_INSTALL_LIBDIR} # INCLUDES DESTINATION diff --git a/units/units.hpp b/units/units.hpp index 5611c6e8..300870a6 100644 --- a/units/units.hpp +++ b/units/units.hpp @@ -1751,15 +1751,17 @@ constexpr measurement measurement_cast(const uncertain_measurement& measure) #ifndef UNITS_HEADER_ONLY -measurement root(const measurement& meas, int power); +UNITS_EXPORT measurement root(const measurement& meas, int power); -fixed_measurement root(const fixed_measurement& fm, int power); +UNITS_EXPORT fixed_measurement root(const fixed_measurement& fm, int power); -uncertain_measurement root(const uncertain_measurement& um, int power); +UNITS_EXPORT uncertain_measurement + root(const uncertain_measurement& um, int power); -precise_measurement root(const precise_measurement& pm, int power); +UNITS_EXPORT precise_measurement root(const precise_measurement& pm, int power); -fixed_precise_measurement root(const fixed_precise_measurement& fpm, int power); +UNITS_EXPORT fixed_precise_measurement + root(const fixed_precise_measurement& fpm, int power); inline measurement sqrt(const measurement& meas) { @@ -1865,7 +1867,7 @@ inline unit unit_cast_from_string( @return a precise unit corresponding to the SI unit for the measurement specified in unit_type */ -precise_unit default_unit(std::string unit_type); +UNITS_EXPORT precise_unit default_unit(std::string unit_type); /** Generate a precise_measurement from a string @param measurement_string the string to convert @@ -1923,14 +1925,16 @@ UNITS_EXPORT std::string to_string( std::uint32_t match_flags = 0U); /// Add a custom unit to be included in any string processing -void addUserDefinedUnit(const std::string& name, const precise_unit& un); +UNITS_EXPORT void + addUserDefinedUnit(const std::string& name, const precise_unit& un); /// Add a custom unit to be included in from string interpretation but not used /// in generating string representations of units -void addUserDefinedInputUnit(const std::string& name, const precise_unit& un); +UNITS_EXPORT void + addUserDefinedInputUnit(const std::string& name, const precise_unit& un); /// Clear all user defined units from memory -void clearUserDefinedUnits(); +UNITS_EXPORT void clearUserDefinedUnits(); /** load a set of user define units from a file @details file should consist of lines formatted like == @@ -1942,37 +1946,38 @@ interpreted but the output units are not modified. # indicates a comment line @return a string which will be empty if everything worked and an error message if it didn't */ -std::string definedUnitsFromFile(const std::string& filename) noexcept; +UNITS_EXPORT std::string + definedUnitsFromFile(const std::string& filename) noexcept; /// Turn off the ability to add custom units for later access -void disableUserDefinedUnits(); +UNITS_EXPORT void disableUserDefinedUnits(); /// Enable the ability to add custom units for later access -void enableUserDefinedUnits(); +UNITS_EXPORT void enableUserDefinedUnits(); /// get the code to use for a particular commodity -std::uint32_t getCommodity(std::string comm); +UNITS_EXPORT std::uint32_t getCommodity(std::string comm); /// get the code to use for a particular commodity -std::string getCommodityName(std::uint32_t commodity); +UNITS_EXPORT std::string getCommodityName(std::uint32_t commodity); /// add a custom commodity for later retrieval -void addCustomCommodity(std::string comm, std::uint32_t code); +UNITS_EXPORT void addCustomCommodity(std::string comm, std::uint32_t code); /// clear all custom commodities -void clearCustomCommodities(); +UNITS_EXPORT void clearCustomCommodities(); /// Turn off the ability to add custom commodities for later access -void disableCustomCommodities(); +UNITS_EXPORT void disableCustomCommodities(); /// Enable the ability to add custom commodities for later access -void enableCustomCommodities(); +UNITS_EXPORT void enableCustomCommodities(); #define EXTRA_UNIT_STANDARDS // Some specific unit code standards #ifdef EXTRA_UNIT_STANDARDS /// generate a unit from a string as defined by the X12 standard -precise_unit x12_unit(const std::string& x12_string); +UNITS_EXPORT precise_unit x12_unit(const std::string& x12_string); /// generate a unit from a string as defined by the US DOD -precise_unit dod_unit(const std::string& dod_string); +UNITS_EXPORT precise_unit dod_unit(const std::string& dod_string); /// generate a unit from a string as defined by the r20 standard -precise_unit r20_unit(const std::string& r20_string); +UNITS_EXPORT precise_unit r20_unit(const std::string& r20_string); #endif #endif // UNITS_HEADER_ONLY @@ -2080,8 +2085,9 @@ namespace detail { #ifdef ENABLE_UNIT_MAP_ACCESS namespace detail { - const std::unordered_map& getUnitStringMap(); - const std::unordered_map& getUnitNameMap(); + UNITS_EXPORT const std::unordered_map& + getUnitStringMap(); + UNITS_EXPORT const std::unordered_map& getUnitNameMap(); } // namespace detail #endif From 569c24ef489752cc623781e841b0bf210a6a880e Mon Sep 17 00:00:00 2001 From: Philip Top Date: Thu, 12 Aug 2021 12:46:24 -0700 Subject: [PATCH 03/20] update azure pipelines --- azure-pipelines.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 67531157..82c9a7c1 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -46,6 +46,7 @@ jobs: units.std: 11 Windows17: vmImage: 'vs2017-win2016' + units.options: -DUNITS_BUILD_SHARED_LBIRARY=ON units.std: 17 Windows11: vmImage: 'vs2017-win2016' From b88454f1d79d96c4553a78df77bf3e316984a249 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Thu, 12 Aug 2021 13:16:00 -0700 Subject: [PATCH 04/20] tweak the travis builds --- .travis.yml | 4 ++-- units/CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 73de2eaa..74cbde63 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ matrix: - CCACHE_CPP2=yes script: - .ci/make_and_test.sh 11 - - .ci/make_and_test.sh 14 -DUNITS_HEADER_ONLY=ON + - .ci/make_and_test.sh 14 # - .ci/make_and_test.sh 14 # - .ci/make_and_test.sh 17 # Docs and clang 3.5 @@ -66,7 +66,7 @@ matrix: - 'bash .ci/run_codecov.sh' script: - .ci/make_and_test.sh 11 - - .ci/make_and_test.sh 14 + - .ci/make_and_test.sh 14 -DUNITS_HEADER_ONLY=ON - .ci/make_and_test.sh 17 # GCC 4.8 diff --git a/units/CMakeLists.txt b/units/CMakeLists.txt index 7e4822de..701365fb 100644 --- a/units/CMakeLists.txt +++ b/units/CMakeLists.txt @@ -125,7 +125,7 @@ elseif(UNITS_BUILD_OBJECT_LIBRARY) if(UNITS_INSTALL AND NOT UNITS_BINARY_ONLY_INSTALL) install(FILES ${units_header_files} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) - if(UNITS_BUILD_SHARED_LIBRARY) + if(UNITS_BUILD_SHARED_LIBRARY OR BUILD_SHARED_LIBS) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/units_export.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/units) endif() endif() From b7eb115a0893da025d0fef545860b4f50a40dfd8 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Thu, 12 Aug 2021 13:31:25 -0700 Subject: [PATCH 05/20] try reordering the tests --- .travis.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 74cbde63..750a5ea9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,9 +18,6 @@ matrix: - CCACHE_CPP2=yes script: - .ci/make_and_test.sh 11 - - .ci/make_and_test.sh 14 - # - .ci/make_and_test.sh 14 - # - .ci/make_and_test.sh 17 # Docs and clang 3.5 - compiler: clang env: @@ -65,9 +62,9 @@ matrix: - '. .ci/build_lcov.sh' - 'bash .ci/run_codecov.sh' script: - - .ci/make_and_test.sh 11 - .ci/make_and_test.sh 14 -DUNITS_HEADER_ONLY=ON - .ci/make_and_test.sh 17 + - .ci/make_and_test.sh 11 # GCC 4.8 - compiler: gcc From 9dc647824954440f8ba8edd1ef08b9136f2a3a31 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Thu, 12 Aug 2021 13:39:01 -0700 Subject: [PATCH 06/20] more travis build updates --- .travis.yml | 23 +++++++++++++++++++++++ azure-pipelines.yml | 3 +++ units/CMakeLists.txt | 9 ++++----- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 750a5ea9..5cf8e60e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -63,9 +63,32 @@ matrix: - 'bash .ci/run_codecov.sh' script: - .ci/make_and_test.sh 14 -DUNITS_HEADER_ONLY=ON + + # GCC 7 test2 (8 does not support lcov, wait till 9 and new lcov) + - compiler: gcc + env: + - GCC_VER=7 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-7 + - curl + - lcov + install: + - export CC=gcc-7 + - export CXX=g++-7 + - DEPS_DIR="${TRAVIS_BUILD_DIR}/deps" + - cd $TRAVIS_BUILD_DIR + - '. .ci/build_lcov.sh' + - 'bash .ci/run_codecov.sh' + script: + - .ci/make_and_test.sh 14 - .ci/make_and_test.sh 17 - .ci/make_and_test.sh 11 + # GCC 4.8 - compiler: gcc env: diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 82c9a7c1..74452689 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -38,6 +38,9 @@ jobs: matrix: Linux14: vmImage: 'ubuntu-latest' + Linux14shared: + vmImage: 'ubuntu-latest' + units.options: -DUNITS_BUILD_SHARED_LBIRARY=ON macOS17: vmImage: 'macOS-latest' units.std: 17 diff --git a/units/CMakeLists.txt b/units/CMakeLists.txt index 701365fb..e8f0fde0 100644 --- a/units/CMakeLists.txt +++ b/units/CMakeLists.txt @@ -22,7 +22,7 @@ if(UNITS_BUILD_SHARED_LIBRARY OR BUILD_SHARED_LIBS) ) target_link_libraries(units PRIVATE compile_flags_target) - add_library(units::units ALIAS units) + if(UNITS_NAMESPACE) target_compile_definitions( units PUBLIC -DUNITS_NAMESPACE=${UNITS_NAMESPACE} @@ -60,10 +60,9 @@ elseif(UNITS_HEADER_ONLY) endif() if(UNITS_BASE_TYPE) target_compile_definitions( - units PUBLIC -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE} + units INTERFACE -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE} ) endif() - add_library(units::units ALIAS units) elseif(UNITS_BUILD_OBJECT_LIBRARY) add_library(units OBJECT ${units_source_files} ${units_header_files}) @@ -71,7 +70,6 @@ elseif(UNITS_BUILD_OBJECT_LIBRARY) units PRIVATE $ ) - add_library(units::units ALIAS units) if(UNITS_NAMESPACE) target_compile_definitions( units PUBLIC -DUNITS_NAMESPACE=${UNITS_NAMESPACE} @@ -108,7 +106,6 @@ elseif(UNITS_BUILD_OBJECT_LIBRARY) units PUBLIC -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE} ) endif() - add_library(units::units ALIAS units) if(UNITS_INSTALL) install(TARGETS units ${UNITS_LIBRARY_EXPORT_COMMAND} DESTINATION ${CMAKE_INSTALL_LIBDIR} # INCLUDES DESTINATION @@ -123,6 +120,8 @@ elseif(UNITS_BUILD_OBJECT_LIBRARY) endif() endif() +add_library(units::units ALIAS units) + if(UNITS_INSTALL AND NOT UNITS_BINARY_ONLY_INSTALL) install(FILES ${units_header_files} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) if(UNITS_BUILD_SHARED_LIBRARY OR BUILD_SHARED_LIBS) From ae61f444faeb9263645c1828d3d68a483c8da22b Mon Sep 17 00:00:00 2001 From: Philip Top Date: Thu, 12 Aug 2021 15:10:40 -0700 Subject: [PATCH 07/20] change the header_only target --- test/CMakeLists.txt | 2 +- units/CMakeLists.txt | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6c9dcc86..1bfa0cef 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -31,7 +31,7 @@ if(UNITS_HEADER_ONLY) foreach(T ${UNIT_TEST_HEADER_ONLY}) add_unit_test(${T}.cpp) - target_link_libraries(${T} units::units compile_flags_target) + target_link_libraries(${T} units::header_only compile_flags_target) endforeach() if(MSVC) diff --git a/units/CMakeLists.txt b/units/CMakeLists.txt index e8f0fde0..ce6ee45e 100644 --- a/units/CMakeLists.txt +++ b/units/CMakeLists.txt @@ -42,28 +42,28 @@ if(UNITS_BUILD_SHARED_LIBRARY OR BUILD_SHARED_LIBS) # include/units ) endif() - + add_library(units::units ALIAS units) elseif(UNITS_HEADER_ONLY) - add_library(units INTERFACE) + add_library(header_only INTERFACE) target_include_directories( - units INTERFACE $ + header_only INTERFACE $ $ ) - target_compile_definitions(units INTERFACE UNITS_HEADER_ONLY) + target_compile_definitions(header_only INTERFACE UNITS_HEADER_ONLY) if(UNITS_INSTALL) - install(TARGETS units ${UNITS_LIBRARY_EXPORT_COMMAND}) + install(TARGETS header_only ${UNITS_LIBRARY_EXPORT_COMMAND}) endif() if(UNITS_NAMESPACE) target_compile_definitions( - units INTERFACE -DUNITS_NAMESPACE=${UNITS_NAMESPACE} + header_only INTERFACE -DUNITS_NAMESPACE=${UNITS_NAMESPACE} ) endif() if(UNITS_BASE_TYPE) target_compile_definitions( - units INTERFACE -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE} + header_only INTERFACE -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE} ) endif() - + add_library(units::header_only ALIAS header_only) elseif(UNITS_BUILD_OBJECT_LIBRARY) add_library(units OBJECT ${units_source_files} ${units_header_files}) target_include_directories( @@ -118,9 +118,11 @@ elseif(UNITS_BUILD_OBJECT_LIBRARY) if(UNITS_CLANG_TIDY) set_property(TARGET units PROPERTY CXX_CLANG_TIDY "${DO_CLANG_TIDY}") endif() + add_library(units::units ALIAS units) endif() -add_library(units::units ALIAS units) + + if(UNITS_INSTALL AND NOT UNITS_BINARY_ONLY_INSTALL) install(FILES ${units_header_files} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) From a03421aa6c4a4f9ac9c5edc1314582191b6758a7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 12 Aug 2021 15:32:38 -0700 Subject: [PATCH 08/20] Automated formatting of repo files (#156) Co-authored-by: Philip Top Co-authored-by: HELICS-bot --- .travis.yml | 3 +- CMakeLists.txt | 16 ++- test/CMakeLists.txt | 3 +- test/find_package_tests/CMakeLists.txt | 10 +- test/pkg_test_code/header_only.cpp | 6 +- test/pkg_test_code/main.cpp | 8 +- units/CMakeLists.txt | 151 +++++++++++-------------- 7 files changed, 94 insertions(+), 103 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5cf8e60e..464578b7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -63,7 +63,7 @@ matrix: - 'bash .ci/run_codecov.sh' script: - .ci/make_and_test.sh 14 -DUNITS_HEADER_ONLY=ON - + # GCC 7 test2 (8 does not support lcov, wait till 9 and new lcov) - compiler: gcc env: @@ -88,7 +88,6 @@ matrix: - .ci/make_and_test.sh 17 - .ci/make_and_test.sh 11 - # GCC 4.8 - compiler: gcc env: diff --git a/CMakeLists.txt b/CMakeLists.txt index 3265a41e..5fb620dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,22 +41,26 @@ endif() # Set the build output paths if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY) - set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" CACHE PATH - "Archive output dir." + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY + "${CMAKE_BINARY_DIR}/lib" + CACHE PATH "Archive output dir." ) endif() if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY) - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" CACHE PATH - "Library output dir." + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY + "${CMAKE_BINARY_DIR}/lib" + CACHE PATH "Library output dir." ) endif() if(NOT CMAKE_PDB_OUTPUT_DIRECTORY) - set(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" + set(CMAKE_PDB_OUTPUT_DIRECTORY + "${CMAKE_BINARY_DIR}/bin" CACHE PATH "PDB (MSVC debug symbol)output dir." ) endif() if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY) - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY + "${CMAKE_BINARY_DIR}/bin" CACHE PATH "Executable/dll output dir." ) endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1bfa0cef..56c77ad8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -51,8 +51,7 @@ else() test_unit_strings PUBLIC -DTEST_FILE_FOLDER="${TEST_FILE_FOLDER}" ) - - if (NOT UNITS_BUILD_SHARED_LIBRARY) + if(NOT UNITS_BUILD_SHARED_LIBRARY) target_compile_definitions( test_unit_strings PUBLIC -DENABLE_UNIT_TESTING=1 -DENABLE_UNIT_MAP_ACCESS=1 ) diff --git a/test/find_package_tests/CMakeLists.txt b/test/find_package_tests/CMakeLists.txt index a13f3b0d..887051fa 100644 --- a/test/find_package_tests/CMakeLists.txt +++ b/test/find_package_tests/CMakeLists.txt @@ -25,14 +25,18 @@ if(UNITS_BUILD_SHARED_LIBRARY) target_link_libraries(shared-library-test-exe UNITS::units) add_test(NAME shared-library-test COMMAND shared-library-test-exe) - set_property(TEST shared-library-test PROPERTY PASS_REGULAR_EXPRESSION "${HELICS_VERSION}") + set_property( + TEST shared-library-test PROPERTY PASS_REGULAR_EXPRESSION "${HELICS_VERSION}" + ) -# Test the C and C++98 targets + # Test the C and C++98 targets elseif(UNITS_HEADER_ONLY) add_executable(header_only-exe ../pkg_test_code/header_only.cpp) target_link_libraries(header_only-exe UNITS::units) add_test(NAME header_only-exe COMMAND header_only-exe) - set_property(TEST c-shared-library-test PROPERTY PASS_REGULAR_EXPRESSION "${HELICS_VERSION}") + set_property( + TEST c-shared-library-test PROPERTY PASS_REGULAR_EXPRESSION "${HELICS_VERSION}" + ) endif() diff --git a/test/pkg_test_code/header_only.cpp b/test/pkg_test_code/header_only.cpp index aedc18e3..e20ae555 100644 --- a/test/pkg_test_code/header_only.cpp +++ b/test/pkg_test_code/header_only.cpp @@ -1,8 +1,8 @@ /* Copyright (c) 2019, -Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable -Energy, LLC. See the top-level NOTICE for additional details. All rights reserved. -SPDX-License-Identifier: BSD-3-Clause +Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance +for Sustainable Energy, LLC. See the top-level NOTICE for additional details. +All rights reserved. SPDX-License-Identifier: BSD-3-Clause */ #include "helics/helics.h" diff --git a/test/pkg_test_code/main.cpp b/test/pkg_test_code/main.cpp index 714ad357..1648e1d5 100644 --- a/test/pkg_test_code/main.cpp +++ b/test/pkg_test_code/main.cpp @@ -1,8 +1,8 @@ /* Copyright (c) 2021, -Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable -Energy, LLC. See the top-level NOTICE for additional details. All rights reserved. -SPDX-License-Identifier: BSD-3-Clause +Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance +for Sustainable Energy, LLC. See the top-level NOTICE for additional details. +All rights reserved. SPDX-License-Identifier: BSD-3-Clause */ #include "units/units.hpp" @@ -13,6 +13,6 @@ int main(int /*argc*/, char* /*argv*/[]) { auto u1 = units::measurement_from_string("10.7 meters per second"); - std::cout << u1 << std::endl; + std::cout << u1 << std::endl; return 0; } diff --git a/units/CMakeLists.txt b/units/CMakeLists.txt index ce6ee45e..cb7c0036 100644 --- a/units/CMakeLists.txt +++ b/units/CMakeLists.txt @@ -11,43 +11,38 @@ set(units_header_files units.hpp units_decl.hpp unit_definitions.hpp units_util. include(GenerateExportHeader) if(UNITS_BUILD_SHARED_LIBRARY OR BUILD_SHARED_LIBS) - add_library(units SHARED ${units_source_files} ${units_header_files}) - generate_export_header(units BASE_NAME units) - target_compile_definitions(units PUBLIC UNITS_EXPORT_HEADER) - target_include_directories( - units - PUBLIC $ - $ - $ + add_library(units SHARED ${units_source_files} ${units_header_files}) + generate_export_header(units BASE_NAME units) + target_compile_definitions(units PUBLIC UNITS_EXPORT_HEADER) + target_include_directories( + units + PUBLIC $ + $ + $ + ) + target_link_libraries(units PRIVATE compile_flags_target) + + if(UNITS_NAMESPACE) + target_compile_definitions(units PUBLIC -DUNITS_NAMESPACE=${UNITS_NAMESPACE}) + endif() + if(UNITS_BASE_TYPE) + target_compile_definitions(units PUBLIC -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE}) + endif() + if(UNITS_INSTALL) + install( + TARGETS units ${UNITS_LIBRARY_EXPORT_COMMAND} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} # INCLUDES DESTINATION + # include/units ) - target_link_libraries(units PRIVATE compile_flags_target) - - - if(UNITS_NAMESPACE) - target_compile_definitions( - units PUBLIC -DUNITS_NAMESPACE=${UNITS_NAMESPACE} - ) - endif() - if(UNITS_BASE_TYPE) - target_compile_definitions( - units PUBLIC -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE} - ) - endif() - if(UNITS_INSTALL) - install( - TARGETS units ${UNITS_LIBRARY_EXPORT_COMMAND} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} # INCLUDES DESTINATION - # include/units - ) - endif() - add_library(units::units ALIAS units) + endif() + add_library(units::units ALIAS units) elseif(UNITS_HEADER_ONLY) add_library(header_only INTERFACE) target_include_directories( header_only INTERFACE $ - $ + $ ) target_compile_definitions(header_only INTERFACE UNITS_HEADER_ONLY) if(UNITS_INSTALL) @@ -63,70 +58,60 @@ elseif(UNITS_HEADER_ONLY) header_only INTERFACE -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE} ) endif() - add_library(units::header_only ALIAS header_only) + add_library(units::header_only ALIAS header_only) elseif(UNITS_BUILD_OBJECT_LIBRARY) - add_library(units OBJECT ${units_source_files} ${units_header_files}) - target_include_directories( - units PRIVATE $ - ) + add_library(units OBJECT ${units_source_files} ${units_header_files}) + target_include_directories(units PRIVATE $) - if(UNITS_NAMESPACE) - target_compile_definitions( - units PUBLIC -DUNITS_NAMESPACE=${UNITS_NAMESPACE} - ) - - if(UNITS_BASE_TYPE) - target_compile_definitions( - units PUBLIC -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE} - ) - endif() - endif() - else() - add_library(units STATIC ${units_source_files} ${units_header_files}) - target_include_directories( - units - PUBLIC $ - $ - $ - ) - target_link_libraries(units PRIVATE compile_flags_target) + if(UNITS_NAMESPACE) + target_compile_definitions(units PUBLIC -DUNITS_NAMESPACE=${UNITS_NAMESPACE}) - if(UNITS_ENABLE_TESTS) - target_compile_definitions( - units PUBLIC -DENABLE_UNIT_TESTING=1 -DENABLE_UNIT_MAP_ACCESS=1 - ) - endif() - if(UNITS_NAMESPACE) - target_compile_definitions( - units PUBLIC -DUNITS_NAMESPACE=${UNITS_NAMESPACE} - ) - endif() if(UNITS_BASE_TYPE) target_compile_definitions( units PUBLIC -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE} ) endif() - if(UNITS_INSTALL) - install(TARGETS units ${UNITS_LIBRARY_EXPORT_COMMAND} - DESTINATION ${CMAKE_INSTALL_LIBDIR} # INCLUDES DESTINATION - # include/units - ) - endif(UNITS_INSTALL) - if(CMAKE_BUILD_TYPE STREQUAL Coverage) - set_source_files_properties(foo.cpp PROPERTIES COMPILE_FLAGS -Wno-effc++) - endif() - if(UNITS_CLANG_TIDY) - set_property(TARGET units PROPERTY CXX_CLANG_TIDY "${DO_CLANG_TIDY}") - endif() - add_library(units::units ALIAS units) endif() +else() + add_library(units STATIC ${units_source_files} ${units_header_files}) + target_include_directories( + units + PUBLIC $ + $ + $ + ) + target_link_libraries(units PRIVATE compile_flags_target) - - + if(UNITS_ENABLE_TESTS) + target_compile_definitions( + units PUBLIC -DENABLE_UNIT_TESTING=1 -DENABLE_UNIT_MAP_ACCESS=1 + ) + endif() + if(UNITS_NAMESPACE) + target_compile_definitions(units PUBLIC -DUNITS_NAMESPACE=${UNITS_NAMESPACE}) + endif() + if(UNITS_BASE_TYPE) + target_compile_definitions(units PUBLIC -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE}) + endif() + if(UNITS_INSTALL) + install(TARGETS units ${UNITS_LIBRARY_EXPORT_COMMAND} + DESTINATION ${CMAKE_INSTALL_LIBDIR} # INCLUDES DESTINATION include/units + ) + endif(UNITS_INSTALL) + if(CMAKE_BUILD_TYPE STREQUAL Coverage) + set_source_files_properties(foo.cpp PROPERTIES COMPILE_FLAGS -Wno-effc++) + endif() + if(UNITS_CLANG_TIDY) + set_property(TARGET units PROPERTY CXX_CLANG_TIDY "${DO_CLANG_TIDY}") + endif() + add_library(units::units ALIAS units) +endif() if(UNITS_INSTALL AND NOT UNITS_BINARY_ONLY_INSTALL) install(FILES ${units_header_files} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) if(UNITS_BUILD_SHARED_LIBRARY OR BUILD_SHARED_LIBS) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/units_export.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/units) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/units_export.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/units + ) endif() endif() From 68064101f818546a3bf63a6cf752be34a509fdbd Mon Sep 17 00:00:00 2001 From: Philip Top Date: Thu, 12 Aug 2021 17:31:58 -0700 Subject: [PATCH 09/20] add installer tests --- .circleci/config.yml | 27 +++++++++ FuzzTargets/CMakeLists.txt | 2 +- FuzzTargets/fuzz_target_from_string.cpp | 2 +- .../fuzz_target_measurement_from_string.cpp | 2 +- README.md | 14 +++-- docs/installation/cmake_variables.rst | 13 ++-- test/CMakeLists.txt | 60 +++++++++++++++++++ test/find_package_tests/CMakeLists.txt | 6 +- 8 files changed, 107 insertions(+), 19 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a15239e3..9d461c8f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,5 +1,14 @@ version: 2 aliases: + - &setup_units + name: setup_units + environment: + command: | + mkdir -p build + cd build + eval cmake .. ${CMAKE_FLAGS} + make -j 4 + - &run_units name: run_units environment: @@ -20,6 +29,13 @@ aliases: make -j 4 make QUICK_RAW_FUZZ + - &run_installer_tests + name: run_installer_tests + command: | + cd build + make install + ctest -V -R find-package-tests + jobs: unitsTSan: docker: @@ -69,6 +85,16 @@ jobs: - store_artifacts: path: /root/project/build/FuzzTargets/units_fail_measurement_artifact.txt + unitsInstall: + docker: + - image: helics/buildenv:builder + environment: + CMAKE_FLAGS: '-DUNITS_BUILD_TESTS=ON -DUNITS_INSTALL_PACKAGE_TESTS=ON -DUNITS_BUILD_SHARED_LIBRARY=ON' + steps: + - checkout + - run: *setup_units + - run: *run_installer_tests + workflows: version: 2 units_test: @@ -76,4 +102,5 @@ workflows: - unitsMSan - unitsASan - unitsTSan + - unitsInstall - unitsFuzz diff --git a/FuzzTargets/CMakeLists.txt b/FuzzTargets/CMakeLists.txt index a63dc009..d6025322 100644 --- a/FuzzTargets/CMakeLists.txt +++ b/FuzzTargets/CMakeLists.txt @@ -1,5 +1,5 @@ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Copyright (c) 2019-2020, +# Copyright (c) 2019-2021, # Lawrence Livermore National Security, LLC; # See the top-level NOTICE for additional details. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause diff --git a/FuzzTargets/fuzz_target_from_string.cpp b/FuzzTargets/fuzz_target_from_string.cpp index a94d4c12..8ef3e67b 100644 --- a/FuzzTargets/fuzz_target_from_string.cpp +++ b/FuzzTargets/fuzz_target_from_string.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2019-2020, +Copyright (c) 2019-2021, Lawrence Livermore National Security, LLC; See the top-level NOTICE for additional details. All rights reserved. SPDX-License-Identifier: BSD-3-Clause diff --git a/FuzzTargets/fuzz_target_measurement_from_string.cpp b/FuzzTargets/fuzz_target_measurement_from_string.cpp index 4336d557..3d92875f 100644 --- a/FuzzTargets/fuzz_target_measurement_from_string.cpp +++ b/FuzzTargets/fuzz_target_measurement_from_string.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2019-2020, +Copyright (c) 2019-2021, Lawrence Livermore National Security, LLC; See the top-level NOTICE for additional details. All rights reserved. SPDX-License-Identifier: BSD-3-Clause diff --git a/README.md b/README.md index f76a7fc9..5e797ff6 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ if (!meas.units().is_convertible(out) ## Limitations -- The powers represented by units are limited see [Unit representation](#unit_representation) and only normal physical units or common operations are supported. +- The powers represented by units by default are limited see [Unit representation](#unit_representation) and only normal physical units or common operations are supported, this can be modified at compile time to support a much broader range at the expense of size and computation. - The library uses floating point and double precision for the multipliers which is generally good enough for most engineering contexts, but does come with the limits and associated loss of precision for long series of calculations on floating point numbers. - Currency is supported as a unit but it is not recommended to use this for anything beyond basic financial calculations. So if you are doing a lot of financial calculations or accounting use something more specific for currency manipulations. - Fractional unit powers are not supported in general. While some mathematical operations on units are supported any root operations `sqrt` or `cbrt` will only produce valid results if the result is integral powers of the base units. One exception is limited support for √Hz operations in measurements of Amplitude spectral density. A specific definition of a unit representing square root of Hz is available and will work in combination with other units. @@ -99,7 +99,7 @@ These libraries will work well if the number of units being dealt with is known 5. Working with per unit values 6. Dealing with commodities in addition to regular units. i.e. differentiate between a gallon of water and a gallon of gasoline 7. Dealing with equation type units -8. Complete C++ type safety is not a critical design requirement. +8. Complete C++ type safety is **NOT** a critical design requirement. 9. Support is needed for some funky custom unit with bizarre base units. ### Reasons to choose something else @@ -108,7 +108,7 @@ These libraries will work well if the number of units being dealt with is known 2. Performance is absolutely critical (many other libraries are zero runtime overhead) 3. You are only working with a small number of known units 4. You cannot use C++11 yet. -5. You need to operate on arbitrary powers of base units +5. You need to operate on arbitrary or fractional powers of base units ## Types @@ -143,11 +143,13 @@ The seven [SI units](https://www.nist.gov/pml/weights-and-measures/metric-si/si- These ranges were chosen to represent nearly all physical quantities that could be found in various disciplines we have encountered. +The CMake variable `UNITS_BASE_TYPE` if set to a 64 bit type like `uint64_t` will double the space requirements but also change the ranges to be at least a power of 4 larger than the above table. See [Cmake Reference](https://units.readthedocs.io/en/latest/installation/cmake_variables.html) for more details. + ### Discussion points - Currency may seem like a unusual choice in units but numbers involving prices are encountered often enough in various disciplines that it is useful to include as part of a unit. - Technically count and radians are not units, they are representations of real things. A radian is a representation of rotation around a circle and is therefore distinct from a true unitless quantity even though there are no physical measurements associated with either. -- And count and mole are theoretically equivalent though as a practical matter using moles for counts of things is a bit odd for example 1 GB of data is ~1.6605\*10^-15 mol of data. So they are used in different context and don't mix very often, the convert functions does convert between them if necessary. +- Count and mole are theoretically equivalent though as a practical matter using moles for counts of things is a bit odd for example 1 GB of data is ~1.6605\*10^-15 mol of data. So they are used in different context and don't mix very often, the convert functions do convert between them if necessary. - This library **CANNOT** represent fractional unit powers( except for sqrt Hz used in noise density units), and it follows the order of operation in C++ so **IF** you have equations that any portion of the operation may exceed the numerical limits on powers even if the result does not, **BE CAREFUL**. - The normal rules about floating point operations losing precision also apply to unit representations with non-integral multipliers. - With string conversions there are many units that can be interpreted in multiple ways. In general the priority was given to units in more common use in the United States, or in power systems and electrical engineering which was the origin of this library. @@ -170,6 +172,8 @@ There are two parts of the library a header only portion that can simply be copi The second part is a few cpp files that can add some additional functionality. The primary additions from the cpp file are an ability to take roots of units and measurements and convert to and from strings. These files can be built as a standalone static library or included in the source code of whatever project want to use them. The code should build with an C++11 compiler. Most of the library is tagged with constexpr so can be run at compile time to link units that are known at compile time. Unit numerical conversions are not at compile time, so will have a run-time cost. A `quick_convert` function is available to do simple conversions. with a requirement that the units have the same base and not be an equation unit. The cpp code also includes some functions for commodities and will eventually have r20 and x12 conversions, though this is not complete yet. +It builds by default with the static library. Using `UNIT_BUILD_SHARED_LIBRARY` or `BUILD_SHARED_LIBS` will build the shared library instead. Either one can be used with CMake as units::units. The header only library target can also be generate `units::header_only` + ## Try it out If you want to try out the string conversion components. There is server running that can do the string conversions @@ -275,7 +279,7 @@ These functions are not class methods but operate on units #### Uncertain measurement methods -Uncertatin measurements have a few additional functions to support the uncertainty calculations +Uncertain measurements have a few additional functions to support the uncertainty calculations - `rss_add`, `rss_subtract`, `rss_product`, `rss_divide` are equivalent to the associated operator but use the root-sum of squares method for propagating the uncertainty. - `double uncertainty()` get the numerical value of the uncertainty. diff --git a/docs/installation/cmake_variables.rst b/docs/installation/cmake_variables.rst index e8725ce7..d0084eab 100644 --- a/docs/installation/cmake_variables.rst +++ b/docs/installation/cmake_variables.rst @@ -28,7 +28,7 @@ If compiling as part of a subproject then a few other options are useful - `UNITS_HEADER_ONLY`: Only generate the header only target - `UNITS_INSTALL`: enable the install instructions of the library -- `UNITS_WITH_CMAKE_PACKAGE`: Generate the cmake package variables for an installation or package +- `UNITS_WITH_CMAKE_PACKAGE`: Generate the CMake package variables for an installation or package - `UNITS_BUILD_OBJECT_LIBRARY`: Generate an object library that can be used as part of other builds CMake Targets @@ -36,17 +36,14 @@ CMake Targets If you are using the library as a submodule or importing the package there are a couple targets that can be used depending on the build -- `units::static` will be set to the static library if built -- `units::shared` will be set to the shared library if built -- `units::object` will be set to the object library if enabled -- `units::units` will be set to the static library if built or the shared library if built and the static is not -- `units::units-header-only` is a target if `UNITS_HEADER_ONLY` cmake variable is set +- `units::units` will be set to the library being built, either the shared, static, or object +- `units::header_only` is a target if `UNITS_HEADER_ONLY` CMake variable is set Example --------- -As part of the HELICS library the units library is used as a submodule it is included +As part of the `HELICS `_ library the units library is used as a submodule it is included by the following code .. code-block:: cmake @@ -65,7 +62,7 @@ As part of the HELICS library the units library is used as a submodule it is inc add_subdirectory("${PROJECT_SOURCE_DIR}/ThirdParty/units" "${PROJECT_BINARY_DIR}/ThirdParty/units") - set_target_properties(units-static PROPERTIES FOLDER Extern) + set_target_properties(units PROPERTIES FOLDER Extern) hide_variable(UNITS_HEADER_ONLY) hide_variable(UNITS_BUILD_OBJECT_LIBRARY) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 56c77ad8..a6babf22 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -132,4 +132,64 @@ else() ) endif() + + if(UNITS_INSTALL_PACKAGE_TESTS) + set(UNITS_PACKAGE_SEARCH_LOC) + + +if(NOT MSVC) + set(package_test_command --test-command "${CMAKE_CTEST_COMMAND}") +else() # don't try to run the tests on MSVC since that would require copying the dll's and doing + # some other setup that isn't that important to run on all OS + set(package_test_command) +endif() + +if(CMAKE_BUILD_TYPE) + set(UNITS_PACKAGE_TEST_BUILD_TYPE ${CMAKE_BUILD_TYPE}) +else() + set(UNITS_PACKAGE_TEST_BUILD_TYPE Release) +endif() + +file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/find_package_tests") + +if(MSVC AND ${CMAKE_VERSION} VERSION_GREATER 3.12.9) + # Tests for other CMake projects including and using UNITS using find_package + add_test( + NAME find-package-testsA + COMMAND + ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" -A "${CMAKE_GENERATOR_PLATFORM}" + ${UNITS_PACKAGE_SEARCH_LOC} + "-DUNITS_BUILD_SHARED_LIBRARY=${UNITS_BUILD_SHARED_LIBRARY}" + "-DUNITS_HEADER_ONLY=${UNITS_HEADER_ONLY}" + "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" + "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}" + "-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" + "${CMAKE_CURRENT_SOURCE_DIR}/find_package_tests" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/find_package_tests" + ) +else() + add_test( + NAME find-package-testsA + COMMAND + ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" ${UNITS_PACKAGE_SEARCH_LOC} + "-DUNITS_BUILD_SHARED_LIBRARY=${UNITS_BUILD_SHARED_LIBRARY}" + "-DUNITS_HEADER_ONLY=${UNITS_HEADER_ONLY}" + "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" + "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}" + "-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" + "${CMAKE_CURRENT_SOURCE_DIR}/find_package_tests" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/find_package_tests" + ) +endif() + +add_test(NAME find-package-testsB + COMMAND ${CMAKE_COMMAND} --build "${CMAKE_CURRENT_BINARY_DIR}/find_package_tests" --config + ${UNITS_PACKAGE_TEST_BUILD_TYPE} +) + +add_test(NAME find-package-testsC COMMAND ${CMAKE_CTEST_COMMAND} -C + ${UNITS_PACKAGE_TEST_BUILD_TYPE} + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/find_package_tests" +) + endif() #UNITS_INSTALL_PACKAGE_TESTS endif() # UNITS_HEADER_ONLY diff --git a/test/find_package_tests/CMakeLists.txt b/test/find_package_tests/CMakeLists.txt index 887051fa..3c79baf3 100644 --- a/test/find_package_tests/CMakeLists.txt +++ b/test/find_package_tests/CMakeLists.txt @@ -14,7 +14,7 @@ project(units-find-package-test) include(CTest) # Test the HELICS CMake package config -find_package(UNITS 0.6 REQUIRED) +find_package(UNITS 0.5 REQUIRED) # add some tests inside of the CMake @@ -32,11 +32,11 @@ if(UNITS_BUILD_SHARED_LIBRARY) # Test the C and C++98 targets elseif(UNITS_HEADER_ONLY) add_executable(header_only-exe ../pkg_test_code/header_only.cpp) - target_link_libraries(header_only-exe UNITS::units) + target_link_libraries(header_only-exe UNITS::units_headers) add_test(NAME header_only-exe COMMAND header_only-exe) set_property( - TEST c-shared-library-test PROPERTY PASS_REGULAR_EXPRESSION "${HELICS_VERSION}" + TEST header_only-test PROPERTY PASS_REGULAR_EXPRESSION "${HELICS_VERSION}" ) endif() From 2bc410b39232a2ce6fb1f18c33be8aafe0797646 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Thu, 12 Aug 2021 17:46:58 -0700 Subject: [PATCH 10/20] more tries at installer test --- .circleci/config.yml | 2 +- CMakeLists.txt | 28 ++++++++++++++++++++++++-- test/find_package_tests/CMakeLists.txt | 8 ++++---- units/CMakeLists.txt | 2 +- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9d461c8f..6b36c4a2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -89,7 +89,7 @@ jobs: docker: - image: helics/buildenv:builder environment: - CMAKE_FLAGS: '-DUNITS_BUILD_TESTS=ON -DUNITS_INSTALL_PACKAGE_TESTS=ON -DUNITS_BUILD_SHARED_LIBRARY=ON' + CMAKE_FLAGS: '-DUNITS_ENABLE_TESTS=ON -DUNITS_INSTALL_PACKAGE_TESTS=ON -DUNITS_BUILD_SHARED_LIBRARY=ON' steps: - checkout - run: *setup_units diff --git a/CMakeLists.txt b/CMakeLists.txt index 5fb620dc..fed04ab1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -194,7 +194,31 @@ if(UNITS_INSTALL) install(TARGETS compile_flags_target ${UNITS_LIBRARY_EXPORT_COMMAND}) endif() if(UNITS_WITH_CMAKE_PACKAGE AND NOT UNITS_BINARY_ONLY_INSTALL) - install(EXPORT unitsConfig DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/units) - export(EXPORT unitsConfig) + install(EXPORT unitsConfig DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) + export(EXPORT unitsConfig NAMESPACE units::) + write_basic_package_version_file(${PROJECT_BINARY_DIR}/unitsConfigVersion.cmake COMPATIBILITY AnyNewerVersion) + install(FILES ${PROJECT_BINARY_DIR}/unitsConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/units) endif() endif() + + + +#if(HELICS_WITH_CMAKE_PACKAGE) + +# set(HELICS_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" +# CACHE STRING "install path for HELICSConfig.cmake" +# ) +# mark_as_advanced(HELICS_CMAKECONFIG_INSTALL_DIR) + + # Export targets for importing build tree with find_package +# export(EXPORT helics-targets NAMESPACE HELICS:: +# FILE ${PROJECT_BINARY_DIR}/helics-targets.cmake +# ) + +# install( +# EXPORT helics-targets +# NAMESPACE HELICS:: +# DESTINATION ${HELICS_CMAKECONFIG_INSTALL_DIR} +# COMPONENT libs +# ) + endif() \ No newline at end of file diff --git a/test/find_package_tests/CMakeLists.txt b/test/find_package_tests/CMakeLists.txt index 3c79baf3..0f2a00b3 100644 --- a/test/find_package_tests/CMakeLists.txt +++ b/test/find_package_tests/CMakeLists.txt @@ -14,7 +14,7 @@ project(units-find-package-test) include(CTest) # Test the HELICS CMake package config -find_package(UNITS 0.5 REQUIRED) +find_package(units 0.4.8 REQUIRED) # add some tests inside of the CMake @@ -22,17 +22,17 @@ message(STATUS "Binary location is ${PROJECT_BINARY_DIR}") # Test the CXX shared library target if(UNITS_BUILD_SHARED_LIBRARY) add_executable(shared-library-test-exe ../pkg_test_code/main.cpp) - target_link_libraries(shared-library-test-exe UNITS::units) + target_link_libraries(shared-library-test-exe units::units) add_test(NAME shared-library-test COMMAND shared-library-test-exe) set_property( - TEST shared-library-test PROPERTY PASS_REGULAR_EXPRESSION "${HELICS_VERSION}" + TEST shared-library-test PROPERTY PASS_REGULAR_EXPRESSION "10.7" ) # Test the C and C++98 targets elseif(UNITS_HEADER_ONLY) add_executable(header_only-exe ../pkg_test_code/header_only.cpp) - target_link_libraries(header_only-exe UNITS::units_headers) + target_link_libraries(header_only-exe units::units_headers) add_test(NAME header_only-exe COMMAND header_only-exe) set_property( diff --git a/units/CMakeLists.txt b/units/CMakeLists.txt index cb7c0036..90450d42 100644 --- a/units/CMakeLists.txt +++ b/units/CMakeLists.txt @@ -108,7 +108,7 @@ else() endif() if(UNITS_INSTALL AND NOT UNITS_BINARY_ONLY_INSTALL) - install(FILES ${units_header_files} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + install(FILES ${units_header_files} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/units) if(UNITS_BUILD_SHARED_LIBRARY OR BUILD_SHARED_LIBS) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/units_export.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/units From e50ce8d061cf01c55b2e15e3176d1576d5126eb1 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Fri, 13 Aug 2021 05:51:22 -0700 Subject: [PATCH 11/20] try a separate config file --- CMakeLists.txt | 6 +++--- config/unitConfig.cmake.in | 20 ++++++++++++++++++++ converter/CMakeLists.txt | 7 +++++++ webserver/CMakeLists.txt | 21 ++++++++++++++------- webserver/Dockerfile | 4 ++-- webserver/web_script.sh | 2 +- 6 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 config/unitConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index fed04ab1..0aee21d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -194,8 +194,8 @@ if(UNITS_INSTALL) install(TARGETS compile_flags_target ${UNITS_LIBRARY_EXPORT_COMMAND}) endif() if(UNITS_WITH_CMAKE_PACKAGE AND NOT UNITS_BINARY_ONLY_INSTALL) - install(EXPORT unitsConfig DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) - export(EXPORT unitsConfig NAMESPACE units::) + install(EXPORT unitsTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) + export(EXPORT unitsTargets NAMESPACE units::) write_basic_package_version_file(${PROJECT_BINARY_DIR}/unitsConfigVersion.cmake COMPATIBILITY AnyNewerVersion) install(FILES ${PROJECT_BINARY_DIR}/unitsConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/units) endif() @@ -221,4 +221,4 @@ endif() # DESTINATION ${HELICS_CMAKECONFIG_INSTALL_DIR} # COMPONENT libs # ) - endif() \ No newline at end of file +# endif() \ No newline at end of file diff --git a/config/unitConfig.cmake.in b/config/unitConfig.cmake.in new file mode 100644 index 00000000..8d471d43 --- /dev/null +++ b/config/unitConfig.cmake.in @@ -0,0 +1,20 @@ +# - Config file for the units package +# It defines the following variables +# UNITS_INCLUDE_DIRS - include directories for units library +# UNITS_LIBRARIES - libraries to link against +# UNITS_WEBSERVER - the units webserver executable +# UNITS_CONVERT - the units conversion utility + +# Compute paths +get_filename_component(UNITS_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +set(UNITS_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@") + +# Our library dependencies (contains definitions for IMPORTED targets) +if(NOT TARGET units::units AND NOT units_BINARY_DIR) + include("${UNITS_CMAKE_DIR}/unitsTargets.cmake") +endif() + +# These are IMPORTED targets created by FooBarTargets.cmake +set(UNITS_LIBRARIES units::units) +set(UNITS_WEBSERVER units::webserver) +set(UNITS_CONVERT units::convert diff --git a/converter/CMakeLists.txt b/converter/CMakeLists.txt index d042ddc0..3cb8271f 100644 --- a/converter/CMakeLists.txt +++ b/converter/CMakeLists.txt @@ -24,4 +24,11 @@ if(UNITS_BUILD_CONVERTER_APP) target_link_libraries(unit_convert PRIVATE -lstdc++fs) endif() endif() + + if (UNITS_INSTALL) + install(TARGETS unit_convert + EXPORT unitsTargets + RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT units_convert) + endif() + endif() diff --git a/webserver/CMakeLists.txt b/webserver/CMakeLists.txt index b78649bd..3226d9f7 100644 --- a/webserver/CMakeLists.txt +++ b/webserver/CMakeLists.txt @@ -1,5 +1,5 @@ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Copyright (c) 2019-2020, +# Copyright (c) 2019-2021, # Lawrence Livermore National Security, LLC; # See the top-level NOTICE for additional details. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause @@ -17,21 +17,28 @@ if(CMAKE_VERSION VERSION_GREATER 3.12) if(UNITS_BUILD_WEBSERVER) find_package(Boost 1.70.0 REQUIRED) - add_executable(unit_web_server unit_web_server.cpp) + add_executable(units_webserver unit_web_server.cpp) target_link_libraries( - unit_web_server PUBLIC units::units compile_flags_target Boost::boost + units_webserver PUBLIC units::units compile_flags_target Boost::boost ) - target_compile_definitions(unit_web_server PUBLIC BOOST_DATE_TIME_NO_LIB) + target_compile_definitions(units_webserver PUBLIC BOOST_DATE_TIME_NO_LIB) target_compile_definitions( - unit_web_server PUBLIC UNITS_VERSION_STRING="${UNITS_VERSION}" + units_webserver PUBLIC UNITS_VERSION_STRING="${UNITS_VERSION}" ) if(MSYS OR CYGWIN) - target_link_libraries(unit_web_server PUBLIC wsock32 ws2_32 iphlpapi) + target_link_libraries(units_webserver PUBLIC wsock32 ws2_32 iphlpapi) elseif(NOT WIN32) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) - target_link_libraries(unit_web_server PUBLIC Threads::Threads) + target_link_libraries(units_webserver PUBLIC Threads::Threads) endif() + + if (UNITS_INSTALL) + install(TARGETS units_webserver + EXPORT unitsTargets + RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT units_webserver) + endif() + add_executable(units::units_webserver ALIAS units_webserver) endif() endif() diff --git a/webserver/Dockerfile b/webserver/Dockerfile index 069efd31..5afd284d 100644 --- a/webserver/Dockerfile +++ b/webserver/Dockerfile @@ -1,7 +1,7 @@ FROM helics/buildenv:tumbleweed-builder as builder # should already be in /root/develop from the builder -# modification date 2020-05-04 +# modification date 2021-08-13 RUN git clone /~https://github.com/LLNL/units.git units @@ -11,7 +11,7 @@ RUN cmake ../units -DUNITS_BUILD_WEBSERVER=ON -DBUILD_TESTING=OFF -DCMAKE_CXX_ST WORKDIR /root/develop/webserver -RUN cp ../build/webserver/unit_web_server . && cp ../units/webserver/*.html . && cp ../units/webserver/*.sh . +RUN cp ../build/webserver/units_webserver . && cp ../units/webserver/*.html . && cp ../units/webserver/*.sh . FROM opensuse/tumbleweed:latest diff --git a/webserver/web_script.sh b/webserver/web_script.sh index 0c91d979..c7a1d5fb 100755 --- a/webserver/web_script.sh +++ b/webserver/web_script.sh @@ -1,4 +1,4 @@ #!/bin/bash # run the webserver -./unit_web_server 0.0.0.0 80 +./units_webserver 0.0.0.0 80 From 636880fd7e1c6ef7b427a6f638a50c94c1993a2b Mon Sep 17 00:00:00 2001 From: Philip Top Date: Fri, 13 Aug 2021 06:57:46 -0700 Subject: [PATCH 12/20] add config template --- CMakeLists.txt | 63 +++++++------------ ...itConfig.cmake.in => unitsConfig.cmake.in} | 4 +- converter/CMakeLists.txt | 16 ++--- test/CMakeLists.txt | 2 - test/find_package_tests/CMakeLists.txt | 12 ++-- test/pkg_test_code/header_only.cpp | 20 +++--- test/pkg_test_code/main.cpp | 2 +- units/CMakeLists.txt | 56 +++++++++-------- webserver/CMakeLists.txt | 2 +- 9 files changed, 83 insertions(+), 94 deletions(-) rename config/{unitConfig.cmake.in => unitsConfig.cmake.in} (89%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0aee21d4..0bc08a44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,18 +83,15 @@ set(UNITS_NAMESPACE CACHE STRING "Top-level namespace name. Default is `units`." ) -option(UNITS_INSTALL "Enable installation of the units library" ON) -mark_as_advanced(UNITS_INSTALL) - cmake_dependent_option( - UNITS_WITH_CMAKE_PACKAGE + UNITS_INSTALL "Generate and install cmake package files" ON - "CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME;UNITS_INSTALL;NOT UNITS_BINARY_ONLY_INSTALL" + "CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME;NOT UNITS_BINARY_ONLY_INSTALL" OFF ) -mark_as_advanced(UNITS_WITH_CMAKE_PACKAGE) +mark_as_advanced(UNITS_INSTALL) cmake_dependent_option( UNITS_BUILD_FUZZ_TARGETS "Build the targets for a fuzzing system" OFF @@ -113,12 +110,9 @@ set(UNITS_CLANG_TIDY_OPTIONS mark_as_advanced(UNITS_CLANG_TIDY_OPTIONS) mark_as_advanced(UNITS_CLANG_TIDY) -# Install instructions for this target -if(UNITS_WITH_CMAKE_PACKAGE) - set(UNITS_LIBRARY_EXPORT_COMMAND EXPORT unitsConfig) -else(UNITS_WITH_CMAKE_PACKAGE) - set(UNITS_LIBRARY_EXPORT_COMMAND) -endif(UNITS_WITH_CMAKE_PACKAGE) + +set(UNITS_LIBRARY_EXPORT_COMMAND EXPORT unitsTargets) +mark_as_advanced(UNITS_LIBRARY_EXPORT_COMMAND) option(UNITS_HEADER_ONLY "Expose the units library as header-only" OFF) @@ -160,7 +154,13 @@ if(NOT UNITS_HEADER_ONLY) UNITS_BUILD_OBJECT_LIBRARY "Enable construction of the units object library" OFF "NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME" OFF ) - +else() + option(UNITS_BUILD_STATIC_LIBRARY + "enable Construction of the units static library" OFF + ) + option(UNITS_BUILD_SHARED_LIBRARY + "enable Construction of the units shared library" OFF + ) endif(NOT UNITS_HEADER_ONLY) # Prepare Clang-Tidy @@ -193,32 +193,15 @@ if(UNITS_INSTALL) if(UNITS_BUILD_STATIC_LIBRARY) install(TARGETS compile_flags_target ${UNITS_LIBRARY_EXPORT_COMMAND}) endif() - if(UNITS_WITH_CMAKE_PACKAGE AND NOT UNITS_BINARY_ONLY_INSTALL) - install(EXPORT unitsTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) - export(EXPORT unitsTargets NAMESPACE units::) + if(NOT UNITS_BINARY_ONLY_INSTALL) + configure_file(config/unitsConfig.cmake.in + "${PROJECT_BINARY_DIR}/unitsConfig.cmake" @ONLY) + + export(EXPORT unitsTargets NAMESPACE units:: FILE ${PROJECT_BINARY_DIR}/unitsTargets.cmake) + + install(EXPORT unitsTargets NAMESPACE units:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/units) + write_basic_package_version_file(${PROJECT_BINARY_DIR}/unitsConfigVersion.cmake COMPATIBILITY AnyNewerVersion) - install(FILES ${PROJECT_BINARY_DIR}/unitsConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/units) + install(FILES ${PROJECT_BINARY_DIR}/unitsConfigVersion.cmake ${PROJECT_BINARY_DIR}/unitsConfig.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/units) endif() -endif() - - - -#if(HELICS_WITH_CMAKE_PACKAGE) - -# set(HELICS_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" -# CACHE STRING "install path for HELICSConfig.cmake" -# ) -# mark_as_advanced(HELICS_CMAKECONFIG_INSTALL_DIR) - - # Export targets for importing build tree with find_package -# export(EXPORT helics-targets NAMESPACE HELICS:: -# FILE ${PROJECT_BINARY_DIR}/helics-targets.cmake -# ) - -# install( -# EXPORT helics-targets -# NAMESPACE HELICS:: -# DESTINATION ${HELICS_CMAKECONFIG_INSTALL_DIR} -# COMPONENT libs -# ) -# endif() \ No newline at end of file +endif() \ No newline at end of file diff --git a/config/unitConfig.cmake.in b/config/unitsConfig.cmake.in similarity index 89% rename from config/unitConfig.cmake.in rename to config/unitsConfig.cmake.in index 8d471d43..ff0dd26e 100644 --- a/config/unitConfig.cmake.in +++ b/config/unitsConfig.cmake.in @@ -16,5 +16,5 @@ endif() # These are IMPORTED targets created by FooBarTargets.cmake set(UNITS_LIBRARIES units::units) -set(UNITS_WEBSERVER units::webserver) -set(UNITS_CONVERT units::convert +set(UNITS_WEBSERVER units::units_webserver) +set(UNITS_CONVERT units::units_convert) diff --git a/converter/CMakeLists.txt b/converter/CMakeLists.txt index 3cb8271f..93a90a43 100644 --- a/converter/CMakeLists.txt +++ b/converter/CMakeLists.txt @@ -11,24 +11,24 @@ cmake_dependent_option( ) if(UNITS_BUILD_CONVERTER_APP) - add_executable(unit_convert converter.cpp) - target_link_libraries(unit_convert PUBLIC units::units compile_flags_target) - target_include_directories(unit_convert PRIVATE ${PROJECT_SOURCE_DIR}/ThirdParty) + add_executable(units_convert converter.cpp) + target_link_libraries(units_convert PUBLIC units::units compile_flags_target) + target_include_directories(units_convert PRIVATE ${PROJECT_SOURCE_DIR}/ThirdParty) target_compile_definitions( - unit_convert PUBLIC UNITS_VERSION_STRING="${UNITS_VERSION}" + units_convert PUBLIC UNITS_VERSION_STRING="${UNITS_VERSION}" ) if(CMAKE_CXX_STANDARD GREATER 16) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 8 ) - target_link_libraries(unit_convert PRIVATE -lstdc++fs) + target_link_libraries(unit_sconvert PRIVATE -lstdc++fs) endif() endif() if (UNITS_INSTALL) - install(TARGETS unit_convert - EXPORT unitsTargets + install(TARGETS units_convert + ${UNITS_LIBRARY_EXPORT_COMMAND} RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT units_convert) endif() - + add_executable(units::units_convert ALIAS units_convert) endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a6babf22..1a470229 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -160,7 +160,6 @@ if(MSVC AND ${CMAKE_VERSION} VERSION_GREATER 3.12.9) ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" -A "${CMAKE_GENERATOR_PLATFORM}" ${UNITS_PACKAGE_SEARCH_LOC} "-DUNITS_BUILD_SHARED_LIBRARY=${UNITS_BUILD_SHARED_LIBRARY}" - "-DUNITS_HEADER_ONLY=${UNITS_HEADER_ONLY}" "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}" "-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" @@ -173,7 +172,6 @@ else() COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" ${UNITS_PACKAGE_SEARCH_LOC} "-DUNITS_BUILD_SHARED_LIBRARY=${UNITS_BUILD_SHARED_LIBRARY}" - "-DUNITS_HEADER_ONLY=${UNITS_HEADER_ONLY}" "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}" "-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" diff --git a/test/find_package_tests/CMakeLists.txt b/test/find_package_tests/CMakeLists.txt index 0f2a00b3..8a5db0b9 100644 --- a/test/find_package_tests/CMakeLists.txt +++ b/test/find_package_tests/CMakeLists.txt @@ -14,7 +14,7 @@ project(units-find-package-test) include(CTest) # Test the HELICS CMake package config -find_package(units 0.4.8 REQUIRED) +find_package(units 0.5 REQUIRED) # add some tests inside of the CMake @@ -29,14 +29,14 @@ if(UNITS_BUILD_SHARED_LIBRARY) TEST shared-library-test PROPERTY PASS_REGULAR_EXPRESSION "10.7" ) - # Test the C and C++98 targets -elseif(UNITS_HEADER_ONLY) + +endif() +# Test the header only targets add_executable(header_only-exe ../pkg_test_code/header_only.cpp) - target_link_libraries(header_only-exe units::units_headers) + target_link_libraries(header_only-exe units::header_only) add_test(NAME header_only-exe COMMAND header_only-exe) set_property( - TEST header_only-test PROPERTY PASS_REGULAR_EXPRESSION "${HELICS_VERSION}" + TEST header_only-exe PROPERTY PASS_REGULAR_EXPRESSION "PASS" ) -endif() diff --git a/test/pkg_test_code/header_only.cpp b/test/pkg_test_code/header_only.cpp index e20ae555..05339639 100644 --- a/test/pkg_test_code/header_only.cpp +++ b/test/pkg_test_code/header_only.cpp @@ -5,14 +5,20 @@ for Sustainable Energy, LLC. See the top-level NOTICE for additional details. All rights reserved. SPDX-License-Identifier: BSD-3-Clause */ -#include "helics/helics.h" +#include "units/units.hpp" + +#include -#include int main() { - volatile HelicsFederateInfo fedinfo = helicsCreateFederateInfo(); - helicsFederateInfoFree(fedinfo); - printf("%s\n", helicsGetVersion()); - helicsCloseLibrary(); - return (0); + units::measurement b(50.0, units::m); + units::measurement c(25.0, units::f); + auto k = b * c; + + if (k.units() == units::units(m.pow(2))) { + std::cout << "PASS\n"; + } else { + std::cout << "FAILE\n"; + } + return 0; } diff --git a/test/pkg_test_code/main.cpp b/test/pkg_test_code/main.cpp index 1648e1d5..05665bf5 100644 --- a/test/pkg_test_code/main.cpp +++ b/test/pkg_test_code/main.cpp @@ -13,6 +13,6 @@ int main(int /*argc*/, char* /*argv*/[]) { auto u1 = units::measurement_from_string("10.7 meters per second"); - std::cout << u1 << std::endl; + std::cout << to_string(u1) << std::endl; return 0; } diff --git a/units/CMakeLists.txt b/units/CMakeLists.txt index 90450d42..fa8948dd 100644 --- a/units/CMakeLists.txt +++ b/units/CMakeLists.txt @@ -10,7 +10,7 @@ set(units_header_files units.hpp units_decl.hpp unit_definitions.hpp units_util. include(GenerateExportHeader) -if(UNITS_BUILD_SHARED_LIBRARY OR BUILD_SHARED_LIBS) +if(UNITS_BUILD_SHARED_LIBRARY ) add_library(units SHARED ${units_source_files} ${units_header_files}) generate_export_header(units BASE_NAME units) target_compile_definitions(units PUBLIC UNITS_EXPORT_HEADER) @@ -38,30 +38,10 @@ if(UNITS_BUILD_SHARED_LIBRARY OR BUILD_SHARED_LIBS) ) endif() add_library(units::units ALIAS units) -elseif(UNITS_HEADER_ONLY) - add_library(header_only INTERFACE) - target_include_directories( - header_only INTERFACE $ - $ - ) - target_compile_definitions(header_only INTERFACE UNITS_HEADER_ONLY) - if(UNITS_INSTALL) - install(TARGETS header_only ${UNITS_LIBRARY_EXPORT_COMMAND}) - endif() - if(UNITS_NAMESPACE) - target_compile_definitions( - header_only INTERFACE -DUNITS_NAMESPACE=${UNITS_NAMESPACE} - ) - endif() - if(UNITS_BASE_TYPE) - target_compile_definitions( - header_only INTERFACE -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE} - ) - endif() - add_library(units::header_only ALIAS header_only) + elseif(UNITS_BUILD_OBJECT_LIBRARY) add_library(units OBJECT ${units_source_files} ${units_header_files}) - target_include_directories(units PRIVATE $) + target_include_directories(units PRIVATE $) if(UNITS_NAMESPACE) target_compile_definitions(units PUBLIC -DUNITS_NAMESPACE=${UNITS_NAMESPACE}) @@ -72,7 +52,7 @@ elseif(UNITS_BUILD_OBJECT_LIBRARY) ) endif() endif() -else() +elseif (UNITS_BUILD_STATIC_LIBRARY) add_library(units STATIC ${units_source_files} ${units_header_files}) target_include_directories( units @@ -93,11 +73,11 @@ else() if(UNITS_BASE_TYPE) target_compile_definitions(units PUBLIC -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE}) endif() - if(UNITS_INSTALL) + if(UNITS_INSTALL AND NOT UNITS_BINARY_ONLY_INSTALL) install(TARGETS units ${UNITS_LIBRARY_EXPORT_COMMAND} - DESTINATION ${CMAKE_INSTALL_LIBDIR} # INCLUDES DESTINATION include/units + DESTINATION ${CMAKE_INSTALL_LIBDIR} # INCLUDES DESTINATION include/${PROJECT_NAME} ) - endif(UNITS_INSTALL) + endif() if(CMAKE_BUILD_TYPE STREQUAL Coverage) set_source_files_properties(foo.cpp PROPERTIES COMPILE_FLAGS -Wno-effc++) endif() @@ -107,6 +87,28 @@ else() add_library(units::units ALIAS units) endif() +## add the header only interface library +add_library(header_only INTERFACE) + target_include_directories( + header_only INTERFACE $ + $ + ) + target_compile_definitions(header_only INTERFACE UNITS_HEADER_ONLY) + if(UNITS_INSTALL AND NOT UNITS_BINARY_ONLY_INSTALL) + install(TARGETS header_only ${UNITS_LIBRARY_EXPORT_COMMAND}) + endif() + if(UNITS_NAMESPACE) + target_compile_definitions( + header_only INTERFACE -DUNITS_NAMESPACE=${UNITS_NAMESPACE} + ) + endif() + if(UNITS_BASE_TYPE) + target_compile_definitions( + header_only INTERFACE -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE} + ) + endif() + add_library(units::header_only ALIAS header_only) + if(UNITS_INSTALL AND NOT UNITS_BINARY_ONLY_INSTALL) install(FILES ${units_header_files} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/units) if(UNITS_BUILD_SHARED_LIBRARY OR BUILD_SHARED_LIBS) diff --git a/webserver/CMakeLists.txt b/webserver/CMakeLists.txt index 3226d9f7..33457fca 100644 --- a/webserver/CMakeLists.txt +++ b/webserver/CMakeLists.txt @@ -36,7 +36,7 @@ if(CMAKE_VERSION VERSION_GREATER 3.12) if (UNITS_INSTALL) install(TARGETS units_webserver - EXPORT unitsTargets + ${UNITS_LIBRARY_EXPORT_COMMAND} RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT units_webserver) endif() add_executable(units::units_webserver ALIAS units_webserver) From 5a8e11d9fe1a119bc25708c4f9d34f0af5c9428e Mon Sep 17 00:00:00 2001 From: Philip Top Date: Fri, 13 Aug 2021 12:44:35 -0700 Subject: [PATCH 13/20] update header_only test case --- test/pkg_test_code/header_only.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/pkg_test_code/header_only.cpp b/test/pkg_test_code/header_only.cpp index 05339639..20587f57 100644 --- a/test/pkg_test_code/header_only.cpp +++ b/test/pkg_test_code/header_only.cpp @@ -11,11 +11,12 @@ All rights reserved. SPDX-License-Identifier: BSD-3-Clause int main() { - units::measurement b(50.0, units::m); - units::measurement c(25.0, units::f); + using namespace units; + units::measurement b(50.0, m); + units::measurement c(25.0, ft); auto k = b * c; - if (k.units() == units::units(m.pow(2))) { + if (k.units().has_same_base(m.pow(2))) { std::cout << "PASS\n"; } else { std::cout << "FAILE\n"; From 20ddee8319bd8b217b7abd2565d41234502993c5 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Fri, 13 Aug 2021 14:10:16 -0700 Subject: [PATCH 14/20] update some more docs --- README.md | 4 ++-- converter/CMakeLists.txt | 2 +- docs/installation/cmake_variables.rst | 9 +++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5e797ff6..6b4c88e9 100644 --- a/README.md +++ b/README.md @@ -172,7 +172,7 @@ There are two parts of the library a header only portion that can simply be copi The second part is a few cpp files that can add some additional functionality. The primary additions from the cpp file are an ability to take roots of units and measurements and convert to and from strings. These files can be built as a standalone static library or included in the source code of whatever project want to use them. The code should build with an C++11 compiler. Most of the library is tagged with constexpr so can be run at compile time to link units that are known at compile time. Unit numerical conversions are not at compile time, so will have a run-time cost. A `quick_convert` function is available to do simple conversions. with a requirement that the units have the same base and not be an equation unit. The cpp code also includes some functions for commodities and will eventually have r20 and x12 conversions, though this is not complete yet. -It builds by default with the static library. Using `UNIT_BUILD_SHARED_LIBRARY` or `BUILD_SHARED_LIBS` will build the shared library instead. Either one can be used with CMake as units::units. The header only library target can also be generate `units::header_only` +It builds by default with the static library. Using `UNIT_BUILD_SHARED_LIBRARY` or `BUILD_SHARED_LIBS` will build the shared library instead. Either one can be used with CMake as units::units. The header only library target is also generated `units::header_only`. The shared/static library has a CMake target `units::units`. ## Try it out @@ -192,7 +192,7 @@ A [converter](https://units.readthedocs.io/en/latest/introduction/converter.html Many units are defined as `constexpr` objects and can be used directly ```cpp -#include "units.hpp" +#include "units/units.hpp" using namespace units measurement length1=45.0*m; diff --git a/converter/CMakeLists.txt b/converter/CMakeLists.txt index 93a90a43..1b05473d 100644 --- a/converter/CMakeLists.txt +++ b/converter/CMakeLists.txt @@ -21,7 +21,7 @@ if(UNITS_BUILD_CONVERTER_APP) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 8 ) - target_link_libraries(unit_sconvert PRIVATE -lstdc++fs) + target_link_libraries(units_convert PRIVATE -lstdc++fs) endif() endif() diff --git a/docs/installation/cmake_variables.rst b/docs/installation/cmake_variables.rst index d0084eab..4449dd77 100644 --- a/docs/installation/cmake_variables.rst +++ b/docs/installation/cmake_variables.rst @@ -23,13 +23,14 @@ CMake variables This increases the size of a unit by 4 Byte. - `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`. +- `UNITS_INSTALL`: This is set to `ON` normally but defaults to `OFF` if used as a subproejct. This controls whether anything gets installed by the install target. If compiling as part of a subproject then a few other options are useful -- `UNITS_HEADER_ONLY`: Only generate the header only target +- `UNITS_HEADER_ONLY`: Only generate the header only target, sets `UNITS_BUILD_STATIC_LIBRARY` and `UNITS_BUILD_SHARED_LIBRARY` to OFF - `UNITS_INSTALL`: enable the install instructions of the library -- `UNITS_WITH_CMAKE_PACKAGE`: Generate the CMake package variables for an installation or package -- `UNITS_BUILD_OBJECT_LIBRARY`: Generate an object library that can be used as part of other builds +- `UNITS_BUILD_OBJECT_LIBRARY`: Generate an object library that can be used as part of other builds. Only one of `UNITS_BUILD_SHARED_LIBRARY`, `UNITS_BUILD_STATIC_LIBRARY`, or `UNITS_BUILD_OBJECT_LIBRARY` can be set to `ON`. If more than one are set, the shared library and object library settings take precedence over the static library. +- `UNITS_LIBRARY_EXPORT_COMMAND`: If desired the targets for the units library can be merged into an root project target list by modifying this variable. The use cases for this are rare, but if this is something you want to do this variable should be set to something like `EXPORT rootProjectTargets` CMake Targets -------------- @@ -37,7 +38,7 @@ CMake Targets If you are using the library as a submodule or importing the package there are a couple targets that can be used depending on the build - `units::units` will be set to the library being built, either the shared, static, or object -- `units::header_only` is a target if `UNITS_HEADER_ONLY` CMake variable is set +- `units::header_only` is a target for the headers if `UNITS_HEADER_ONLY` CMake variable is set, then only this target is generated. This target is always created. Example From d019ed32e3e0226c020966f5311f6baf1896f9e1 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Fri, 13 Aug 2021 14:19:05 -0700 Subject: [PATCH 15/20] fix issue with the install location for built executables --- converter/CMakeLists.txt | 2 +- webserver/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/converter/CMakeLists.txt b/converter/CMakeLists.txt index 1b05473d..7ed99e55 100644 --- a/converter/CMakeLists.txt +++ b/converter/CMakeLists.txt @@ -28,7 +28,7 @@ if(UNITS_BUILD_CONVERTER_APP) if (UNITS_INSTALL) install(TARGETS units_convert ${UNITS_LIBRARY_EXPORT_COMMAND} - RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT units_convert) + DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT units_convert) endif() add_executable(units::units_convert ALIAS units_convert) endif() diff --git a/webserver/CMakeLists.txt b/webserver/CMakeLists.txt index 33457fca..98e60813 100644 --- a/webserver/CMakeLists.txt +++ b/webserver/CMakeLists.txt @@ -37,7 +37,7 @@ if(CMAKE_VERSION VERSION_GREATER 3.12) if (UNITS_INSTALL) install(TARGETS units_webserver ${UNITS_LIBRARY_EXPORT_COMMAND} - RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT units_webserver) + DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT units_webserver) endif() add_executable(units::units_webserver ALIAS units_webserver) endif() From 676d09f21a819498dd850da310fde8ca86b51352 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 13 Aug 2021 14:32:22 -0700 Subject: [PATCH 16/20] Automated formatting of repo files (#157) Co-authored-by: Philip Top Co-authored-by: HELICS-bot --- .circleci/config.yml | 2 +- CMakeLists.txt | 55 ++++++++----- README.md | 6 +- converter/CMakeLists.txt | 16 ++-- test/CMakeLists.txt | 110 +++++++++++++------------ test/find_package_tests/CMakeLists.txt | 16 ++-- units/CMakeLists.txt | 47 +++++------ webserver/CMakeLists.txt | 12 +-- 8 files changed, 139 insertions(+), 125 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6b36c4a2..0201fed5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,7 +8,7 @@ aliases: cd build eval cmake .. ${CMAKE_FLAGS} make -j 4 - + - &run_units name: run_units environment: diff --git a/CMakeLists.txt b/CMakeLists.txt index 0bc08a44..2d0fa7f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,11 +84,8 @@ set(UNITS_NAMESPACE ) cmake_dependent_option( - UNITS_INSTALL - "Generate and install cmake package files" - ON - "CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME;NOT UNITS_BINARY_ONLY_INSTALL" - OFF + UNITS_INSTALL "Generate and install cmake package files" ON + "CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME;NOT UNITS_BINARY_ONLY_INSTALL" OFF ) mark_as_advanced(UNITS_INSTALL) @@ -110,7 +107,6 @@ set(UNITS_CLANG_TIDY_OPTIONS mark_as_advanced(UNITS_CLANG_TIDY_OPTIONS) mark_as_advanced(UNITS_CLANG_TIDY) - set(UNITS_LIBRARY_EXPORT_COMMAND EXPORT unitsTargets) mark_as_advanced(UNITS_LIBRARY_EXPORT_COMMAND) @@ -155,12 +151,12 @@ if(NOT UNITS_HEADER_ONLY) OFF "NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME" OFF ) else() - option(UNITS_BUILD_STATIC_LIBRARY - "enable Construction of the units static library" OFF - ) - option(UNITS_BUILD_SHARED_LIBRARY - "enable Construction of the units shared library" OFF - ) + option(UNITS_BUILD_STATIC_LIBRARY "enable Construction of the units static library" + OFF + ) + option(UNITS_BUILD_SHARED_LIBRARY "enable Construction of the units shared library" + OFF + ) endif(NOT UNITS_HEADER_ONLY) # Prepare Clang-Tidy @@ -194,14 +190,29 @@ if(UNITS_INSTALL) install(TARGETS compile_flags_target ${UNITS_LIBRARY_EXPORT_COMMAND}) endif() if(NOT UNITS_BINARY_ONLY_INSTALL) - configure_file(config/unitsConfig.cmake.in - "${PROJECT_BINARY_DIR}/unitsConfig.cmake" @ONLY) - - export(EXPORT unitsTargets NAMESPACE units:: FILE ${PROJECT_BINARY_DIR}/unitsTargets.cmake) - - install(EXPORT unitsTargets NAMESPACE units:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/units) - - write_basic_package_version_file(${PROJECT_BINARY_DIR}/unitsConfigVersion.cmake COMPATIBILITY AnyNewerVersion) - install(FILES ${PROJECT_BINARY_DIR}/unitsConfigVersion.cmake ${PROJECT_BINARY_DIR}/unitsConfig.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/units) + configure_file( + config/unitsConfig.cmake.in "${PROJECT_BINARY_DIR}/unitsConfig.cmake" @ONLY + ) + + export( + EXPORT unitsTargets + NAMESPACE units:: + FILE ${PROJECT_BINARY_DIR}/unitsTargets.cmake + ) + + install( + EXPORT unitsTargets + NAMESPACE units:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/units + ) + + write_basic_package_version_file( + ${PROJECT_BINARY_DIR}/unitsConfigVersion.cmake + COMPATIBILITY AnyNewerVersion + ) + install(FILES ${PROJECT_BINARY_DIR}/unitsConfigVersion.cmake + ${PROJECT_BINARY_DIR}/unitsConfig.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/units + ) endif() -endif() \ No newline at end of file +endif() diff --git a/README.md b/README.md index 6b4c88e9..42e3b440 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ if (!meas.units().is_convertible(out) ## Limitations -- The powers represented by units by default are limited see [Unit representation](#unit_representation) and only normal physical units or common operations are supported, this can be modified at compile time to support a much broader range at the expense of size and computation. +- The powers represented by units by default are limited see [Unit representation](#unit_representation) and only normal physical units or common operations are supported, this can be modified at compile time to support a much broader range at the expense of size and computation. - The library uses floating point and double precision for the multipliers which is generally good enough for most engineering contexts, but does come with the limits and associated loss of precision for long series of calculations on floating point numbers. - Currency is supported as a unit but it is not recommended to use this for anything beyond basic financial calculations. So if you are doing a lot of financial calculations or accounting use something more specific for currency manipulations. - Fractional unit powers are not supported in general. While some mathematical operations on units are supported any root operations `sqrt` or `cbrt` will only produce valid results if the result is integral powers of the base units. One exception is limited support for √Hz operations in measurements of Amplitude spectral density. A specific definition of a unit representing square root of Hz is available and will work in combination with other units. @@ -143,7 +143,7 @@ The seven [SI units](https://www.nist.gov/pml/weights-and-measures/metric-si/si- These ranges were chosen to represent nearly all physical quantities that could be found in various disciplines we have encountered. -The CMake variable `UNITS_BASE_TYPE` if set to a 64 bit type like `uint64_t` will double the space requirements but also change the ranges to be at least a power of 4 larger than the above table. See [Cmake Reference](https://units.readthedocs.io/en/latest/installation/cmake_variables.html) for more details. +The CMake variable `UNITS_BASE_TYPE` if set to a 64 bit type like `uint64_t` will double the space requirements but also change the ranges to be at least a power of 4 larger than the above table. See [Cmake Reference](https://units.readthedocs.io/en/latest/installation/cmake_variables.html) for more details. ### Discussion points @@ -172,7 +172,7 @@ There are two parts of the library a header only portion that can simply be copi The second part is a few cpp files that can add some additional functionality. The primary additions from the cpp file are an ability to take roots of units and measurements and convert to and from strings. These files can be built as a standalone static library or included in the source code of whatever project want to use them. The code should build with an C++11 compiler. Most of the library is tagged with constexpr so can be run at compile time to link units that are known at compile time. Unit numerical conversions are not at compile time, so will have a run-time cost. A `quick_convert` function is available to do simple conversions. with a requirement that the units have the same base and not be an equation unit. The cpp code also includes some functions for commodities and will eventually have r20 and x12 conversions, though this is not complete yet. -It builds by default with the static library. Using `UNIT_BUILD_SHARED_LIBRARY` or `BUILD_SHARED_LIBS` will build the shared library instead. Either one can be used with CMake as units::units. The header only library target is also generated `units::header_only`. The shared/static library has a CMake target `units::units`. +It builds by default with the static library. Using `UNIT_BUILD_SHARED_LIBRARY` or `BUILD_SHARED_LIBS` will build the shared library instead. Either one can be used with CMake as units::units. The header only library target is also generated `units::header_only`. The shared/static library has a CMake target `units::units`. ## Try it out diff --git a/converter/CMakeLists.txt b/converter/CMakeLists.txt index 7ed99e55..d7908eb3 100644 --- a/converter/CMakeLists.txt +++ b/converter/CMakeLists.txt @@ -24,11 +24,13 @@ if(UNITS_BUILD_CONVERTER_APP) target_link_libraries(units_convert PRIVATE -lstdc++fs) endif() endif() - - if (UNITS_INSTALL) - install(TARGETS units_convert - ${UNITS_LIBRARY_EXPORT_COMMAND} - DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT units_convert) - endif() - add_executable(units::units_convert ALIAS units_convert) + + if(UNITS_INSTALL) + install( + TARGETS units_convert ${UNITS_LIBRARY_EXPORT_COMMAND} + DESTINATION "${CMAKE_INSTALL_BINDIR}" + COMPONENT units_convert + ) + endif() + add_executable(units::units_convert ALIAS units_convert) endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1a470229..b212589f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -132,62 +132,66 @@ else() ) endif() - if(UNITS_INSTALL_PACKAGE_TESTS) - set(UNITS_PACKAGE_SEARCH_LOC) - + set(UNITS_PACKAGE_SEARCH_LOC) + + if(NOT MSVC) + set(package_test_command --test-command "${CMAKE_CTEST_COMMAND}") + else() # don't try to run the tests on MSVC since that would require copying the + # dll's and doing some other setup that isn't that important to run on + # all OS + set(package_test_command) + endif() -if(NOT MSVC) - set(package_test_command --test-command "${CMAKE_CTEST_COMMAND}") -else() # don't try to run the tests on MSVC since that would require copying the dll's and doing - # some other setup that isn't that important to run on all OS - set(package_test_command) -endif() + if(CMAKE_BUILD_TYPE) + set(UNITS_PACKAGE_TEST_BUILD_TYPE ${CMAKE_BUILD_TYPE}) + else() + set(UNITS_PACKAGE_TEST_BUILD_TYPE Release) + endif() -if(CMAKE_BUILD_TYPE) - set(UNITS_PACKAGE_TEST_BUILD_TYPE ${CMAKE_BUILD_TYPE}) -else() - set(UNITS_PACKAGE_TEST_BUILD_TYPE Release) -endif() - -file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/find_package_tests") - -if(MSVC AND ${CMAKE_VERSION} VERSION_GREATER 3.12.9) - # Tests for other CMake projects including and using UNITS using find_package - add_test( - NAME find-package-testsA - COMMAND - ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" -A "${CMAKE_GENERATOR_PLATFORM}" - ${UNITS_PACKAGE_SEARCH_LOC} - "-DUNITS_BUILD_SHARED_LIBRARY=${UNITS_BUILD_SHARED_LIBRARY}" - "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" - "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}" - "-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" - "${CMAKE_CURRENT_SOURCE_DIR}/find_package_tests" - WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/find_package_tests" - ) -else() - add_test( - NAME find-package-testsA - COMMAND - ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" ${UNITS_PACKAGE_SEARCH_LOC} - "-DUNITS_BUILD_SHARED_LIBRARY=${UNITS_BUILD_SHARED_LIBRARY}" - "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" - "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}" - "-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" - "${CMAKE_CURRENT_SOURCE_DIR}/find_package_tests" - WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/find_package_tests" - ) -endif() + file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/find_package_tests") + + if(MSVC AND ${CMAKE_VERSION} VERSION_GREATER 3.12.9) + # Tests for other CMake projects including and using UNITS using + # find_package + add_test( + NAME find-package-testsA + COMMAND + ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" -A + "${CMAKE_GENERATOR_PLATFORM}" ${UNITS_PACKAGE_SEARCH_LOC} + "-DUNITS_BUILD_SHARED_LIBRARY=${UNITS_BUILD_SHARED_LIBRARY}" + "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" + "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}" + "-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" + "${CMAKE_CURRENT_SOURCE_DIR}/find_package_tests" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/find_package_tests" + ) + else() + add_test( + NAME find-package-testsA + COMMAND + ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" ${UNITS_PACKAGE_SEARCH_LOC} + "-DUNITS_BUILD_SHARED_LIBRARY=${UNITS_BUILD_SHARED_LIBRARY}" + "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" + "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}" + "-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" + "${CMAKE_CURRENT_SOURCE_DIR}/find_package_tests" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/find_package_tests" + ) + endif() -add_test(NAME find-package-testsB - COMMAND ${CMAKE_COMMAND} --build "${CMAKE_CURRENT_BINARY_DIR}/find_package_tests" --config - ${UNITS_PACKAGE_TEST_BUILD_TYPE} -) + add_test( + NAME find-package-testsB + COMMAND + ${CMAKE_COMMAND} --build + "${CMAKE_CURRENT_BINARY_DIR}/find_package_tests" --config + ${UNITS_PACKAGE_TEST_BUILD_TYPE} + ) -add_test(NAME find-package-testsC COMMAND ${CMAKE_CTEST_COMMAND} -C - ${UNITS_PACKAGE_TEST_BUILD_TYPE} - WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/find_package_tests" -) - endif() #UNITS_INSTALL_PACKAGE_TESTS + add_test( + NAME find-package-testsC + COMMAND ${CMAKE_CTEST_COMMAND} -C ${UNITS_PACKAGE_TEST_BUILD_TYPE} + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/find_package_tests" + ) + endif() # UNITS_INSTALL_PACKAGE_TESTS endif() # UNITS_HEADER_ONLY diff --git a/test/find_package_tests/CMakeLists.txt b/test/find_package_tests/CMakeLists.txt index 8a5db0b9..72bf9cb3 100644 --- a/test/find_package_tests/CMakeLists.txt +++ b/test/find_package_tests/CMakeLists.txt @@ -25,18 +25,12 @@ if(UNITS_BUILD_SHARED_LIBRARY) target_link_libraries(shared-library-test-exe units::units) add_test(NAME shared-library-test COMMAND shared-library-test-exe) - set_property( - TEST shared-library-test PROPERTY PASS_REGULAR_EXPRESSION "10.7" - ) + set_property(TEST shared-library-test PROPERTY PASS_REGULAR_EXPRESSION "10.7") - endif() # Test the header only targets - add_executable(header_only-exe ../pkg_test_code/header_only.cpp) - target_link_libraries(header_only-exe units::header_only) - - add_test(NAME header_only-exe COMMAND header_only-exe) - set_property( - TEST header_only-exe PROPERTY PASS_REGULAR_EXPRESSION "PASS" - ) +add_executable(header_only-exe ../pkg_test_code/header_only.cpp) +target_link_libraries(header_only-exe units::header_only) +add_test(NAME header_only-exe COMMAND header_only-exe) +set_property(TEST header_only-exe PROPERTY PASS_REGULAR_EXPRESSION "PASS") diff --git a/units/CMakeLists.txt b/units/CMakeLists.txt index fa8948dd..adb313b1 100644 --- a/units/CMakeLists.txt +++ b/units/CMakeLists.txt @@ -10,7 +10,7 @@ set(units_header_files units.hpp units_decl.hpp unit_definitions.hpp units_util. include(GenerateExportHeader) -if(UNITS_BUILD_SHARED_LIBRARY ) +if(UNITS_BUILD_SHARED_LIBRARY) add_library(units SHARED ${units_source_files} ${units_header_files}) generate_export_header(units BASE_NAME units) target_compile_definitions(units PUBLIC UNITS_EXPORT_HEADER) @@ -38,7 +38,7 @@ if(UNITS_BUILD_SHARED_LIBRARY ) ) endif() add_library(units::units ALIAS units) - + elseif(UNITS_BUILD_OBJECT_LIBRARY) add_library(units OBJECT ${units_source_files} ${units_header_files}) target_include_directories(units PRIVATE $) @@ -52,7 +52,7 @@ elseif(UNITS_BUILD_OBJECT_LIBRARY) ) endif() endif() -elseif (UNITS_BUILD_STATIC_LIBRARY) +elseif(UNITS_BUILD_STATIC_LIBRARY) add_library(units STATIC ${units_source_files} ${units_header_files}) target_include_directories( units @@ -75,7 +75,8 @@ elseif (UNITS_BUILD_STATIC_LIBRARY) endif() if(UNITS_INSTALL AND NOT UNITS_BINARY_ONLY_INSTALL) install(TARGETS units ${UNITS_LIBRARY_EXPORT_COMMAND} - DESTINATION ${CMAKE_INSTALL_LIBDIR} # INCLUDES DESTINATION include/${PROJECT_NAME} + DESTINATION ${CMAKE_INSTALL_LIBDIR} # INCLUDES DESTINATION + # include/${PROJECT_NAME} ) endif() if(CMAKE_BUILD_TYPE STREQUAL Coverage) @@ -87,27 +88,27 @@ elseif (UNITS_BUILD_STATIC_LIBRARY) add_library(units::units ALIAS units) endif() -## add the header only interface library +# add the header only interface library add_library(header_only INTERFACE) - target_include_directories( - header_only INTERFACE $ - $ +target_include_directories( + header_only INTERFACE $ + $ +) +target_compile_definitions(header_only INTERFACE UNITS_HEADER_ONLY) +if(UNITS_INSTALL AND NOT UNITS_BINARY_ONLY_INSTALL) + install(TARGETS header_only ${UNITS_LIBRARY_EXPORT_COMMAND}) +endif() +if(UNITS_NAMESPACE) + target_compile_definitions( + header_only INTERFACE -DUNITS_NAMESPACE=${UNITS_NAMESPACE} ) - target_compile_definitions(header_only INTERFACE UNITS_HEADER_ONLY) - if(UNITS_INSTALL AND NOT UNITS_BINARY_ONLY_INSTALL) - install(TARGETS header_only ${UNITS_LIBRARY_EXPORT_COMMAND}) - endif() - if(UNITS_NAMESPACE) - target_compile_definitions( - header_only INTERFACE -DUNITS_NAMESPACE=${UNITS_NAMESPACE} - ) - endif() - if(UNITS_BASE_TYPE) - target_compile_definitions( - header_only INTERFACE -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE} - ) - endif() - add_library(units::header_only ALIAS header_only) +endif() +if(UNITS_BASE_TYPE) + target_compile_definitions( + header_only INTERFACE -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE} + ) +endif() +add_library(units::header_only ALIAS header_only) if(UNITS_INSTALL AND NOT UNITS_BINARY_ONLY_INSTALL) install(FILES ${units_header_files} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/units) diff --git a/webserver/CMakeLists.txt b/webserver/CMakeLists.txt index 98e60813..65bedc2d 100644 --- a/webserver/CMakeLists.txt +++ b/webserver/CMakeLists.txt @@ -33,11 +33,13 @@ if(CMAKE_VERSION VERSION_GREATER 3.12) find_package(Threads REQUIRED) target_link_libraries(units_webserver PUBLIC Threads::Threads) endif() - - if (UNITS_INSTALL) - install(TARGETS units_webserver - ${UNITS_LIBRARY_EXPORT_COMMAND} - DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT units_webserver) + + if(UNITS_INSTALL) + install( + TARGETS units_webserver ${UNITS_LIBRARY_EXPORT_COMMAND} + DESTINATION "${CMAKE_INSTALL_BINDIR}" + COMPONENT units_webserver + ) endif() add_executable(units::units_webserver ALIAS units_webserver) endif() From 4fd73d2170524cedf48ffdd422d44295a25e7e55 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Fri, 13 Aug 2021 16:31:04 -0700 Subject: [PATCH 17/20] add missing includes --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0bc08a44..b78ad9ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -194,7 +194,8 @@ if(UNITS_INSTALL) install(TARGETS compile_flags_target ${UNITS_LIBRARY_EXPORT_COMMAND}) endif() if(NOT UNITS_BINARY_ONLY_INSTALL) - configure_file(config/unitsConfig.cmake.in + include(CMakePackageConfigHelpers) + configure_file(config/unitsConfig.cmake.in "${PROJECT_BINARY_DIR}/unitsConfig.cmake" @ONLY) export(EXPORT unitsTargets NAMESPACE units:: FILE ${PROJECT_BINARY_DIR}/unitsTargets.cmake) From 487cd04c7d85c53a2fd5a9d653b42a958e27b8eb Mon Sep 17 00:00:00 2001 From: Philip Top Date: Fri, 13 Aug 2021 17:21:37 -0700 Subject: [PATCH 18/20] update include paths and remove some warnings on MSVC --- test/CMakeLists.txt | 16 ++++++++++++++-- units/CMakeLists.txt | 1 + units/units_decl.hpp | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b212589f..14f9cd1e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -26,16 +26,20 @@ set(UNITS_TESTS 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 it if(UNITS_HEADER_ONLY) foreach(T ${UNIT_TEST_HEADER_ONLY}) add_unit_test(${T}.cpp) target_link_libraries(${T} units::header_only compile_flags_target) + if (MSVC) + target_compile_options(${T} PRIVATE /wd4459) + endif() endforeach() if(MSVC) - target_compile_options(test_unit_ops PRIVATE /wd4127) + target_compile_options(test_unit_ops PRIVATE /wd4127 /wd4459) endif() else() foreach(T ${UNITS_TESTS}) @@ -45,6 +49,9 @@ else() if(UNITS_CLANG_TIDY) set_property(TARGET ${T} PROPERTY CXX_CLANG_TIDY "${DO_CLANG_TIDY}") endif() + if (MSVC) + target_compile_options(${T} PRIVATE /wd4459) + endif() endforeach() target_compile_definitions( @@ -62,6 +69,9 @@ else() set_property(TARGET ${T} PROPERTY CXX_CLANG_TIDY "${DO_CLANG_TIDY}") endif() target_compile_definitions(test_leadingNumbers PUBLIC -DENABLE_UNIT_TESTING=1) + if (MSVC) + target_compile_options(test_leadingNumbers PRIVATE /wd4459) + endif() endif() target_compile_definitions( @@ -112,7 +122,9 @@ else() add_test(examples_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples_test) add_executable(test_all_unit_base test_all_unit_base.cpp) - + if (MSVC) + target_compile_options(test_all_unit_base PRIVATE /wd4459) + endif() target_link_libraries( test_all_unit_base gtest gmock gtest_main units::units compile_flags_target ) diff --git a/units/CMakeLists.txt b/units/CMakeLists.txt index adb313b1..06e24e68 100644 --- a/units/CMakeLists.txt +++ b/units/CMakeLists.txt @@ -17,6 +17,7 @@ if(UNITS_BUILD_SHARED_LIBRARY) target_include_directories( units PUBLIC $ + $ $ $ ) diff --git a/units/units_decl.hpp b/units/units_decl.hpp index ac014936..83f5bb3e 100644 --- a/units/units_decl.hpp +++ b/units/units_decl.hpp @@ -7,7 +7,7 @@ SPDX-License-Identifier: BSD-3-Clause #pragma once #ifdef UNITS_EXPORT_HEADER -#include "units/units_export.h" +#include "units_export.h" #else #define UNITS_EXPORT #endif From f28293d037c280c6e3ac04ddf249132fabaad19e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 13 Aug 2021 17:27:25 -0700 Subject: [PATCH 19/20] Automated formatting of repo files (#158) Co-authored-by: Philip Top Co-authored-by: HELICS-bot --- CMakeLists.txt | 27 ++++++++++++++++++--------- test/CMakeLists.txt | 15 ++++++++------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b3f3dcab..be98a49c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -155,19 +155,28 @@ else() ) endif(NOT UNITS_HEADER_ONLY) -if (UNITS_BUILD_SHARED_LIBRARY AND UNITS_BUILD_STATIC_LIBRARY) - message(WARNING "Both UNITS_BUILD_SHARED_LIBRARY and UNITS_BUILD_STATIC_LIBRARY are set to ON, only the shared library will be built") +if(UNITS_BUILD_SHARED_LIBRARY AND UNITS_BUILD_STATIC_LIBRARY) + message( + WARNING + "Both UNITS_BUILD_SHARED_LIBRARY and UNITS_BUILD_STATIC_LIBRARY are set to ON, only the shared library will be built" + ) endif() cmake_dependent_option( - UNITS_BUILD_OBJECT_LIBRARY "Enable construction of the units object library" - OFF "NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME" OFF - ) + UNITS_BUILD_OBJECT_LIBRARY "Enable construction of the units object library" OFF + "NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME" OFF +) -if (UNITS_BUILD_SHARED_LIBRARY AND UNITS_BUILD_OBJECT_LIBRARY) - message(WARNING "Both UNITS_BUILD_SHARED_LIBRARY and UNITS_BUILD_OBJECT_LIBRARY are set to ON, only the shared library will be built") -elseif (UNITS_BUILD_STATIC_LIBRARY AND UNITS_BUILD_OBJECT_LIBRARY) - message(WARNING "Both UNITS_BUILD_STATIC_LIBRARY and UNITS_BUILD_OBJECT_LIBRARY are set to ON, only the object library will be built") +if(UNITS_BUILD_SHARED_LIBRARY AND UNITS_BUILD_OBJECT_LIBRARY) + message( + WARNING + "Both UNITS_BUILD_SHARED_LIBRARY and UNITS_BUILD_OBJECT_LIBRARY are set to ON, only the shared library will be built" + ) +elseif(UNITS_BUILD_STATIC_LIBRARY AND UNITS_BUILD_OBJECT_LIBRARY) + message( + WARNING + "Both UNITS_BUILD_STATIC_LIBRARY and UNITS_BUILD_OBJECT_LIBRARY are set to ON, only the object library will be built" + ) endif() # Prepare Clang-Tidy diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 14f9cd1e..c500d5dd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -26,14 +26,15 @@ set(UNITS_TESTS 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 it +# /wd4459 is for a warning of a global m in google test. They won't interfere so ignore +# it if(UNITS_HEADER_ONLY) foreach(T ${UNIT_TEST_HEADER_ONLY}) add_unit_test(${T}.cpp) target_link_libraries(${T} units::header_only compile_flags_target) - if (MSVC) + if(MSVC) target_compile_options(${T} PRIVATE /wd4459) endif() endforeach() @@ -49,7 +50,7 @@ else() if(UNITS_CLANG_TIDY) set_property(TARGET ${T} PROPERTY CXX_CLANG_TIDY "${DO_CLANG_TIDY}") endif() - if (MSVC) + if(MSVC) target_compile_options(${T} PRIVATE /wd4459) endif() endforeach() @@ -69,7 +70,7 @@ else() set_property(TARGET ${T} PROPERTY CXX_CLANG_TIDY "${DO_CLANG_TIDY}") endif() target_compile_definitions(test_leadingNumbers PUBLIC -DENABLE_UNIT_TESTING=1) - if (MSVC) + if(MSVC) target_compile_options(test_leadingNumbers PRIVATE /wd4459) endif() endif() @@ -122,9 +123,9 @@ else() add_test(examples_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples_test) add_executable(test_all_unit_base test_all_unit_base.cpp) - if (MSVC) - target_compile_options(test_all_unit_base PRIVATE /wd4459) - endif() + if(MSVC) + target_compile_options(test_all_unit_base PRIVATE /wd4459) + endif() target_link_libraries( test_all_unit_base gtest gmock gtest_main units::units compile_flags_target ) From 6b1d26bf9f5aafd2917989c584b0ad2ca409f7f4 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Fri, 13 Aug 2021 18:33:42 -0700 Subject: [PATCH 20/20] update cpplint to ignore more issues that are not relevent --- CPPLINT.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/CPPLINT.cfg b/CPPLINT.cfg index 34f08646..766fbc50 100644 --- a/CPPLINT.cfg +++ b/CPPLINT.cfg @@ -3,6 +3,7 @@ linelength=100 # As in .clang-format # Non-used filters filter=-build/include_order # Requires unusual include order that encourages creating not self-contained headers +filter=-build/include_subdir # this is generally good but causes some issues filter=-readability/nolint # Conflicts with clang-tidy filter=-runtime/references # Requires fundamental change of API, don't see need for this filter=-whitespace/blank_line # Unnecessarily strict with blank lines that otherwise help with readability