Skip to content

Commit

Permalink
(conan-io#10836) hdf5 - fix module_file
Browse files Browse the repository at this point in the history
  • Loading branch information
paulharris committed May 18, 2022
1 parent 775ffdd commit e793fa1
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions recipes/hdf5/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def _components(self):
}

@staticmethod
def _create_cmake_module_alias_targets(module_file, targets, is_parallel):
def _create_cmake_module_alias_targets(module_file, targets):
content = ""
for alias, aliased in targets.items():
content += textwrap.dedent("""\
Expand All @@ -193,14 +193,23 @@ def _create_cmake_module_alias_targets(module_file, targets, is_parallel):
set_property(TARGET hdf5::hdf5_hl_cpp PROPERTY INTERFACE_LINK_LIBRARIES HDF5::HL_CXX)
endif()
""")
content += textwrap.dedent("set(HDF5_IS_PARALLEL {})".format("ON" if is_parallel else "OFF"))
tools.save(module_file, content)

@staticmethod
def _create_cmake_module_variables(module_file, is_parallel):
content = "set(HDF5_IS_PARALLEL {})".format("ON" if is_parallel else "OFF")
tools.save(module_file, content)

@property
def _module_file_rel_path(self):
def _module_file_targets_rel_path(self):
return os.path.join("lib", "cmake",
"conan-official-{}-targets.cmake".format(self.name))

@property
def _module_file_variables_rel_path(self):
return os.path.join("lib", "cmake",
"conan-official-{}-variables.cmake".format(self.name))

def package(self):
self.copy("COPYING", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
Expand All @@ -211,8 +220,11 @@ def package(self):
# but component targets have a lower case namespace prefix. hdf5::hdf5 refers to the C library only
components = self._components()
self._create_cmake_module_alias_targets(
os.path.join(self.package_folder, self._module_file_rel_path),
{"hdf5::{}".format(component["alias_target"]): "HDF5::{}".format(component["component"]) for component in components.values()},
os.path.join(self.package_folder, self._module_file_targets_rel_path),
{"hdf5::{}".format(component["alias_target"]): "HDF5::{}".format(component["component"]) for component in components.values()}
)
self._create_cmake_module_variables(
os.path.join(self.package_folder, self._module_file_variables_rel_path),
self.options.get_safe("parallel", False)
)

Expand All @@ -229,14 +241,15 @@ def _config_libname(lib):

self.cpp_info.components[component_name].set_property("cmake_target_name", f"hdf5::{alias_target}")
self.cpp_info.components[component_name].set_property("pkg_config_name", alias_target)
self.cpp_info.components[component_name].set_property("cmake_build_modules", [self._module_file_variables_rel_path])
self.cpp_info.components[component_name].libs = [_config_libname(alias_target)]
self.cpp_info.components[component_name].requires = requirements

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.components[component_name].names["cmake_find_package"] = component
self.cpp_info.components[component_name].names["cmake_find_package_multi"] = component
self.cpp_info.components[component_name].build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.components[component_name].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
self.cpp_info.components[component_name].build_modules["cmake_find_package"] = [self._module_file_targets_rel_path, self._module_file_variables_rel_path]
self.cpp_info.components[component_name].build_modules["cmake_find_package_multi"] = [self._module_file_targets_rel_path, self._module_file_variables_rel_path]

self.cpp_info.set_property("cmake_find_mode", "both")
self.cpp_info.set_property("cmake_file_name", "HDF5")
Expand Down

0 comments on commit e793fa1

Please sign in to comment.