DGtal
DGtal copied to clipboard
CMake: Create relocatable packages: improve Find[GMP, CAIRO, QGLViewer, Magick++ FFTW3].cmake to create imported targets.
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
Thanks @phcerdan for the link.. it looks like Pablo Arias "Don't do that" example looks pretty similar to the current DGtal setting ;)
Very intersting reading
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.