Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[package] Qt/5.15.2: Cmake doesn't export the versionless targets #6459

Open
tcanabrava opened this issue Jul 22, 2021 · 9 comments · May be fixed by #25198
Open

[package] Qt/5.15.2: Cmake doesn't export the versionless targets #6459

tcanabrava opened this issue Jul 22, 2021 · 9 comments · May be fixed by #25198
Labels
bug Something isn't working

Comments

@tcanabrava
Copy link
Contributor

This is important for Qt5 / 6 compatibility.

https://doc-snapshots.qt.io/qt6-dev/cmake-qt5-and-qt6-compatibility.html

CMake Error at cmake/AddDualTargetLibrary.cmake:61 (add_library):
Target "tet_exec" links to target "Qt::Gui" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
Call Stack (most recent call first):
CMakeLists.txt:5

Steps to reproduce (Include if Applicable)

Create a Qt5 project for cmake.
Use the versionless Target:

add_executable(test main.cpp)
target_link_libraries(test Qt::Core)

@tcanabrava tcanabrava added the bug Something isn't working label Jul 22, 2021
@tcanabrava
Copy link
Contributor Author

This also affects Qt6

@ericLemanissier
Copy link
Contributor

I think conan is not able to generate targets in several namespaces : https://docs.conan.io/en/latest/reference/generators/cmake_find_package.html
It may be already reported in conan-io/conan. If not, it's worth reporting.

@SpaceIm
Copy link
Contributor

SpaceIm commented Aug 6, 2021

I forgot to answer to this thread: you can emulate any target with a custom CMake module created at package() time, and added to build_modules in package_info(). It's tedious, but it works.

Most recipes using this trick create non namespaced targets, but you can perfectly create custom namespaced targets.
Take a look at openexr recipe:

