Search code examples
cmakecgalmsys2

CMake Error: Target contains relative path in its INTERFACE_INCLUDE_DIRECTORIES


I mean to compile example Advancing_front_surface_reconstruction from the CGAL package under Win10 + PortableApps Msys2. For the library itself I use a precompiled package ($ pacman -Qs cgal gives local/mingw-w64-x86_64-cgal 4.14-1). I used to be able to do that in my previous PC, see details below.

After transferring everything to a new PC (simply copying, it is PortableApps), I made a system update in Msys2 (required for other reasons). I proceed as usual: mkdir build, cd build, ccmake ... Selecting Release mode, and verbosity ON, upon pressing g to generate files I got

 CMake Error in CMakeLists.txt:
   Imported target "CGAL::CGAL" includes non-existent path
     "C:/building/msys64/mingw64/include"
   in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:
   * The path was deleted, renamed, or moved to another location.
   * An install or uninstall procedure did not complete successfully.
   * The installation package was faulty and references files it does not
   provide.

Upon pressing e to exit the error message, the ccmake gui was exited and there were no files generated.

After googling a bit, this suggested creating the missing dirs, which seems merely a workaround (I did not try adapting this). I created those dirs, and then I got

 CMake Error in CMakeLists.txt:
   Target "CGAL::CGAL" contains relative path in its
   INTERFACE_INCLUDE_DIRECTORIES:

     "C:/building/msys64/mingw64/include"

How can I fix this? I found no suitable answers around.

Possibly related links, but which I found no way of relating to a suitable solution:

https://gitlab.kitware.com/cmake/cmake/commit/634bb33f3aa3b7f2181a896c025976b52171524a

https://cmake.org/cmake/help/v3.12/manual/cmake-buildsystem.7.html

NOTE: The same happened with other examples.

EDIT: I do not know what changed, but now upon pressing e to exit the error message (see above) all generated files are present, including the Makefile. So I can proceed as described below in Previous state of affairs. This happens either with or without the missing dirs (the error message changes, but I can generate my executables). AFAICT, the only related change is that I have just installed packages , mingw-w64-x86_64-eigen3 (3.3.7-1) , mingw-w64-x86_64-suitesparse (5.4.0-1) , mingw-w64-x86_64-lapack (3.8.0-5) , but I would not think this should matter.


Previous state of affairs

To compile and link CGAL examples, in my previous PC, some tweaking was needed. Compilation went fine, but linking required a couple of tweaks. An example command line produced for linking reads

 /mingw64/bin/c++.exe -O3 -DNDEBUG  -Wl,--enable-auto-import CMakeFiles/reconstruction_structured.dir/reconstruction_structured.cpp.o  -o reconstruction_structured.exe -Wl,--out-implib,libreconstruction_structured.dll.a -Wl,--major-image-version,0,--minor-image-version,0 /mingw64/lib/lib/libmpfr.a /mingw64/lib/lib/libgmp.dll.a /mingw64/lib/lib/libCGAL.dll.a -lC:/building/msys64/mingw64/lib/libgmp.dll.a -lC:/building/msys64/mingw64/lib/libmpfr.a

The two types of required fixes are

  1. Replacing /mingw64/lib/lib/ with /mingw64/lib/ in every (link.txt;build.make) file.

  2. Replacing flag -lC:/building/msys64/mingw64/lib/libgmp.dll.a with -lgmp in every link.txt file. Similarly for -lmpfr.


Solution

  • Run this command to find all the places in the CGAL CMake files where the erroneous directory C:/building/ is mentioned:

    grep -r '/building/' /mingw64/lib/cmake/CGAL
    

    For each instance, either delete it or replace it with something more appropriate.

    (Note: I haven't tried this myself.)

    This erroneous directory is a general issue with MSYS2 which I attempted to fix at one point.