Build system refactored to be comatible with ConanCenter

This commit is contained in:
Mateusz Pusz
2020-09-06 00:00:06 +02:00
parent 2078de7151
commit 32779e01f0
16 changed files with 77 additions and 50 deletions

View File

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

View File

@@ -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"
]

View File

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

View File

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

View File

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

View File

@@ -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
$<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>
)
target_include_directories(units
target_include_directories(mp-units
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_link_libraries(units
target_link_libraries(mp-units
INTERFACE
$<IF:$<TARGET_EXISTS:CONAN_PKG::range-v3>,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
$<IF:$<TARGET_EXISTS:CONAN_PKG::range-v3>,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)

View File

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

View File

@@ -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}")

View File

@@ -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]")

View File

@@ -182,4 +182,4 @@ namespace units {
template<TypeList List, template<typename, typename> typename Pred>
using type_list_sort_t = type_list_sort<List, Pred>::type;
} // namespace units
} // namespace units

View File

@@ -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]")

View File

@@ -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]")

View File

@@ -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
$<IF:$<TARGET_EXISTS:CONAN_PKG::catch2>,CONAN_PKG::catch2,Catch2::Catch2>
)

View File

@@ -606,4 +606,4 @@ TEST_CASE("piecewise_linear_distribution")
CHECK(units_dist.intervals() == intervals_qty_vec);
CHECK(units_dist.densities() == stl_dist.densities());
}
}
}

View File

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

View File

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