Search code examples
c++cmakepoppler

Using poppler as a subproject in Cmake with `CMAKE_MODULE_PATH` set incorrectly


I'm new to CMake to I'm not sure what I'm doing

I'm using poppler as a library via CMake for my application. I've imported it as a submodule.

If I include popper in my top-level CMake file using add_subdirectory(...), it get the following errors

[cmake] CMake Error at external/poppler/CMakeLists.txt:7 (include):
[cmake]   include could not find requested file:
[cmake] 
[cmake]     PopplerDefaults
[cmake] 
[cmake] 
[cmake] CMake Error at external/poppler/CMakeLists.txt:8 (include):

This is most likely because the CMAKE_MODULE_PATH is incorrect.

After some digging, it looks like poppler is setting the module path instead of appending to it.

https://gitlab.freedesktop.org/poppler/poppler/-/blob/master/CMakeLists.txt#L5

So I can't really override it it seems.

My (probably overly complicated) setup is here, which the poppler line commented out. https://github.com/bdurrani/cmake-test/blob/master/CMakeLists.txt#L69

This works fine if I run cmake from within the poppler folder.

Is there a way around this? How to you handle such scenarios?


Solution

  • So in your CMakeLists.txt just store and restore the CMAKE_MODULE_PATH before including the subproject.

    set(tmp ${CMAKE_MODULE_PATH})
    add_subdirectory(...)
    # suffix the poppler stuff too.
    set(CMAKE_MODULE_PATH "${tmp};${CMAKE_MODULE_PATH}")
    

    You could also separately notify developers of the poppler project of the issue, or at best create a patch for them that Will fix the problem.