From c5919d2cd856076a8a79e4ca8171b6ca2360dbe3 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Wed, 9 Dec 2020 18:47:12 +0100 Subject: [PATCH] build: Conan generator changed to provide more transparent dependency handling --- CMakeLists.txt | 7 ++-- cmake/common/conan.cmake | 46 --------------------------- conanfile.py | 4 +-- example/CMakeLists.txt | 4 +-- src/CMakeLists.txt | 10 +++--- test/metabench/CMakeLists.txt | 2 +- test/unit_test/runtime/CMakeLists.txt | 5 ++- 7 files changed, 15 insertions(+), 63 deletions(-) delete mode 100644 cmake/common/conan.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index b18a30a9..cc17f2c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,15 +23,14 @@ cmake_minimum_required(VERSION 3.12) project(mp-units) -# set path to custom cmake modules list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +# set paths to Conan packages +include(${CMAKE_BINARY_DIR}/conan_paths.cmake OPTIONAL) + # include common tools and workarounds include(common/scripts) -# use Conan configuration if available -conan_init(cmake) - # enable static analysis #enable_clang_tidy() #enable_iwyu() diff --git a/cmake/common/conan.cmake b/cmake/common/conan.cmake deleted file mode 100644 index 6219e05c..00000000 --- a/cmake/common/conan.cmake +++ /dev/null @@ -1,46 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2017 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. - - -# Helper to use conan generated configuration if provided -macro(conan_init generator) - if(${generator} STREQUAL "cmake_paths") - include(${CMAKE_BINARY_DIR}/conan_paths.cmake OPTIONAL) - elseif(${generator} STREQUAL "cmake") - if(NOT DEFINED CONAN_PACKAGE_NAME) - if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) - include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) - conan_basic_setup(TARGETS) - endif() - endif() - else() - message(FATAL_ERROR "Unknown Conan generator: ${generator}") - endif() -endmacro() - - -# Checks if conan installed testing dependencies -macro(conan_check_testing test_framework) - if(NOT TARGET CONAN_PKG::${test_framework}) - message(FATAL_ERROR "CONAN_PKG::${test_framework} not found!\nPlease run `conan install` with `-e CONAN_RUN_TESTS=True`.") - endif() -endmacro() diff --git a/conanfile.py b/conanfile.py index 97153313..96d3bc3a 100644 --- a/conanfile.py +++ b/conanfile.py @@ -43,7 +43,7 @@ class UnitsConan(ConanFile): 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 = "compiler" + settings = "compiler", "build_type" requires = ( "fmt/7.0.3", "ms-gsl/3.1.0" @@ -64,7 +64,7 @@ class UnitsConan(ConanFile): # "revision": "auto", # "submodule": "recursive" # } - generators = "cmake" + generators = "cmake_find_package_multi", "cmake_paths" @property def _run_tests(self): diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 76a99d84..44333130 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -36,11 +36,11 @@ add_example(experimental_angle) add_example(foot_pound_second) add_example(kalman_filter-alpha_beta_filter_example2) -conan_check_testing(linear_algebra) +find_package(linear_algebra CONFIG REQUIRED) add_example(linear_algebra) target_link_libraries(linear_algebra PRIVATE - $,CONAN_PKG::linear_algebra,linear_algebra::linear_algebra> + linear_algebra::linear_algebra ) add_example(measurement) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f79b2bad..9c591814 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,8 +36,8 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake") # include common tools and workarounds include(common/scripts) -# use Conan configuration if available -conan_init(cmake) +find_package(fmt CONFIG REQUIRED) +find_package(Microsoft.GSL CONFIG REQUIRED) # library definition add_library(mp-units INTERFACE) @@ -58,8 +58,8 @@ add_library(mp-units INTERFACE) 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> + fmt::fmt + Microsoft.GSL::GSL ) target_include_directories(mp-units INTERFACE @@ -70,7 +70,7 @@ target_include_directories(mp-units if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") target_link_libraries(mp-units INTERFACE - $,CONAN_PKG::range-v3,range-v3::range-v3> + range-v3::range-v3 ) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") target_compile_options(mp-units diff --git a/test/metabench/CMakeLists.txt b/test/metabench/CMakeLists.txt index 8264d434..b5206de1 100644 --- a/test/metabench/CMakeLists.txt +++ b/test/metabench/CMakeLists.txt @@ -27,7 +27,7 @@ function(add_metabench_test target name erb_path range) target_compile_features(${target} PUBLIC cxx_std_20) target_link_libraries(${target} PUBLIC - $,CONAN_PKG::range-v3,range-v3::range-v3> + range-v3::range-v3> ) target_compile_options(${target} PUBLIC diff --git a/test/unit_test/runtime/CMakeLists.txt b/test/unit_test/runtime/CMakeLists.txt index dc1ea76c..2556b1aa 100644 --- a/test/unit_test/runtime/CMakeLists.txt +++ b/test/unit_test/runtime/CMakeLists.txt @@ -22,8 +22,7 @@ cmake_minimum_required(VERSION 3.12) -# check if conan installed a test framework -conan_check_testing(catch2) +find_package(Catch2 CONFIG REQUIRED) add_executable(unit_tests_runtime catch_main.cpp @@ -36,7 +35,7 @@ add_executable(unit_tests_runtime target_link_libraries(unit_tests_runtime PRIVATE mp-units::mp-units - $,CONAN_PKG::catch2,Catch2::Catch2> + Catch2::Catch2 ) if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")