Skip to content

Commit

Permalink
test: test_package now is tested also with C++20 modules
Browse files Browse the repository at this point in the history
  • Loading branch information
mpusz committed Apr 17, 2024
1 parent 94b4d0a commit 3adcb5f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
23 changes: 16 additions & 7 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
17 changes: 14 additions & 3 deletions test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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=$<BOOL:${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=$<BOOL:${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=$<BOOL:${MP_UNITS_API_STD_FORMAT}>)
endif()
7 changes: 6 additions & 1 deletion test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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")
7 changes: 6 additions & 1 deletion test_package/test_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include <mp-units/compat_macros.h>
#include <iostream>
#ifdef MP_UNITS_MODULES
import mp_units;
#else
#include <mp-units/format.h>
#include <mp-units/ostream.h>
#include <mp-units/systems/isq/isq.h>
#include <mp-units/systems/si/si.h>
#include <iostream>
#endif

using namespace mp_units;

Expand Down

0 comments on commit 3adcb5f

Please sign in to comment.