Skip to content

Conversation

tstrutz
Copy link

@tstrutz tstrutz commented Aug 22, 2025

Changelog: (Feature | Fix | Bugfix): Describe here your pull request
Docs: https://github.com/conan-io/docs/pull/XXXX

… files to be provided in place of the generated ones. Works better with cmake-conan plugin.
@CLAassistant
Copy link

CLAassistant commented Aug 22, 2025

CLA assistant check
All committers have signed the CLA.

@tstrutz
Copy link
Author

tstrutz commented Aug 22, 2025

Currently I am using the Conan generated targets.cmake and targets-.cmake files because the link path doesn't propagate correctly when using the project generated ones. This creates problems when setting the INSTALL_RPATH on project installed targets using INSTALL_RPATH_USE_LINK_PATH, which should contain all the directories of the conan packages.

I'm not sure why this is the case. I would prefer to use the project generated ones if possible, as they can contain linking information for targets that Conan may not be managing.

For example if I'm using an optional CUDA-enabled feature with one of the linked targets, conan doesn't manage cuda at all, so it the linker/include paths won't be propagated.

Yeah I just confirmed that adding a CUDA feature flag to one of the dependencies (uses system-installed CUDA) doesn't work:

[21/93] Building CXX object src/CMakeFiles/DEWMARS_SignalProcessing.dir/Release/composite.cpp.o
FAILED: src/CMakeFiles/DEWMARS_SignalProcessing.dir/Release/composite.cpp.o 
/usr/bin/c++ -DDEWMARS_SignalProcessing_EXPORTS -DDEWM_USE_CUDA -DLIBUUID_CPP20_OR_GREATER -DQCUSTOMPLOT_USE_LIBRARY -DQT_CONCURRENT_LIB -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_PRINT_SUPPORT_LIB -DQT_SQL_LIB -DQT_WIDGETS_LIB -DSPDLOG_COMPILED_LIB -DSPDLOG_FMT_EXTERNAL -DCMAKE_INTDIR=\"Release\" -I/home/tstrutz/development/dewmars/build/src -I/home/tstrutz/development/dewmars/src -I/home/tstrutz/development/dewmars/include -I/home/tstrutz/development/dewmars/include/DEWMARS -isystem /home/tstrutz/development/dewmars/build/src/DEWMARS_SignalProcessing_autogen/include_Release -isystem /home/tstrutz/.conan2/p/b/qt3a3f22f8977b9/p/include -isystem /home/tstrutz/.conan2/p/b/qt3a3f22f8977b9/p/include/QtWidgets -isystem /home/tstrutz/.conan2/p/b/qt3a3f22f8977b9/p/include/QtGui -isystem /home/tstrutz/.conan2/p/b/qt3a3f22f8977b9/p/include/QtCore -isystem /home/tstrutz/.conan2/p/b/qt3a3f22f8977b9/p/bin/archdatadir/mkspecs/linux-g++ -isystem /home/tstrutz/.conan2/p/b/qt3a3f22f8977b9/p/include/QtNetwork -isystem /home/tstrutz/.conan2/p/b/qt3a3f22f8977b9/p/include/QtSql -isystem /home/tstrutz/.conan2/p/b/qt3a3f22f8977b9/p/include/QtPrintSupport -isystem /home/tstrutz/.conan2/p/b/qt3a3f22f8977b9/p/include/QtConcurrent -isystem /home/tstrutz/.conan2/p/b/qcust335835ec573c5/p/include -isystem /home/tstrutz/.conan2/p/b/dewm4368526f688b9/p/include -isystem /home/tstrutz/.conan2/p/fftwfd0fcdeb2af6f/p/include -isystem /home/tstrutz/.conan2/p/spdlo043d22b3929a1/p/include -isystem /home/tstrutz/.conan2/p/fmt3ae8ec1ea6204/p/include -isystem /home/tstrutz/.conan2/p/matla49a7238405701/p/include -isystem /home/tstrutz/.conan2/p/midas5c079fb898566/p/include -isystem /home/tstrutz/.conan2/p/ms-gs000db09c5aa93/p/include -isystem /home/tstrutz/.conan2/p/stduuc98cd9a774ddd/p/include -isystem /home/tstrutz/.conan2/p/b/vclma45866bf1f434d/p/include -isystem /home/tstrutz/.conan2/p/nlohm0567ffc90cfc1/p/include -msse3  -O3 -DNDEBUG -std=gnu++20 -fPIC -fPIC -MD -MT src/CMakeFiles/DEWMARS_SignalProcessing.dir/Release/composite.cpp.o -MF src/CMakeFiles/DEWMARS_SignalProcessing.dir/Release/composite.cpp.o.d -o src/CMakeFiles/DEWMARS_SignalProcessing.dir/Release/composite.cpp.o -c /home/tstrutz/development/dewmars/src/composite.cpp
In file included from /home/tstrutz/.conan2/p/b/dewm4368526f688b9/p/include/DEWM/Triplet.hpp:33,
                 from /home/tstrutz/.conan2/p/b/dewm4368526f688b9/p/include/DEWM/SignalPDW.hpp:35,
                 from /home/tstrutz/development/dewmars/include/DEWMARS/dewmars_component.hpp:24,
                 from /home/tstrutz/development/dewmars/include/DEWMARS/composite.hpp:17,
                 from /home/tstrutz/development/dewmars/src/composite.cpp:14:
