diff --git a/CMakeLists.txt b/CMakeLists.txt index ce7bf7c0..08831032 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ conan_init(cmake) add_subdirectory(src) # set restrictive compilation warnings -set_warnings(units) +set_warnings(mp-units) # add unit tests enable_testing() diff --git a/conanfile.py b/conanfile.py index 21241a87..a757b5dd 100644 --- a/conanfile.py +++ b/conanfile.py @@ -21,7 +21,7 @@ # SOFTWARE. from conans import ConanFile, CMake, tools -from conans.tools import Version +from conans.tools import Version, check_min_cppstd from conans.errors import ConanInvalidConfiguration import re @@ -38,17 +38,18 @@ def get_version(): class UnitsConan(ConanFile): name = "mp-units" version = get_version() - author = "Mateusz Pusz" - license = "https://github.com/mpusz/units/blob/master/LICENSE.md" - url = "https://github.com/mpusz/units" + homepage = "https://github.com/mpusz/units" description = "Physical Units library for C++" - exports = ["LICENSE.md"] - exports_sources = ["docs/*", "src/*", "test/*", "cmake/*", "example/*","CMakeLists.txt"] + topics = ("units", "dimensions", "quantities", "dimensional-analysis", "physical-quantities", "physical-units", "system-of-units", "cpp23", "cpp20", "library", "quantity-manipulation") + license = "MIT" + url = "https://github.com/mpusz/units" settings = "os", "compiler", "build_type", "arch" requires = ( "fmt/7.0.3", "ms-gsl/3.1.0" ) + exports = ["LICENSE.md"] + exports_sources = ["docs/*", "src/*", "test/*", "cmake/*", "example/*","CMakeLists.txt"] # scm = { # "type": "git", # "url": "auto", @@ -61,6 +62,19 @@ class UnitsConan(ConanFile): def _run_tests(self): return tools.get_env("CONAN_RUN_TESTS", False) + def _validate_compiler_settings(self): + compiler = self.settings.compiler + version = Version(self.settings.compiler.version) + if compiler == "gcc": + if version < "9.3": + raise ConanInvalidConfiguration("mp-units requires at least g++-9.3") + elif compiler == "Visual Studio": + if version < "16": + raise ConanInvalidConfiguration("mp-units requires at least MSVC 16") + else: + raise ConanInvalidConfiguration("mp-units is supported only by gcc and Visual Studio so far") + check_min_cppstd(self, "20") + def _configure_cmake(self, folder="src"): cmake = CMake(self) if self._run_tests: @@ -72,15 +86,7 @@ class UnitsConan(ConanFile): return cmake def configure(self): - if self.settings.compiler != "gcc" and self.settings.compiler != "Visual Studio": # and self.settings.compiler != "clang": - raise ConanInvalidConfiguration("Library works only with gcc and Visual Studio so far") # and clang") - if self.settings.compiler == "gcc" and Version(self.settings.compiler.version) < "9": - raise ConanInvalidConfiguration("Library requires at least g++-9") - if self.settings.compiler == "Visual Studio" and Version(self.settings.compiler.version) < "16": - raise ConanInvalidConfiguration("Library requires at least Visual Studio 2019") - if self.settings.compiler == "clang" and Version(self.settings.compiler.version) < "11": - raise ConanInvalidConfiguration("Library requires at least clang++-11") - tools.check_min_cppstd(self, "20") + self._validate_compiler_settings() def requirements(self): if ((self.settings.compiler == "gcc" and Version(self.settings.compiler.version) < "10") or @@ -104,18 +110,25 @@ class UnitsConan(ConanFile): cmake = self._configure_cmake() cmake.install() - def package_info(self): - if self.settings.compiler == "gcc": - self.cpp_info.cxxflags = [ - "-Wno-literal-suffix", - "-Wno-non-template-friend", - ] - if Version(self.settings.compiler.version) < "10": - self.cpp_info.cxxflags.extend([ - "-fconcepts" - ]) - def package_id(self): self.info.settings.clear() self.info.settings.compiler = self.settings.compiler self.info.settings.compiler.version = self.settings.compiler.version + + def package_info(self): + compiler = self.settings.compiler + version = Version(self.settings.compiler.version) + if compiler == "gcc": + self.cpp_info.cxxflags = [ + "-Wno-literal-suffix", + "-Wno-non-template-friend", + ] + if version < "10": + self.cpp_info.cxxflags.extend([ + "-fconcepts" + ]) + elif compiler == "Visual Studio": + self.cpp_info.cxxflags = [ + "/utf-8", + "/wd4455" + ] diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 57fabf75..c595a723 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -20,6 +20,8 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +cmake_minimum_required(VERSION 3.12) + option(GENERATE_DOCS "Generate project documenation" ON) if(NOT GENERATE_DOCS) return() diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 8a6fc23b..3a2d15ee 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -20,9 +20,11 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +cmake_minimum_required(VERSION 3.12) + function(add_example target) add_executable(${target} ${target}.cpp) - target_link_libraries(${target} PRIVATE mp::units) + target_link_libraries(${target} PRIVATE mp-units::mp-units) endfunction() add_example(box_example) diff --git a/example/alternative_namespaces/CMakeLists.txt b/example/alternative_namespaces/CMakeLists.txt index 6f3bc3d7..6341730c 100644 --- a/example/alternative_namespaces/CMakeLists.txt +++ b/example/alternative_namespaces/CMakeLists.txt @@ -20,9 +20,11 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +cmake_minimum_required(VERSION 3.12) + function(add_example target) add_executable(${target}_alt ${target}.cpp) - target_link_libraries(${target}_alt PRIVATE mp::units) + target_link_libraries(${target}_alt PRIVATE mp-units::mp-units) endfunction() add_example(box_example) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 915bf5b9..23332d47 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -37,8 +37,8 @@ include(common/cmake/scripts) conan_init(cmake) # library definition -add_library(units INTERFACE) -#target_sources(units INTERFACE +add_library(mp-units INTERFACE) +#target_sources(mp-units INTERFACE # include/units/dimension.h # include/units/quantity.h # include/units/unit.h @@ -52,55 +52,55 @@ add_library(units INTERFACE) # include/units/si/time.h # include/units/si/speed.h #) -target_compile_features(units INTERFACE cxx_std_20) -target_link_libraries(units +target_compile_features(mp-units INTERFACE cxx_std_20) +target_link_libraries(mp-units INTERFACE $,CONAN_PKG::fmt,fmt::fmt> $,CONAN_PKG::ms-gsl,Microsoft.GSL::GSL> ) -target_include_directories(units +target_include_directories(mp-units INTERFACE $ $ ) if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - target_link_libraries(units + target_link_libraries(mp-units INTERFACE $,CONAN_PKG::range-v3,range-v3::range-v3> ) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - target_compile_options(units + target_compile_options(mp-units INTERFACE -Wno-literal-suffix -Wno-non-template-friend ) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0) - target_compile_options(units + target_compile_options(mp-units INTERFACE -fconcepts ) - target_link_libraries(units + target_link_libraries(mp-units INTERFACE $,CONAN_PKG::range-v3,range-v3::range-v3> ) endif() elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - target_compile_options(units + target_compile_options(mp-units INTERFACE /utf-8 # Specifies both the source character set and the execution character set as UTF-8 /wd4455 # 'operator name': literal suffix identifiers that do not start with an underscore are reserved ) endif() -add_library(mp::units ALIAS units) +add_library(mp-units::mp-units ALIAS mp-units) # installation info -install_targets(units) +install_targets(mp-units) install(DIRECTORY include/units DESTINATION include COMPONENT Devel ) # generate configuration files and install the package -configure_and_install(../cmake/common/cmake/simple-config.cmake.in mp SameMajorVersion) +configure_and_install(../cmake/common/cmake/simple-config.cmake.in mp-units SameMajorVersion) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 67a1d088..32c5ea73 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -20,6 +20,8 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +cmake_minimum_required(VERSION 3.12) + add_subdirectory(unit_test/runtime) add_subdirectory(unit_test/static) #add_subdirectory(metabench) diff --git a/test/metabench/CMakeLists.txt b/test/metabench/CMakeLists.txt index a7894a18..8264d434 100644 --- a/test/metabench/CMakeLists.txt +++ b/test/metabench/CMakeLists.txt @@ -20,6 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +cmake_minimum_required(VERSION 3.12) function(add_metabench_test target name erb_path range) metabench_add_dataset(${target} "${erb_path}" "${range}" NAME "${name}") diff --git a/test/metabench/list/CMakeLists.txt b/test/metabench/list/CMakeLists.txt index fb1b5b97..c8776f04 100644 --- a/test/metabench/list/CMakeLists.txt +++ b/test/metabench/list/CMakeLists.txt @@ -20,6 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +cmake_minimum_required(VERSION 3.12) add_metabench_test(metabench.data.list.type_list.concepts_all "all concepts" type_list_concepts_all.cpp.erb "[3, 6, 9, 12, 15]") add_metabench_test(metabench.data.list.type_list.concepts_iface "concepts in interface" type_list_concepts_iface.cpp.erb "[3, 6, 9, 12, 15]") diff --git a/test/metabench/list/type_list_concepts_all.h b/test/metabench/list/type_list_concepts_all.h index 0344bdc9..62255427 100644 --- a/test/metabench/list/type_list_concepts_all.h +++ b/test/metabench/list/type_list_concepts_all.h @@ -182,4 +182,4 @@ namespace units { template typename Pred> using type_list_sort_t = type_list_sort::type; -} // namespace units \ No newline at end of file +} // namespace units diff --git a/test/metabench/make_dimension/CMakeLists.txt b/test/metabench/make_dimension/CMakeLists.txt index 63fdff45..c3d7c39b 100644 --- a/test/metabench/make_dimension/CMakeLists.txt +++ b/test/metabench/make_dimension/CMakeLists.txt @@ -20,6 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +cmake_minimum_required(VERSION 3.12) add_metabench_test(metabench.data.make_dimension.no_concepts "no concepts" no_concepts.cpp.erb "[1, 2, 3, 4, 6, 8, 10]") add_metabench_test(metabench.data.make_dimension.concepts_iface "concepts iface" concepts_iface.cpp.erb "[1, 2, 3, 4, 6, 8, 10]") diff --git a/test/metabench/ratio/CMakeLists.txt b/test/metabench/ratio/CMakeLists.txt index fe5e2ca2..a3cc5fea 100644 --- a/test/metabench/ratio/CMakeLists.txt +++ b/test/metabench/ratio/CMakeLists.txt @@ -20,6 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +cmake_minimum_required(VERSION 3.12) add_metabench_test(metabench.data.ratio.create.std_ratio "std::ratio" create_std_ratio.cpp.erb "[1000, 2500, 5000, 7500, 10000]") add_metabench_test(metabench.data.ratio.create.ratio_type_constexpr "ratio with constexpr" create_ratio_type_constexpr.cpp.erb "[1000, 2500, 5000, 7500, 10000]") diff --git a/test/unit_test/runtime/CMakeLists.txt b/test/unit_test/runtime/CMakeLists.txt index 0a727dbb..dc1ea76c 100644 --- a/test/unit_test/runtime/CMakeLists.txt +++ b/test/unit_test/runtime/CMakeLists.txt @@ -20,6 +20,8 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +cmake_minimum_required(VERSION 3.12) + # check if conan installed a test framework conan_check_testing(catch2) @@ -33,7 +35,7 @@ add_executable(unit_tests_runtime ) target_link_libraries(unit_tests_runtime PRIVATE - mp::units + mp-units::mp-units $,CONAN_PKG::catch2,Catch2::Catch2> ) diff --git a/test/unit_test/runtime/distribution_test.cpp b/test/unit_test/runtime/distribution_test.cpp index 9422fd90..101d569c 100644 --- a/test/unit_test/runtime/distribution_test.cpp +++ b/test/unit_test/runtime/distribution_test.cpp @@ -606,4 +606,4 @@ TEST_CASE("piecewise_linear_distribution") CHECK(units_dist.intervals() == intervals_qty_vec); CHECK(units_dist.densities() == stl_dist.densities()); } -} \ No newline at end of file +} diff --git a/test/unit_test/static/CMakeLists.txt b/test/unit_test/static/CMakeLists.txt index a5fe55e3..afe82e06 100644 --- a/test/unit_test/static/CMakeLists.txt +++ b/test/unit_test/static/CMakeLists.txt @@ -20,6 +20,8 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +cmake_minimum_required(VERSION 3.12) + add_library(unit_tests_static cgs_test.cpp custom_rep_min_req_test.cpp @@ -43,5 +45,5 @@ add_library(unit_tests_static ) target_link_libraries(unit_tests_static PRIVATE - mp::units + mp-units::mp-units ) diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt index 559377d3..b59831c0 100644 --- a/test_package/CMakeLists.txt +++ b/test_package/CMakeLists.txt @@ -20,11 +20,9 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -cmake_minimum_required(VERSION 2.8.12) +cmake_minimum_required(VERSION 3.12) project(test_package) -set(CMAKE_VERBOSE_MAKEFILE TRUE) - # set path to custom cmake modules list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake") @@ -41,4 +39,4 @@ target_link_libraries(${PROJECT_NAME}_conan PRIVATE CONAN_PKG::mp-units) # test cmake-generated target find_package(mp-units CONFIG REQUIRED) add_executable(${PROJECT_NAME}_cmake test_package.cpp) -target_link_libraries(${PROJECT_NAME}_cmake PRIVATE mp::units) +target_link_libraries(${PROJECT_NAME}_cmake PRIVATE mp-units::mp-units)