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

CMake: Create relocatable packages: improve Find[GMP, CAIRO, QGLViewer, Magick++ FFTW3].cmake to create imported targets. #1544

Open
phcerdan opened this issue Jan 12, 2021 · 3 comments

Comments

@phcerdan
Copy link
Member

phcerdan commented Jan 12, 2021

DGtal is not relocatable (the install tree cannot be moved to other computer) when compiled with these dependencies.
The installed DGtal target contains full paths to the Foo_INCLUDE_DIRECTORY and/or Foo_LIBRARIES, which makes it not relocatable.
This is not a problem if we know beforehand where these dependencies will be installed (homebrew, specific OS, etc.) but it is cumberstone to set it up for different platforms.

This is an extract of DGtalLibraryDepends.cmake (exported targets) of the install tree, showing full paths.

# Create imported target DGtal
add_library(DGtal STATIC IMPORTED)

set_target_properties(DGtal PROPERTIES
  INTERFACE_COMPILE_DEFINITIONS "UNIX;BOOST_ALL_NO_LIB;WITH_GMP;GMP_HAS_IOSTREAM;WITH_CAIRO;WITH_QT5;WITH_VISU3D_QGLVIEWER;WITH_EIGEN;CGAL_EIGEN3_ENABLED;WITH_CGAL;WITH_Eigen3;WITH_LAPACK;WITH_FFTW3;WITH_FFTW3_FLOAT;WITH_FFTW3_DOUBLE;WITH_FFTW3_LONG"
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include;/usr/include;/usr/include;/usr/include;/usr/include/cairo;/usr/include;/usr/include"
  INTERFACE_LINK_LIBRARIES
  "ZLIB::ZLIB;
  rt;
  /usr/lib/libgmpxx.so;/usr/lib/libgmp.so; <-------- GMP
  /usr/lib/libcairo.so; <------------ CAIRO
  Qt5::Widgets;Qt5::OpenGL;Qt5::Xml;
  /usr/lib/libQGLViewer-qt5.so; <-------- QGLVIEWER
/usr/lib/libOpenGL.so;/usr/lib/libGLX.so;/usr/lib/libGLU.so;  <--These are probably ok, systemic libraries.
Eigen3::Eigen;
CGAL::CGAL_Core;CGAL::CGAL;
/usr/lib/libfftw3f.so;/usr/lib/libfftw3.so;/usr/lib/libfftw3l.so; <------ FFTW3
/usr/lib/libfftw3f_threads.so;/usr/lib/libfftw3_threads.so;/usr/lib/libfftw3l_threads.so;
m;
pthread"
  INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "/usr/include"
)

The imported targets with the signature Foo::Foo are the best solution (CMake docs), but there are packages that don't
provide a FooConfig.cmake with FooTargets.cmake. In this case, I think the best solution would be to
improve the FindFoo.cmake to create an imported target inside FindFoo.cmake. This approach is done by Kitware/CMake for
ZLIB::ZLIB, another HPC user has done it for FFTW3.

The current FindGMP.cmake (Cairo, QGLViewer, Magick++), would need to be improved to generate imported target GMP::GMP instead of just GMP_INCLUDE_DIR and GMP_LIBRARIES.

For a short tutorial about this topic and other modern CMake areas: It’s Time To Do CMake Right | Pablo Arias

@dcoeurjo
Copy link
Member

Thanks @phcerdan for the link.. it looks like Pablo Arias "Don't do that" example looks pretty similar to the current DGtal setting ;)

@dcoeurjo
Copy link
Member

Very intersting reading

@phcerdan
Copy link
Member Author

Thanks @phcerdan for the link.. it looks like Pablo Arias "Don't do that" example looks pretty similar to the current DGtal setting ;)

Hehe a bit, at least now we don't modify CXX_FLAGS or use global include_directories, link_libraries!
The good thing is that the core DGtal (without those dependencies) is indeed relocatable, but some tweaking would be needed if we are interested in shipping DGtal with those extra deps.

@phcerdan phcerdan changed the title CMake: Create realocatable packages: improve Find[GMP, CAIRO, QGLViewer, Magick++ FFTW3].cmake to create imported targets. CMake: Create relocatable packages: improve Find[GMP, CAIRO, QGLViewer, Magick++ FFTW3].cmake to create imported targets. Jan 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants