0

One of the canonical ways to include libraries that do not give support for CMake is to fallback to pkg-config.

For example the FFTW library can be found in this way:

find_package(PkgConfig)

pkg_search_module(FFTW REQUIRED fftw3 IMPORTED_TARGET)

and made available by

include_directories(PkgConfig::FFTW)
link_libraries(PkgConfig::FFTW)

However, in some configurations, pkg-config does not return an include path (I guess because if the library headers are in a system path, it is not needed to add an -I option).

The problem is that in such a case, CMake attaches the option -IPkgConfig::FFTW which is an incorrect path.

In fact the compiler (in my case g++) complains, and, with certain warning levels, produces an error.

How can I prevent CMake or the pkg-config CMake package from generating these bad include paths?

codeling
  • 11,056
  • 4
  • 42
  • 71
alfC
  • 14,261
  • 4
  • 67
  • 118
  • Use another canonical (more canonical?) way: write a find module yourself? – ixSci Apr 21 '22 at 06:40
  • 3
    Also if you use `target_link_libraries(target PkgConfig::FFTW)` instead of your global commands you should not have the problem described in the first place. _Maybe_ it should also work with just `link_libraries`, that I'm not sure. What I'm sure about is that you should not have `include_directories(PkgConfig::FFTW)` at all. – ixSci Apr 21 '22 at 06:44
  • 1
    according to the doc you have `_INCLUDE_DIRS` the '-I' preprocessor flags (without the '-I') ref: https://cmake.org/cmake/help/latest/module/FindPkgConfig.html#command:pkg_check_modules – Mizux Apr 21 '22 at 12:48
  • 1
    and you have https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/FindPkgConfig.cmake#L313-315 so PkgConfig::FFTW should already have the property `INTERFACE_INCLUDE_DIRECTORIES` correctly set. – Mizux Apr 21 '22 at 12:51
  • related https://stackoverflow.com/questions/44277114/how-to-use-fftw-library-in-cmake – alfC Apr 23 '22 at 18:33
  • @ixSci, ok, I use (only) `target_link_libraries(target_name PRIVATE PkgConfig::FFTW)`. I guess the real test will be in a system where pkg-config returns an actual path. – alfC Apr 23 '22 at 18:34

0 Answers0