/home/tstrutz/.conan2/p/b/dewm4368526f688b9/p/include/DEWM/Constants.hpp:31:10: fatal error: cuComplex.h: No such file or directory
   31 | #include <cuComplex.h>

The project generated Target files contain this information, but I don't think Conan is setting up some of the linker path information correctly if I use those.

I may need some help to get Conan to use these paths correctly using all of the project provided files instead.

@tstrutz
Copy link
Author

tstrutz commented Aug 22, 2025

I just updated this branch using my old method, which looks to correctly import everything including CUDA targets if the project was built with them.

It just has issues with propagating the imported library paths to the linker path and INSTALL_RPATH. Can anyone help me figure out how conan sets those, i.e. why it works correctly with the conan generated files, and would could cause that to not work with the CMake generated ones?

In this workflow, the path that the libraries are copied to in the conan-generators folder OR the original package folder should be on the linker path, and so should be propagated into the install target. But this is not the case:

tstrutz@BAH5CG333536R:~/development/conan$ ldd ~/Install/bin/dewmars 
        linux-vdso.so.1 (0x00007fff00326000)
        libDEWMARS_SignalProcessing.so => /home/tstrutz/Install/lib/libDEWMARS_SignalProcessing.so (0x00007e3c9e223000)
        libqcustomplot.so.2 => /home/tstrutz/.conan2/p/b/qcust335835ec573c5/p/lib/libqcustomplot.so.2 (0x00007e3c9e0c0000)
        libQt5Widgets.so.5 => /home/tstrutz/.conan2/p/b/qt3a3f22f8977b9/p/lib/libQt5Widgets.so.5 (0x00007e3c9d800000)
        libQt5Core.so.5 => /home/tstrutz/.conan2/p/b/qt3a3f22f8977b9/p/lib/libQt5Core.so.5 (0x00007e3c9d000000)
        libDEWM.so => not found
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007e3c9cc00000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007e3c9e086000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007e3c9c800000)
        libQt5Network.so.5 => /home/tstrutz/.conan2/p/b/qt3a3f22f8977b9/p/lib/libQt5Network.so.5 (0x00007e3c9df31000)
        libQt5Sql.so.5 => /home/tstrutz/.conan2/p/b/qt3a3f22f8977b9/p/lib/libQt5Sql.so.5 (0x00007e3c9deec000)
        libQt5Concurrent.so.5 => /home/tstrutz/.conan2/p/b/qt3a3f22f8977b9/p/lib/libQt5Concurrent.so.5 (0x00007e3c9dee3000)
        libDEWM.so => not found
        libQt5Gui.so.5 => /home/tstrutz/.conan2/p/b/qt3a3f22f8977b9/p/lib/libQt5Gui.so.5 (0x00007e3c9c000000)
        libcudart.so.12 => /usr/local/cuda-12.9/targets/x86_64-linux/lib/libcudart.so.12 (0x00007e3c9bc00000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007e3c9d719000)
        /lib64/ld-linux-x86-64.so.2 (0x00007e3c9e43a000)
        libQt5PrintSupport.so.5 => /lib/x86_64-linux-gnu/libQt5PrintSupport.so.5 (0x00007e3c9cf88000)
        libGL.so.1 => /lib/x86_64-linux-gnu/libGL.so.1 (0x00007e3c9cf01000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007e3c9dedc000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007e3c9ded7000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007e3c9ded2000)
        libGLdispatch.so.0 => /lib/x86_64-linux-gnu/libGLdispatch.so.0 (0x00007e3c9ce49000)
        libGLX.so.0 => /lib/x86_64-linux-gnu/libGLX.so.0 (0x00007e3c9d6e5000)
        libX11.so.6 => /lib/x86_64-linux-gnu/libX11.so.6 (0x00007e3c9cac0000)
        libxcb.so.1 => /lib/x86_64-linux-gnu/libxcb.so.1 (0x00007e3c9d6bb000)
        libXau.so.6 => /lib/x86_64-linux-gnu/libXau.so.6 (0x00007e3c9deca000)
        libXdmcp.so.6 => /lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007e3c9ce41000)
        libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007e3c9caa8000)
        libmd.so.0 => /lib/x86_64-linux-gnu/libmd.so.0 (0x00007e3c9ce34000)

