diff --git a/conanfile.py b/conanfile.py index 760e8026c5..302eb70cd2 100644 --- a/conanfile.py +++ b/conanfile.py @@ -259,13 +259,22 @@ def package(self): ) cmake = CMake(self) 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): compiler = self.settings.compiler - self.cpp_info.components["core"].requires = ["gsl-lite::gsl-lite"] - if self._use_fmtlib: - self.cpp_info.components["core"].requires.append("fmt::fmt") - if compiler == "msvc": - self.cpp_info.components["core"].cxxflags = ["/utf-8"] - self.cpp_info.components["systems"].requires = ["core"] + 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: + self.cpp_info.components["core"].requires = ["gsl-lite::gsl-lite"] + if self._use_fmtlib: + self.cpp_info.components["core"].requires.append("fmt::fmt") + if compiler == "msvc": + self.cpp_info.components["core"].cxxflags = ["/utf-8"] + self.cpp_info.components["systems"].requires = ["core"] diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt index 074aa5fd47..84f6cd0c1b 100644 --- a/test_package/CMakeLists.txt +++ b/test_package/CMakeLists.txt @@ -23,8 +23,19 @@ cmake_minimum_required(VERSION 3.15) project(test_package LANGUAGES CXX) +message(STATUS "MP_UNITS_BUILD_CXX_MODULES: ${MP_UNITS_BUILD_CXX_MODULES}") +message(STATUS "MP_UNITS_API_STD_FORMAT: ${MP_UNITS_API_STD_FORMAT}") + find_package(mp-units REQUIRED) -add_executable(test_package test_package.cpp) -target_link_libraries(test_package PRIVATE mp-units::mp-units) -target_compile_definitions(test_package PRIVATE MP_UNITS_API_STD_FORMAT=$) +add_executable(test_package-headers test_package.cpp) +target_compile_features(test_package-headers PRIVATE cxx_std_20) +target_link_libraries(test_package-headers PRIVATE mp-units::mp-units) +target_compile_definitions(test_package-headers PRIVATE MP_UNITS_API_STD_FORMAT=$) + +if(MP_UNITS_BUILD_CXX_MODULES) + add_executable(test_package test_package.cpp) + target_compile_features(test_package PRIVATE cxx_std_20) + target_link_libraries(test_package PRIVATE mp-units::mp-units) + target_compile_definitions(test_package PRIVATE MP_UNITS_MODULES MP_UNITS_API_STD_FORMAT=$) +endif() diff --git a/test_package/conanfile.py b/test_package/conanfile.py index 5e3586b192..28ffefcf82 100644 --- a/test_package/conanfile.py +++ b/test_package/conanfile.py @@ -39,6 +39,8 @@ def layout(self): def generate(self): tc = CMakeToolchain(self) + if self.dependencies["mp-units"].options.cxx_modules: + tc.variables["MP_UNITS_BUILD_CXX_MODULES"] = True tc.variables["MP_UNITS_API_STD_FORMAT"] = bool( self.dependencies["mp-units"].options.std_format ) @@ -51,5 +53,8 @@ def build(self): def test(self): if can_run(self): - bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + if self.dependencies["mp-units"].options.cxx_modules: + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package-headers") self.run(bin_path, env="conanrun") diff --git a/test_package/test_package.cpp b/test_package/test_package.cpp index dcdeeadfc1..c851ccd8ca 100644 --- a/test_package/test_package.cpp +++ b/test_package/test_package.cpp @@ -20,11 +20,16 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #include -#include +#endif using namespace mp_units;