Skip to content

Commit

Permalink
Automated formatting of repo files
Browse files Browse the repository at this point in the history
  • Loading branch information
HELICS-bot committed Aug 13, 2021
1 parent a862301 commit 5958ed2
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ aliases:
cd build
eval cmake .. ${CMAKE_FLAGS}
make -j 4
- &run_units
name: run_units
environment:
Expand Down
55 changes: 33 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
endif()
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions converter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
110 changes: 57 additions & 53 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 5 additions & 11 deletions test/find_package_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
47 changes: 24 additions & 23 deletions units/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 $<BUILD_INTERFACE:${units_SOURCE_DIR}>)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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 $<BUILD_INTERFACE:${units_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
target_include_directories(
header_only INTERFACE $<BUILD_INTERFACE:${units_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
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)
Expand Down
10 changes: 5 additions & 5 deletions webserver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 5958ed2

Please sign in to comment.