RPath of this binary:

tstrutz@BAH5CG333536R:~/development/conan$ objdump -x ~/Install/bin/dewmars |grep 'R.*PATH'
  RUNPATH              /home/tstrutz/ARCEM-Install/lib:/home/tstrutz/.conan2/p/b/qt3a3f22f8977b9/p/lib:/home/tstrutz/.conan2/p/b/qcust335835ec573c5/p/lib:/home/tstrutz/.conan2/p/b/xkbco7f538552220db/p/lib:/usr/local/cuda-12.9/targets/x86_64-linux/lib:/home/tstrutz/.conan2/p/midas5c079fb898566/p/lib:/home/tstrutz/.conan2/p/matla49a7238405701/p/lib:/home/tstrutz/.conan2/p/b/vclma45866bf1f434d/p/lib

Copy link
Member

@memsharded memsharded left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for your contribution @tstrutz

Some general comments:

  • Avoid introducing typing annotations, we don't use them in the codebase, they will be introduced just in the ConanAPI at this time, and gradually
  • All PRs should have accompanying new tests. This one will need integration + functional tests

No need to do any changes yet, please don't work yet on tests or do any changes.

It seems there could be some functional and architectural issues to consider carefully in this PR, and specially we should align first in the approach to follow, there could be different angles.

So lets think first about the problem, we will follow up and discuss in the issue you filed here #18815. Thanks again!

Comment on lines +84 to +88
ret[config_filename] = self._read_project_provided_cmake_file(config_filename, dep)
ret[version_filename] = self._read_project_provided_cmake_file(version_filename, dep)
ret[targets_filename] = self._read_project_provided_cmake_file(targets_filename, dep)
ret[target_configuration_filename] = self._read_project_provided_cmake_file(target_configuration_filename, dep)
deduced_cpp_info : CppInfo = dep.cpp_info.deduce_full_cpp_info(self._conanfile)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with this is that the files that projects provide might have different names, the "Targets" files is mostly a convention, but not mandatory. This will not work in many cases, and it is necessary a more general approach

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we provide the ability to pass in the corresponding names of these files then? I tried to use mostly existing code to generate these filenames.

Or just leverage the existing conan variables such as cmake_file_name etc?

Comment on lines +91 to +98
ConanOutput(self._conanfile.ref).info(f"Installing libs found in {deduced_cpp_info.location} and includes in {deduced_cpp_info.includedirs} to IMPORT_PREFIX location")
lib_folder = os.path.join("..", "lib", self.configuration)
os.makedirs(lib_folder, exist_ok=True)
shutil.copy(deduced_cpp_info.location, lib_folder)
shutil.copytree(deduced_cpp_info.includedir, os.path.join("..", "include"), dirs_exist_ok=True)
# Copy the component libraries.
for name, lib in deduced_cpp_info.components.items():
shutil.copy(lib.location, lib_folder)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A generator shouldn't be copying artifacts like headers or libs around, that is more the responsibility of a deployer.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you recommend moving this somewhere else in the code base, or just not doing this step entirely? This is how I attempted to make the files relocatable using the ${_IMPORT_PREFIX} which points to parent directory of the folder.

Another alternative might be to edit this path so that include/lib references for each target point back to the conan package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature] New cmake_find_mode - Copy Project provided Config files.
3 participants