build: Conan generator changed to provide more transparent dependency handling

This commit is contained in:
Mateusz Pusz
2020-12-09 18:47:12 +01:00
parent 9efa8b4711
commit c5919d2cd8
7 changed files with 15 additions and 63 deletions

View File

@ -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()

View File

@ -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()

View File

@ -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):

View File

@ -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
$<IF:$<TARGET_EXISTS:CONAN_PKG::linear_algebra>,CONAN_PKG::linear_algebra,linear_algebra::linear_algebra>
linear_algebra::linear_algebra
)
add_example(measurement)

View File

@ -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
$<IF:$<TARGET_EXISTS:CONAN_PKG::fmt>,CONAN_PKG::fmt,fmt::fmt>
$<IF:$<TARGET_EXISTS:CONAN_PKG::ms-gsl>,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
$<IF:$<TARGET_EXISTS:CONAN_PKG::range-v3>,CONAN_PKG::range-v3,range-v3::range-v3>
range-v3::range-v3
)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(mp-units

View File

@ -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
$<IF:$<TARGET_EXISTS:CONAN_PKG::range-v3>,CONAN_PKG::range-v3,range-v3::range-v3>
range-v3::range-v3>
)
target_compile_options(${target}
PUBLIC

View File

@ -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
$<IF:$<TARGET_EXISTS:CONAN_PKG::catch2>,CONAN_PKG::catch2,Catch2::Catch2>
Catch2::Catch2
)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")