build(conan): packaging improved

This commit is contained in:
Mateusz Pusz
2024-09-27 12:12:26 +02:00
parent 7ea1ea0ff7
commit 3fc7ecc316
3 changed files with 53 additions and 40 deletions

View File

@ -72,7 +72,7 @@ class MPUnitsConan(ConanFile):
"contracts": "gsl-lite", "contracts": "gsl-lite",
"freestanding": False, "freestanding": False,
} }
implements = "auto_header_only" implements = ["auto_header_only"]
exports = "LICENSE.md" exports = "LICENSE.md"
exports_sources = ( exports_sources = (
"docs/*", "docs/*",
@ -305,40 +305,62 @@ class MPUnitsConan(ConanFile):
) )
cmake = CMake(self) cmake = CMake(self)
cmake.install() cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) if not self.options.cxx_modules:
# We have to preserve those files for C++ modules build as Conan
# can't generate such CMake targets for now
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
def package_info(self): def package_info(self):
compiler = self.settings.compiler compiler = self.settings.compiler
if self.options.cxx_modules:
# CMakeDeps does not generate C++ modules definitions for now
# Skip the Conan-generated files and use the mp-unitsConfig.cmake bundled with mp-units
self.cpp_info.set_property("cmake_find_mode", "none")
self.cpp_info.builddirs = ["."]
else:
# handle contracts
if self.options.contracts == "none":
self.cpp_info.components["core"].defines.append(
"MP_UNITS_API_CONTRACTS=0"
)
elif self.options.contracts == "gsl-lite":
self.cpp_info.components["core"].requires.append("gsl-lite::gsl-lite")
self.cpp_info.components["core"].defines.append(
"MP_UNITS_API_CONTRACTS=2"
)
elif self.options.contracts == "ms-gsl":
self.cpp_info.components["core"].requires.append("ms-gsl::ms-gsl")
self.cpp_info.components["core"].defines.append(
"MP_UNITS_API_CONTRACTS=3"
)
# handle contracts # handle API options
if self.options.contracts == "none": self.cpp_info.components["core"].defines.append(
self.cpp_info.components["core"].defines.append("MP_UNITS_API_CONTRACTS=0") "MP_UNITS_API_STRING_VIEW_RET="
elif self.options.contracts == "gsl-lite": + str(int(self.options.string_view_ret == True))
self.cpp_info.components["core"].requires.append("gsl-lite::gsl-lite") )
self.cpp_info.components["core"].defines.append("MP_UNITS_API_CONTRACTS=2") self.cpp_info.components["core"].defines.append(
elif self.options.contracts == "ms-gsl": "MP_UNITS_API_NO_CRTP=" + str(int(self.options.no_crtp == True))
self.cpp_info.components["core"].requires.append("ms-gsl::ms-gsl") )
self.cpp_info.components["core"].defines.append("MP_UNITS_API_CONTRACTS=3") self.cpp_info.components["core"].defines.append(
"MP_UNITS_API_STD_FORMAT=" + str(int(self.options.std_format == True))
)
if not self.options.std_format:
self.cpp_info.components["core"].requires.append("fmt::fmt")
# handle API options # handle hosted configuration
self.cpp_info.components["core"].defines.append( if not self.options.freestanding:
"MP_UNITS_API_STRING_VIEW_RET=" self.cpp_info.components["core"].defines.append("MP_UNITS_HOSTED=1")
+ str(int(self.options.string_view_ret == True))
)
self.cpp_info.components["core"].defines.append(
"MP_UNITS_API_NO_CRTP=" + str(int(self.options.no_crtp == True))
)
self.cpp_info.components["core"].defines.append(
"MP_UNITS_API_STD_FORMAT=" + str(int(self.options.std_format == True))
)
if not self.options.std_format:
self.cpp_info.components["core"].requires.append("fmt::fmt")
# handle hosted configuration # handle import std
if not self.options.freestanding: if self.options.import_std:
self.cpp_info.components["core"].defines.append("MP_UNITS_HOSTED=1") self.cpp_info.components["core"].defines.append("MP_UNITS_IMPORT_STD")
if compiler == "clang" and Version(compiler.version) < 19:
self.cpp_info.components["core"].cxxflags.append(
"-Wno-deprecated-declarations"
)
if compiler == "msvc": if compiler == "msvc":
self.cpp_info.components["core"].cxxflags = ["/utf-8"] self.cpp_info.components["core"].cxxflags.append("/utf-8")
self.cpp_info.components["systems"].requires = ["core"] self.cpp_info.components["systems"].requires = ["core"]

View File

@ -27,12 +27,3 @@ find_package(mp-units REQUIRED)
add_executable(test_package test_package.cpp) add_executable(test_package test_package.cpp)
target_link_libraries(test_package PRIVATE mp-units::mp-units) target_link_libraries(test_package PRIVATE mp-units::mp-units)
target_compile_definitions(test_package PRIVATE MP_UNITS_API_STD_FORMAT=$<BOOL:${MP_UNITS_API_STD_FORMAT}>)
if(MP_UNITS_API_CONTRACTS STREQUAL "NONE")
target_compile_definitions(test_package PRIVATE MP_UNITS_API_CONTRACTS=0)
elseif(MP_UNITS_API_CONTRACTS STREQUAL "GSL-LITE")
target_compile_definitions(test_package PRIVATE MP_UNITS_API_CONTRACTS=2)
elseif(MP_UNITS_API_CONTRACTS STREQUAL "MS-GSL")
target_compile_definitions(test_package PRIVATE MP_UNITS_API_CONTRACTS=3)
endif()

View File

@ -42,13 +42,13 @@ class TestPackageConan(ConanFile):
opt = self.dependencies["mp-units"].options opt = self.dependencies["mp-units"].options
if opt.cxx_modules: if opt.cxx_modules:
tc.cache_variables["CMAKE_CXX_SCAN_FOR_MODULES"] = True tc.cache_variables["CMAKE_CXX_SCAN_FOR_MODULES"] = True
tc.cache_variables["MP_UNITS_BUILD_CXX_MODULES"] = True
if opt.import_std: if opt.import_std:
tc.cache_variables["CMAKE_CXX_MODULE_STD"] = True tc.cache_variables["CMAKE_CXX_MODULE_STD"] = True
# Current experimental support according to `Help/dev/experimental.rst` # Current experimental support according to `Help/dev/experimental.rst`
tc.cache_variables[ tc.cache_variables[
"CMAKE_EXPERIMENTAL_CXX_IMPORT_STD" "CMAKE_EXPERIMENTAL_CXX_IMPORT_STD"
] = "0e5b6991-d74f-4b3d-a41c-cf096e0b2508" ] = "0e5b6991-d74f-4b3d-a41c-cf096e0b2508"
# TODO remove the below when Conan will learn to handle C++ modules
if opt.freestanding: if opt.freestanding:
tc.cache_variables["MP_UNITS_API_FREESTANDING"] = True tc.cache_variables["MP_UNITS_API_FREESTANDING"] = True
else: else: