I have a CMake project, which includes links to two libraries, say A
and B
(in fact, it is more than two, and one of them is forced material, but it does not really matter here). Both of them are located through FindSomething.cmake
scripts that (correctly) populate standard CMake variables, such as added directories, through
INCLUDE_DIRECTORIES(${A_INCLUDE_DIRS}) INCLUDE_DIRECTORIES(${B_INCLUDE_DIRS})
and communication is later done through
TARGET_LINK_LIBRARIES(mytarget ${A_LIBRARIES} ${B_LIBRARIES})
Now the problem is that both libraries can either be in the user location or in the system directories (I am on Linux, by the way, CMake 2.8.2) - or both. Let's say A
is located only in $HOME/usr/include
and $HOME/usr/lib
, and B
(boost in my case) is located both on the system paths ( /usr/include
and on /usr/lib
) And in user paths - in different versions, Search scripts can be found to find either system or user library B
, this works.
The problem starts when I want to associate B
with system paths. ${B_INCLUDE_DIRS}
and ${B_LIBRARIES}
correctly point to system-wide locations of headers and libraries. But thereβs still ${A_INCLUDE_DIRS}
that points to a non-system directory, and ultimately, headers for library B
are taken from this place, and the link for B
uses the version from the system paths (via ${B_LIBRARIES}
), leading to conflicts, i.e. error binding.
Reordering the INCLUDE_DIRECTORIES
statements does not seem to change anything. I checked the origin of the characters that cause binding errors via nm --line-numbers
in object files.
What can I do? Is there a trick for
- forcibly organizes include directories (even if it means it will take precedence over the system path, although there is also a user-defined location)?
- tell CMake to use
${A_INCLUDE_DIRS}
for all the headers from A
and ${B_INCLUDE_DIRS}
for all the headers from B
?
source share