Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions docs/getting_started/installation_and_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,15 @@ dependencies by other means, some modifications to the library's CMake files mig

[cmake natural units]: https://github.com/mpusz/mp-units/releases/tag/v2.5.0

[`MP_UNITS_INSTALL`](#MP_UNITS_INSTALL){ #MP_UNITS_INSTALL }

: [:octicons-tag-24: 2.5.0][cmake install] · :octicons-milestone-24: `ON`/`OFF` (Default: `ON`)

Creates an installable target. Users may want to turn this off for example when consuming the
library via CMake's `add_subdirectory` or similar mechanisms.

[cmake install]: https://github.com/mpusz/mp-units/releases/tag/v2.5.0


## Installation and reuse

Expand Down Expand Up @@ -493,6 +502,34 @@ with the following differences:
[FAQ](faq.md#why-dont-we-have-cmake-options-to-disable-the-building-of-tests-and-examples).


### CPM or FetchContent (CMake)

**mp-units** can be consumed via [CPM](https://github.com/cpm-cmake/CPM.cmake) or CMake's built-in
[FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) mechanism. An example
CPM configuration is shown below.

```cmake
CPMFindPackage(
NAME mp-units
VERSION 2.4.0
GIT_TAG 6e06eddf205deaf6c2f2f63500c8c70ec220a99f
GITHUB_REPOSITORY mpusz/mp-units
SOURCE_SUBDIR src
SYSTEM YES
EXCLUDE_FROM_ALL YES
OPTIONS
"MP_UNITS_BUILD_AS_SYSTEM_HEADERS ON"
"MP_UNITS_INSTALL OFF"
)
# ...
target_link_libraries(<your_target> <PUBLIC|PRIVATE|INTERFACE> mp-units::mp-units)
```

!!! note

This is essentially a shortcut way to do what [Copy + CMake](#copy-cmake) mentions above, so the same
prerequisites apply.

### Install

If you don't want to use Conan in your project and just want to install the **mp-units**
Expand Down
24 changes: 14 additions & 10 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ check_libcxx_in_use(${projectPrefix}LIBCXX)
# project build options
option(${projectPrefix}BUILD_AS_SYSTEM_HEADERS "Export library as system headers" OFF)
option(${projectPrefix}BUILD_CXX_MODULES "Add C++ modules to the list of default targets" OFF)
option(${projectPrefix}INSTALL "Install the library" ON)

message(STATUS "${projectPrefix}BUILD_AS_SYSTEM_HEADERS: ${${projectPrefix}BUILD_AS_SYSTEM_HEADERS}")
message(STATUS "${projectPrefix}BUILD_CXX_MODULES: ${${projectPrefix}BUILD_CXX_MODULES}")
message(STATUS "${projectPrefix}INSTALL: ${${projectPrefix}INSTALL}")

if(${projectPrefix}BUILD_AS_SYSTEM_HEADERS)
set(${projectPrefix}_AS_SYSTEM SYSTEM)
Expand Down Expand Up @@ -135,15 +137,17 @@ add_subdirectory(systems)
# project-wide wrapper
add_mp_units_module(mp-units mp-units DEPENDENCIES mp-units::core mp-units::systems MODULE_INTERFACE_UNIT mp-units.cpp)

# local build
export(EXPORT mp-unitsTargets NAMESPACE mp-units::)
configure_file("mp-unitsConfig.cmake" "." COPYONLY)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(mp-unitsConfigVersion.cmake COMPATIBILITY SameMajorVersion)
if(${projectPrefix}INSTALL)
# local build
export(EXPORT mp-unitsTargets NAMESPACE mp-units::)
configure_file("mp-unitsConfig.cmake" "." COPYONLY)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(mp-unitsConfigVersion.cmake COMPATIBILITY SameMajorVersion)

# installation
install(EXPORT mp-unitsTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/mp-units NAMESPACE mp-units::)
# installation
install(EXPORT mp-unitsTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/mp-units NAMESPACE mp-units::)

install(FILES mp-unitsConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/mp-unitsConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/mp-units
)
install(FILES mp-unitsConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/mp-unitsConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/mp-units
)
endif()
Loading