[CMake] find*.cmake config files, and Qt4 while cross compiling.

Miller Henry MillerHenry at JohnDeere.com
Fri Jul 15 16:51:49 EDT 2016


I'm going to ask two questions, but a good answer to the first will make the second question redundant.

I work with several different cmake projects that are cross compiled, and they depend on each other.  Each project creates a cmake config, so we can use find_package to find the contents.  Up until now we have been setting LINK_INTERFACE_LIBRARIES to "" SET_TARGET_PROPERTIES(${projectName} PROPERTIES LINK_INTERFACE_LIBRARIES ""), but for a few years this has required us to set CMP0022 to OLD.  Now that we no longer support older versions of CMake I figured it was time to set this to NEW (2.12 is minimum we use and most of us are up to 3.2 (I have not tried anything newer than 3.2).

This works great for libraries that provide a cmake config file when we link a library to libFoo the config includes the need to link to libFoo. However any project that we use a FindXXX.cmake to find (including cmake included like FindLibXml2.cmake) the package the config file says you need to link to /home/hank/sysroot/path/to/libFoo.  When I package this build and give it to a different developer to install into his sysroot it fails because the correct path for him is /home/joe/some/other/dir/sysroot/path/to/libFoo. I found a work around: in target_link_libraries make libFoo a private link.  This feels wrong though, I feel that cmake should handle this automatically.  (I'm fine with mark it as private, anything better is probably not implementable)

First question, how can I use libraries from a Find*.cmake file without having to mark it as private in every target_link_libraries call.

I couldn't figure this out, but I was able to mitigate it for the most common package we link to.  For Qt4 is you have a choice, what we were doing was:
  Find_package(Qt4 REQUIRED)
  INCLUDE(${QT_USE_FILE}
  TARGET_LINK_LIBRARIES(MyProject ${QT_LIBRARIES})
If you use this for you get the full path to each library in your sysroot.

However if you do:
  Find_package(Qt4 REQUIRED)
  TARGET_LINK_LIBRARIES(Qt4:QtGui ...)
You get just the Qt library, which would be what I want except that now the INCLUDE_DIRECTORIES for Qt libraries are not SYSTEM libraries and so I'm getting a lot of compiler warnings in qt header files which I cannot fix.

Second question: how can I use the TARGET_LINK_LIBRARIES(Qt4:QtGui...) form and get the qt headers as system libraries?



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160715/4752ce99/attachment.html>


More information about the CMake mailing list