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 7562753d..09529307 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) @@ -188,14 +184,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 5e797ff6..6396d8dd 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 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 can also be generate `units::header_only` ## Try it out diff --git a/converter/CMakeLists.txt b/converter/CMakeLists.txt index 93a90a43..4b3029f5 100644 --- a/converter/CMakeLists.txt +++ b/converter/CMakeLists.txt @@ -24,11 +24,11 @@ if(UNITS_BUILD_CONVERTER_APP) target_link_libraries(unit_sconvert PRIVATE -lstdc++fs) endif() endif() - - if (UNITS_INSTALL) - 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) + + if(UNITS_INSTALL) + 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..0826b177 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -132,64 +132,68 @@ 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}" - "-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() + 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-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 0f2a00b3..9c1100a1 100644 --- a/test/find_package_tests/CMakeLists.txt +++ b/test/find_package_tests/CMakeLists.txt @@ -25,9 +25,7 @@ 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") # Test the C and C++98 targets elseif(UNITS_HEADER_ONLY) diff --git a/units/CMakeLists.txt b/units/CMakeLists.txt index 6208b547..795b2764 100644 --- a/units/CMakeLists.txt +++ b/units/CMakeLists.txt @@ -95,7 +95,8 @@ else() 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) diff --git a/webserver/CMakeLists.txt b/webserver/CMakeLists.txt index 33457fca..b61e2c5a 100644 --- a/webserver/CMakeLists.txt +++ b/webserver/CMakeLists.txt @@ -33,11 +33,11 @@ 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} - RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT units_webserver) + + if(UNITS_INSTALL) + install(TARGETS units_webserver ${UNITS_LIBRARY_EXPORT_COMMAND} + RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT units_webserver + ) endif() add_executable(units::units_webserver ALIAS units_webserver) endif()