build: core library and each system separated to dedicated CMake targets

Refers to #249
This commit is contained in:
Mateusz Pusz
2021-03-16 23:05:45 +01:00
parent 7ee0e3ff90
commit 221883bb25
206 changed files with 547 additions and 121 deletions

View File

@@ -21,7 +21,7 @@
# SOFTWARE.
cmake_minimum_required(VERSION 3.15)
project(mp-units
project(mp-units-dev
LANGUAGES CXX
)

View File

@@ -22,26 +22,27 @@
cmake_minimum_required(VERSION 3.2)
#
# add_example(target <depependencies>...)
#
function(add_example target)
add_executable(${target} ${target}.cpp)
target_link_libraries(${target} PRIVATE mp-units::mp-units)
target_link_libraries(${target} PRIVATE ${ARGN})
endfunction()
add_example(box_example)
add_example(capacitor_time_curve)
add_example(clcpp_response)
add_example(conversion_factor)
add_example(custom_systems)
add_example(experimental_angle)
add_example(foot_pound_second)
add_example(kalman_filter-alpha_beta_filter_example2)
add_example(measurement)
add_example(unknown_dimension)
add_example(avg_speed)
add_example(hello_units)
add_example(total_energy)
add_example(avg_speed mp-units::si mp-units::si-cgs mp-units::si-international)
add_example(box_example mp-units::si)
add_example(capacitor_time_curve mp-units::si)
add_example(clcpp_response mp-units::si mp-units::si-iau mp-units::si-imperial mp-units::si-international mp-units::si-typographic mp-units::si-us)
add_example(conversion_factor mp-units::si)
add_example(custom_systems mp-units::si)
add_example(experimental_angle mp-units::si)
add_example(foot_pound_second mp-units::si-fps)
add_example(hello_units mp-units::si mp-units::si-international)
add_example(kalman_filter-alpha_beta_filter_example2 mp-units::si)
add_example(measurement mp-units::si)
add_example(total_energy mp-units::si mp-units::isq-natural)
add_example(unknown_dimension mp-units::si)
if(NOT UNITS_LIBCXX)
add_executable(glide_computer
@@ -49,14 +50,11 @@ if(NOT UNITS_LIBCXX)
glide_computer.cpp glide_computer.h
glide_computer_example.cpp
)
target_link_libraries(glide_computer PRIVATE mp-units::mp-units)
target_link_libraries(glide_computer PRIVATE mp-units::si mp-units::si-international)
find_package(linear_algebra CONFIG REQUIRED)
add_example(linear_algebra)
target_link_libraries(linear_algebra
PRIVATE
linear_algebra::linear_algebra
)
add_example(linear_algebra mp-units::si)
target_link_libraries(linear_algebra PRIVATE linear_algebra::linear_algebra)
endif()
add_subdirectory(alternative_namespaces)

View File

@@ -27,8 +27,8 @@ function(add_example target)
target_link_libraries(${target}_alt PRIVATE mp-units::mp-units)
endfunction()
add_example(box_example)
add_example(capacitor_time_curve)
add_example(clcpp_response)
add_example(conversion_factor)
add_example(timer)
add_example(box_example mp-units::si)
add_example(capacitor_time_curve mp-units::si)
add_example(clcpp_response mp-units::si)
add_example(conversion_factor mp-units::si)
add_example(timer mp-units::si)

View File

@@ -46,7 +46,7 @@ fixed_double_si_avg_speed(si::length<si::metre> d,
template<typename U1, typename R1, typename U2, typename R2>
constexpr Speed auto si_avg_speed(si::length<U1, R1> d,
si::time<U2, R2> t)
si::time<U2, R2> t)
{
return d / t;
}

View File

@@ -21,92 +21,34 @@
# SOFTWARE.
cmake_minimum_required(VERSION 3.15)
project(mp-units
VERSION 0.7.0
LANGUAGES CXX
)
set(UNITS_DOWNCAST_MODE ON CACHE STRING "Select downcasting mode")
set_property(CACHE UNITS_DOWNCAST_MODE PROPERTY STRINGS AUTO ON OFF)
# check if libc++ is being used
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
message(CHECK_START "Checking if libc++ is being used")
list(APPEND CMAKE_MESSAGE_INDENT " ")
include(CheckSymbolExists)
check_symbol_exists(_LIBCPP_VERSION "ciso646" UNITS_LIBCXX)
list(POP_BACK CMAKE_MESSAGE_INDENT)
if(UNITS_LIBCXX)
message(CHECK_PASS "found")
else()
message(CHECK_FAIL "not found")
endif()
endif()
find_package(fmt CONFIG REQUIRED)
find_package(gsl-lite CONFIG REQUIRED)
# library definition
add_library(mp-units INTERFACE)
target_compile_features(mp-units INTERFACE cxx_std_20)
target_link_libraries(mp-units
INTERFACE
fmt::fmt
gsl::gsl-lite
)
target_include_directories(mp-units
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(UNITS_LIBCXX)
find_package(range-v3)
target_link_libraries(mp-units
INTERFACE
range-v3::range-v3
)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(mp-units
INTERFACE
-Wno-non-template-friend
)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(mp-units
INTERFACE
/utf-8 # Specifies both the source character set and the execution character set as UTF-8
)
endif()
if(DEFINED UNITS_DOWNCAST_MODE)
set(downcast_mode_options OFF ON AUTO)
list(FIND downcast_mode_options "${UNITS_DOWNCAST_MODE}" downcast_mode)
if(downcast_mode EQUAL -1)
message(FATAL_ERROR "'UNITS_DOWNCAST_MODE' should be one of ${downcast_mode_options} ('${UNITS_DOWNCAST_MODE}' received)")
else()
message(STATUS "UNITS_DOWNCAST_MODE: ${UNITS_DOWNCAST_MODE}")
target_compile_definitions(mp-units INTERFACE UNITS_DOWNCAST_MODE=${downcast_mode})
endif()
endif()
add_library(mp-units::mp-units ALIAS mp-units)
# installation info
include(CMakePackageConfigHelpers)
write_basic_package_version_file(mp-unitsConfigVersion.cmake COMPATIBILITY SameMajorVersion)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(GNUInstallDirs)
install(TARGETS mp-units EXPORT mp-unitsTargets)
add_subdirectory(core)
add_subdirectory(systems)
# project-wide wrapper
add_library(mp-units INTERFACE)
target_link_libraries(mp-units INTERFACE
mp-units::core
mp-units::systems
)
add_library(mp-units::mp-units ALIAS mp-units)
# installation
install(EXPORT mp-unitsTargets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/mp-units
NAMESPACE mp-units::
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(mp-unitsConfigVersion.cmake COMPATIBILITY SameMajorVersion)
install(FILES mp-unitsConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/mp-unitsConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/mp-units
)
install(DIRECTORY include/units TYPE INCLUDE)

40
src/cmake/AddSystem.cmake Normal file
View File

@@ -0,0 +1,40 @@
# The MIT License (MIT)
#
# Copyright (c) 2018 Mateusz Pusz
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
cmake_minimum_required(VERSION 3.15)
#
# add_system(SystemName <depependencies>...)
#
function(add_system name)
add_library(mp-units-${name} INTERFACE)
target_link_libraries(mp-units-${name} INTERFACE ${ARGN})
target_include_directories(mp-units-${name} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
set_target_properties(mp-units-${name} PROPERTIES EXPORT_NAME ${name})
add_library(mp-units::${name} ALIAS mp-units-${name})
install(TARGETS mp-units-${name} EXPORT mp-unitsTargets)
install(DIRECTORY include/units TYPE INCLUDE)
endfunction()

View File

@@ -0,0 +1,41 @@
# The MIT License (MIT)
#
# Copyright (c) 2018 Mateusz Pusz
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
cmake_minimum_required(VERSION 3.15)
function(check_libcxx_in_use variable)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
message(CHECK_START "Checking if libc++ is being used")
list(APPEND CMAKE_MESSAGE_INDENT " ")
include(CheckSymbolExists)
check_symbol_exists(_LIBCPP_VERSION "ciso646" ${variable})
set(${variable} ${${variable}} PARENT_SCOPE)
list(POP_BACK CMAKE_MESSAGE_INDENT)
if(UNITS_LIBCXX)
message(CHECK_PASS "found")
else()
message(CHECK_FAIL "not found")
endif()
endif()
endfunction()

80
src/core/CMakeLists.txt Normal file
View File

@@ -0,0 +1,80 @@
# The MIT License (MIT)
#
# Copyright (c) 2018 Mateusz Pusz
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
cmake_minimum_required(VERSION 3.15)
# core library options
set(UNITS_DOWNCAST_MODE ON CACHE STRING "Select downcasting mode")
set_property(CACHE UNITS_DOWNCAST_MODE PROPERTY STRINGS AUTO ON OFF)
# find dependencies
find_package(fmt CONFIG REQUIRED)
find_package(gsl-lite CONFIG REQUIRED)
# check if libc++ is being used
include(CheckLibcxxInUse)
check_libcxx_in_use(UNITS_LIBCXX)
# core library definition
add_library(mp-units-core INTERFACE)
target_compile_features(mp-units-core INTERFACE cxx_std_20)
target_link_libraries(mp-units-core INTERFACE
fmt::fmt
gsl::gsl-lite
)
target_include_directories(mp-units-core INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(UNITS_LIBCXX)
find_package(range-v3)
target_link_libraries(mp-units-core INTERFACE range-v3::range-v3)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(mp-units-core INTERFACE
-Wno-non-template-friend
)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(mp-units-core INTERFACE
/utf-8 # Specifies both the source character set and the execution character set as UTF-8
)
endif()
if(DEFINED UNITS_DOWNCAST_MODE)
set(downcast_mode_options OFF ON AUTO)
list(FIND downcast_mode_options "${UNITS_DOWNCAST_MODE}" downcast_mode)
if(downcast_mode EQUAL -1)
message(FATAL_ERROR "'UNITS_DOWNCAST_MODE' should be one of ${downcast_mode_options} ('${UNITS_DOWNCAST_MODE}' received)")
else()
message(STATUS "UNITS_DOWNCAST_MODE: ${UNITS_DOWNCAST_MODE}")
target_compile_definitions(mp-units-core INTERFACE UNITS_DOWNCAST_MODE=${downcast_mode})
endif()
endif()
set_target_properties(mp-units-core PROPERTIES EXPORT_NAME core)
add_library(mp-units::core ALIAS mp-units-core)
# installation
install(TARGETS mp-units-core EXPORT mp-unitsTargets)
install(DIRECTORY include/units TYPE INCLUDE)

View File

@@ -0,0 +1,55 @@
# The MIT License (MIT)
#
# Copyright (c) 2018 Mateusz Pusz
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
cmake_minimum_required(VERSION 3.15)
include(AddSystem)
# systems
add_subdirectory(data)
add_subdirectory(isq)
add_subdirectory(isq-natural)
add_subdirectory(si)
add_subdirectory(si-cgs)
add_subdirectory(si-fps)
add_subdirectory(si-iau)
add_subdirectory(si-imperial)
add_subdirectory(si-international)
add_subdirectory(si-typographic)
add_subdirectory(si-us)
# wrapper for all the systems
add_library(mp-units-systems INTERFACE)
target_link_libraries(mp-units-systems INTERFACE
mp-units::data
mp-units::isq
mp-units::isq-natural
mp-units::si
mp-units::si-cgs
mp-units::si-fps
mp-units::si-iau
mp-units::si-imperial
mp-units::si-international
mp-units::si-typographic
mp-units::si-us
)
add_library(mp-units::systems ALIAS mp-units-systems)

View File

@@ -0,0 +1,25 @@
# The MIT License (MIT)
#
# Copyright (c) 2018 Mateusz Pusz
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
cmake_minimum_required(VERSION 3.15)
add_system(data mp-units::core)

View File

@@ -0,0 +1,25 @@
# The MIT License (MIT)
#
# Copyright (c) 2018 Mateusz Pusz
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
cmake_minimum_required(VERSION 3.15)
add_system(isq-natural mp-units::isq)

View File

@@ -0,0 +1,25 @@
# The MIT License (MIT)
#
# Copyright (c) 2018 Mateusz Pusz
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
cmake_minimum_required(VERSION 3.15)
add_system(isq mp-units::core)

Some files were not shown because too many files have changed in this diff Show More