[cmake-developers] [PATCH] FindProtobuf: fix wrong library list for Unix
Antonio Pérez Barrero
apbarrero at gmail.com
Tue Feb 9 05:10:28 EST 2016
>
> On 02/08/2016 04:24 PM, Antonio Pérez Barrero wrote:
> > Yes, it is possible, but currently it's not looking for the debug
> > library with a different name, just in a different path that is
> > unlikely to exist in a Unix system.
>
> The fact that a separate find_library is called for it and the result
> is stored in a separate (user-settable) cache entry means that it is
> possible to get two different values. This convention is well established
> in several find modules.
>
> > Having the PROTOBUF_LIBRARIES variable getting the afore mentioned
> > value messes up the client code using `find_package(Protobuf)` on Unix.
>
> The only supported use for PROTOBUF_LIBRARIES is to pass it to
> target_link_libraries, and that interprets the 'optimized' and 'debug'
> keywords. This is shown in the module documentation example:
>
> target_link_libraries(bar ${PROTOBUF_LIBRARIES})
>
> The documentation makes no other guarantees about the variable value.
>
Thanks for your explanantion, that makes sense. I had issues because I was
appending the value of PROTOBUF_LIBRARIES to a list and then removing
duplicates before calling `target_link_libraries(bar ${LIST})`. So when the
PROTOBUF_LIBRARIES values was
`optimized;/usr/lib/libprotobuf.so;debug;/usr/lib/libprotobuf.so` I was
missing the link flag for /usr/lib/libprotobuf.so in Debug builds. Skipping
the duplicates removal step solves my issue.
Anyway, the root cause is the `find_library` is finding the same library
for optimized and debug configuration. So, would a patch like this be
benefial?
diff --git a/Modules/FindProtobuf.cmake b/Modules/FindProtobuf.cmake
index 2f13b09..35929a4 100644
--- a/Modules/FindProtobuf.cmake
+++ b/Modules/FindProtobuf.cmake
@@ -224,7 +224,7 @@ function(_protobuf_find_libraries name filename)
PATHS
${PROTOBUF_SRC_ROOT_FOLDER}/vsprojects/${_PROTOBUF_ARCH_DIR}Debug)
mark_as_advanced(${name}_LIBRARY_DEBUG)
- if(NOT ${name}_LIBRARY_DEBUG)
+ if((NOT ${name}_LIBRARY_DEBUG) OR (${name}_LIBRARY STREQUAL
${name}_LIBRARY_DEBUG))
# There is no debug library
set(${name}_LIBRARY_DEBUG ${${name}_LIBRARY} PARENT_SCOPE)
set(${name}_LIBRARIES ${${name}_LIBRARY} PARENT_SCOPE)
---
Thanks,
Antonio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160209/4bd99335/attachment.html>
More information about the cmake-developers
mailing list