0

I have a project "A" that depends on another project "B".

  • ProjectB installs some headers, for example B1.h, B2.h.
  • ProjectA tries to create a Python wrapper of B1.h and B2.h, using SWIG.

ProjectA uses :

  • ExternalProject_Add(ProjectB ...) to compile and install ProjectB somwhere into the binary dir.
  • Swig_Add_Library(ProjectB ...) to create the Python wrapper ; this command creates a target _ProjectB.

I want to be sure that B1.h, B2.h are installed before SWIG runs, thus I added the following command : add_dependencies(_ProjectB ProjectA)

On Windows, this works fine.

However on Linux, the add_dependencies command is not taken into account, which gives :

.../ProjectA.i: 111: Error: Unable to find 'B1.h'
.../ProjectA.i: 112: Error: Unable to find 'B2.h'

I am sure that the include dir given to SWIG is correct: indeed, when I run make for the second time, this works because ProjectB was successfully installed by the first call to make.

I use CMake 3.13.5.

Any help would be great !

ConanLord
  • 73
  • 5
  • "I use CMake 3.13.5"... **why?** Use the latest version. [It's unbelievably easy to upgrade.](https://alexreinking.com/blog/how-to-use-cmake-without-the-agonizing-pain-part-1.html) – Alex Reinking Jul 27 '21 at 16:13
  • I use legacy code that is not compatible with recent CMake versions. Anyway, I tried my specific issue with a recent CMake (3.19.4) and get the same. – ConanLord Jul 29 '21 at 09:54

1 Answers1

0

I found a workaround : on Linux, I use : add_dependencies(ProjectB_swig_compilation ProjectA)

However, the target ProjectB_swig_compilation does not exist on Windows (I don't understand why since I use the same version of CMake on both Linux and Windows).

Eventually, here is what I did in my CMakeLists.txt :

if (WIN32 AND NOT MINGW)
   add_dependencies(_ProjectB ProjectA)
else ()
   add_dependencies(ProjectB_swig_compilation ProjectA)
endif ()
ConanLord
  • 73
  • 5