Skip to content

Commit

Permalink
Fix some cmake option Variable and add an alternative cmake configura…
Browse files Browse the repository at this point in the history
…tion (#263)

* Fix some variables in cmake Option

* Add an cmake alternative configuration

* Add metric prefixes documentation

* Add unit dependencies table

* Fix typo
  • Loading branch information
augustoicaro authored Sep 26, 2022
1 parent a686789 commit c0b56d7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ OPTION(ENABLE_PREDEFINED_ANGLE_UNITS "Enables library-defined units of ANGLE." O
OPTION(ENABLE_PREDEFINED_CURRENT_UNITS "Enables library-defined units of CURRENT." OFF)
OPTION(ENABLE_PREDEFINED_TEMPERATURE_UNITS "Enables library-defined units of TEMPERATURE." OFF)
OPTION(ENABLE_PREDEFINED_SUBSTANCE_UNITS "Enables library-defined units of SUBSTANCE." OFF)
OPTION(ENABLE_PREDEFINED_LUMINOUS_UNITS "Enables library-defined units of LUMINOUS." OFF)
OPTION(ENABLE_PREDEFINED_SOLID_UNITS "Enables library-defined units of SOLID." OFF)
OPTION(ENABLE_PREDEFINED_LUMINOUS_INTENSITY_UNITS "Enables library-defined units of LUMINOUS INTENSITY." OFF)
OPTION(ENABLE_PREDEFINED_SOLID_ANGLE_UNITS "Enables library-defined units of SOLID ANGLE." OFF)
OPTION(ENABLE_PREDEFINED_FREQUENCY_UNITS "Enables library-defined units of FREQUENCY." OFF)
OPTION(ENABLE_PREDEFINED_VELOCITY_UNITS "Enables library-defined units of VELOCITY." OFF)
OPTION(ENABLE_PREDEFINED_ANGULAR_UNITS "Enables library-defined units of ANGULAR." OFF)
OPTION(ENABLE_PREDEFINED_ANGULAR_VELOCITY_UNITS "Enables library-defined units of ANGULAR VELOCITY." OFF)
OPTION(ENABLE_PREDEFINED_ACCELERATION_UNITS "Enables library-defined units of ACCELERATION." OFF)
OPTION(ENABLE_PREDEFINED_FORCE_UNITS "Enables library-defined units of FORCE." OFF)
OPTION(ENABLE_PREDEFINED_PRESSURE_UNITS "Enables library-defined units of PRESSURE." OFF)
Expand All @@ -39,10 +39,10 @@ OPTION(ENABLE_PREDEFINED_POWER_UNITS "Enables library-defined units of POWER." O
OPTION(ENABLE_PREDEFINED_VOLTAGE_UNITS "Enables library-defined units of VOLTAGE." OFF)
OPTION(ENABLE_PREDEFINED_CAPACITANCE_UNITS "Enables library-defined units of CAPACITANCE." OFF)
OPTION(ENABLE_PREDEFINED_IMPEDANCE_UNITS "Enables library-defined units of IMPEDANCE." OFF)
OPTION(ENABLE_PREDEFINED_MAGNETIC_UNITS "Enables library-defined units of MAGNETIC." OFF)
OPTION(ENABLE_PREDEFINED_MAGNETIC_UNITS "Enables library-defined units of MAGNETIC." OFF)
OPTION(ENABLE_PREDEFINED_MAGNETIC_FLUX_UNITS "Enables library-defined units of MAGNETIC FLUX." OFF)
OPTION(ENABLE_PREDEFINED_MAGNETIC_FIELD_STRENGTH_UNITS "Enables library-defined units of MAGNETIC FIELD STRENGTH." OFF)
OPTION(ENABLE_PREDEFINED_INDUCTANCE_UNITS "Enables library-defined units of INDUCTANCE." OFF)
OPTION(ENABLE_PREDEFINED_LUMINOUS_UNITS "Enables library-defined units of LUMINOUS." OFF)
OPTION(ENABLE_PREDEFINED_LUMINOUS_FLUX_UNITS "Enables library-defined units of LUMINOUS FLUX." OFF)
OPTION(ENABLE_PREDEFINED_ILLUMINANCE_UNITS "Enables library-defined units of ILLUMINANCE." OFF)
OPTION(ENABLE_PREDEFINED_RADIATION_UNITS "Enables library-defined units of RADIATION." OFF)
OPTION(ENABLE_PREDEFINED_TORQUE_UNITS "Enables library-defined units of TORQUE." OFF)
Expand All @@ -51,7 +51,7 @@ OPTION(ENABLE_PREDEFINED_VOLUME_UNITS "Enables library-defined units of VOLUME."
OPTION(ENABLE_PREDEFINED_DENSITY_UNITS "Enables library-defined units of DENSITY." OFF)
OPTION(ENABLE_PREDEFINED_CONCENTRATION_UNITS "Enables library-defined units of CONCENTRATION." OFF)
OPTION(ENABLE_PREDEFINED_DATA_UNITS "Enables library-defined units of DATA." OFF)
OPTION(ENABLE_PREDEFINED_DATA_UNITS "Enables library-defined units of DATA." OFF)
OPTION(ENABLE_PREDEFINED_DATA_TRANSFER_RATE_UNITS "Enables library-defined units of DATA TRANSFER RATE." OFF)
OPTION(ENABLE_PREDEFINED_CONSTANTS_UNITS "Enables library-defined units of CONSTANTS." OFF)

SET(CMAKE_CXX_STANDARD 14)
Expand Down
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,25 @@ auto area = 5_m * 10_m; // with literals

All literals* are defined by their SI abbreviation preceded by an underscore, e.g. `_m` for meter. "Square" units are preceded by `_sq`, e.g. `_sq_m` for square meters. Non SI units use their most common abbreviations.

All literals can be used with a metric prefix as table shows:

| Metric Prefix | Literal | Example |
|:-------------:|:--------:|:---------:|
| femto | f | `10_fm` |
| pico | p | `10_pm` |
| nano | n | `10_nm` |
| micro | u | `10_um` |
| milli | m | `10_mm` |
| centi | c | `10_cm` |
| deci | d | `10_dm` |
| deca | da | `10_dam` |
| hecto | h | `10_hm` |
| kilo | k | `10_km` |
| mega | M | `10_Mm` |
| giga | G | `10_Gm` |
| tera | T | `10_Tm` |
| peta | P | `10_Pm` |

All literals are defined in the `units::literals` namespace, and in order to use literals in your code ***you must include the line `using units::literals`*** (since there is no way to put a namespace on an operator).

_* with the exception of `Teslas`, which use `_Te` for compatibility with MSVC compilers._
Expand Down Expand Up @@ -662,7 +681,34 @@ The generic algorithm is
1. disable the pre-defined units using `#define DISABLE_PREDEFINED_UNITS`
2. opt-in to the namespaces you want using `#define ENABLE_PREDEFINED_<namepsace name>_UNITS`

Additionally, for `CMake` users, there are equivalently-named cmake options defined which will automatically include the preprocessor definitions in your project.
Additionally, for `CMake` users, there are equivalently-named cmake options defined which will automatically include the preprocessor definitions in your project. Alternatively, you can use `add_definitions()` in your cmake file to set macros globally::

```cpp
// Only use length and time
add_definitions(
-DDISABLE_PREDEFINED_UNITS
-DENABLE_PREDEFINED_LENGTH_UNITS
-DENABLE_PREDEFINED_TIME_UNITS
)
```
Be aware, some units depend on others. See the unit dependencies table bellow:
| Unit | Dependencies |
|:-----------------------:|:--------------------------------:|
| ACCELERATION | LENGTH, TIME |
| ANGULAR_VELOCITY | ANGLE, TIME |
| AREA | LENGTH |
| DENSITY | MASS, VOLUME |
| FORCE | ACCELERATION, LENGTH, MASS, TIME |
| ILLUMINANCE | LENGTH, LUMINOUS_FLUX |
| MAGNETIC_FIELD_STRENGTH | MAGNETIC_FLUX |
| PRESSURE | FORCE, LENGTH |
| RADIATION | ENERGY, MASS |
| SOLID_ANGLE | ANGLE |
| TORQUE | FORCE, LENGTH |
| VELOCITY | LENGTH, TIME |
| VOLUME | LENGTH |
# Macro clashes
Expand Down

0 comments on commit c0b56d7

Please sign in to comment.