self._create_cmake_module_alias_targets(
os.path.join(self.package_folder, self._module_file_rel_path),
{
"IlmBase::IlmBaseConfig": "OpenEXR::IlmBaseConfig",
"IlmBase::Half": "OpenEXR::Half",
"IlmBase::Iex": "OpenEXR::Iex",
"IlmBase::IexMath": "OpenEXR::IexMath",
"IlmBase::IMath": "OpenEXR::IMath",
"IlmBase::IlmThread": "OpenEXR::IlmThread",
}
)
@staticmethod
def _create_cmake_module_alias_targets(module_file, targets):
content = ""
for alias, aliased in targets.items():
content += textwrap.dedent("""\
if(TARGET {aliased} AND NOT TARGET {alias})
add_library({alias} INTERFACE IMPORTED)
set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased})
endif()
""".format(alias=alias, aliased=aliased))
tools.save(module_file, content)
@property
def _module_subfolder(self):
return os.path.join("lib", "cmake")
@property
def _module_file_rel_path(self):
return os.path.join(self._module_subfolder,
"conan-official-{}-targets.cmake".format(self.name))
def package_info(self):
# FIXME: we should generate 2 CMake config files: OpenEXRConfig.cmake and IlmBaseConfig.cmake
# waiting an implementation of https://github.com/conan-io/conan/issues/9000
self.cpp_info.names["cmake_find_package"] = "OpenEXR"
self.cpp_info.names["cmake_find_package_multi"] = "OpenEXR"
self.cpp_info.names["pkg_config"] = "openexr_full_package" # not official, we want to avoid clash with OpenEXR.pc generated by IlmImf component
openexr_version = tools.Version(self.version)
lib_suffix = "-{}_{}".format(openexr_version.major, openexr_version.minor)
if self.settings.build_type == "Debug":
lib_suffix += "_d"
include_dir = os.path.join("include", "OpenEXR")
# IlmImfConfig
self.cpp_info.components["openexr_ilmimfconfig"].names["cmake_find_package"] = "IlmImfConfig"
self.cpp_info.components["openexr_ilmimfconfig"].names["cmake_find_package_multi"] = "IlmImfConfig"
self.cpp_info.components["openexr_ilmimfconfig"].includedirs.append(include_dir)
# IlmImf
self.cpp_info.components["openexr_ilmimf"].names["cmake_find_package"] = "IlmImf"
self.cpp_info.components["openexr_ilmimf"].names["cmake_find_package_multi"] = "IlmImf"
self.cpp_info.components["openexr_ilmimf"].names["pkg_config"] = "OpenEXR"
self.cpp_info.components["openexr_ilmimf"].includedirs.append(include_dir)
self.cpp_info.components["openexr_ilmimf"].libs = ["IlmImf{}".format(lib_suffix)]
self.cpp_info.components["openexr_ilmimf"].requires = [
"openexr_ilmimfconfig", "ilmbase_iex", "ilmbase_half",
"ilmbase_imath", "ilmbase_ilmthread", "zlib::zlib",
]
# IlmImfUtil
self.cpp_info.components["openexr_ilmimfutil"].names["cmake_find_package"] = "IlmImfUtil"
self.cpp_info.components["openexr_ilmimfutil"].names["cmake_find_package_multi"] = "IlmImfUtil"
self.cpp_info.components["openexr_ilmimfutil"].includedirs.append(include_dir)
self.cpp_info.components["openexr_ilmimfutil"].libs = ["IlmImfUtil{}".format(lib_suffix)]
self.cpp_info.components["openexr_ilmimfutil"].requires = ["openexr_ilmimfconfig", "openexr_ilmimf"]
# IlmBaseConfig
self.cpp_info.components["ilmbase_ilmbaseconfig"].names["cmake_find_package"] = "IlmBaseConfig"
self.cpp_info.components["ilmbase_ilmbaseconfig"].names["cmake_find_package_multi"] = "IlmBaseConfig"
self.cpp_info.components["ilmbase_ilmbaseconfig"].builddirs.append(self._module_subfolder)
self.cpp_info.components["ilmbase_ilmbaseconfig"].build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.components["ilmbase_ilmbaseconfig"].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
self.cpp_info.components["ilmbase_ilmbaseconfig"].includedirs.append(include_dir)
# Half
self.cpp_info.components["ilmbase_half"].names["cmake_find_package"] = "Half"
self.cpp_info.components["ilmbase_half"].names["cmake_find_package_multi"] = "Half"
self.cpp_info.components["ilmbase_half"].builddirs.append(self._module_subfolder)
self.cpp_info.components["ilmbase_half"].build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.components["ilmbase_half"].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
self.cpp_info.components["ilmbase_half"].includedirs.append(include_dir)
self.cpp_info.components["ilmbase_half"].libs = ["Half{}".format(lib_suffix)]
self.cpp_info.components["ilmbase_half"].requires = ["ilmbase_ilmbaseconfig"]
# Iex
self.cpp_info.components["ilmbase_iex"].names["cmake_find_package"] = "Iex"
self.cpp_info.components["ilmbase_iex"].names["cmake_find_package_multi"] = "Iex"
self.cpp_info.components["ilmbase_iex"].builddirs.append(self._module_subfolder)
self.cpp_info.components["ilmbase_iex"].build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.components["ilmbase_iex"].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
self.cpp_info.components["ilmbase_iex"].includedirs.append(include_dir)
self.cpp_info.components["ilmbase_iex"].libs = ["Iex{}".format(lib_suffix)]
self.cpp_info.components["ilmbase_iex"].requires = ["ilmbase_ilmbaseconfig"]
# IexMath
self.cpp_info.components["ilmbase_iexmath"].names["cmake_find_package"] = "IexMath"
self.cpp_info.components["ilmbase_iexmath"].names["cmake_find_package_multi"] = "IexMath"
self.cpp_info.components["ilmbase_iexmath"].builddirs.append(self._module_subfolder)
self.cpp_info.components["ilmbase_iexmath"].build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.components["ilmbase_iexmath"].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
self.cpp_info.components["ilmbase_iexmath"].includedirs.append(include_dir)
self.cpp_info.components["ilmbase_iexmath"].libs = ["IexMath{}".format(lib_suffix)]
self.cpp_info.components["ilmbase_iexmath"].requires = ["ilmbase_ilmbaseconfig", "ilmbase_iex"]
# IMath
self.cpp_info.components["ilmbase_imath"].names["cmake_find_package"] = "IMath"
self.cpp_info.components["ilmbase_imath"].names["cmake_find_package_multi"] = "IMath"
self.cpp_info.components["ilmbase_imath"].builddirs.append(self._module_subfolder)
self.cpp_info.components["ilmbase_imath"].build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.components["ilmbase_imath"].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
self.cpp_info.components["ilmbase_imath"].includedirs.append(include_dir)
self.cpp_info.components["ilmbase_imath"].libs = ["Imath{}".format(lib_suffix)]
self.cpp_info.components["ilmbase_imath"].requires = ["ilmbase_ilmbaseconfig", "ilmbase_half", "ilmbase_iexmath"]
# IlmThread
self.cpp_info.components["ilmbase_ilmthread"].names["cmake_find_package"] = "IlmThread"
self.cpp_info.components["ilmbase_ilmthread"].names["cmake_find_package_multi"] = "IlmThread"
self.cpp_info.components["ilmbase_ilmthread"].builddirs.append(self._module_subfolder)
self.cpp_info.components["ilmbase_ilmthread"].build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.components["ilmbase_ilmthread"].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
self.cpp_info.components["ilmbase_ilmthread"].includedirs.append(include_dir)
self.cpp_info.components["ilmbase_ilmthread"].libs = ["IlmThread{}".format(lib_suffix)]
self.cpp_info.components["ilmbase_ilmthread"].requires = ["ilmbase_ilmbaseconfig", "ilmbase_iex"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["ilmbase_ilmthread"].system_libs.append("pthread")

@perseoGI
Copy link
Contributor

perseoGI commented Sep 9, 2024

Hi there,
I was reviewing old issues and I have come across this one.
The qt/5.15.2 version is no longer supported by Conan Center Index.

I'm closing this issue as this recipe has suffer plenty of modifications since this issue was reported.
If for some reason the problem remains nowadays, do not hesitate to reopen this issue or create a new ticket with updated information, preferably using conan v2.

Happy coding 🐸

@perseoGI perseoGI closed this as completed Sep 9, 2024
@SpaceIm
Copy link
Contributor

SpaceIm commented Sep 9, 2024

@perseoGI I think it should not be closed, this issue has not been fixed.

@SpaceIm SpaceIm linked a pull request Sep 10, 2024 that will close this issue
3 tasks
@SpaceIm
Copy link
Contributor

SpaceIm commented Sep 10, 2024

I've opened #25198

@perseoGI
Copy link
Contributor

Okey thanks for opening an updated issue!

@SpaceIm
Copy link
Contributor

SpaceIm commented Sep 10, 2024

It's not an updated issue but a PR fixing this issue.

@perseoGI
Copy link
Contributor

My sorry, really early in the morning hehe, thanks for your contribution @SpaceIm

@perseoGI perseoGI reopened this Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants