FindProtobuf: prevent redundant PROTOBUF_LIBRARIES

Before this change, the variable PROTOBUF_LIBRARIES might get redundant
value for debug and optimized configurations, e.g.
`optimized;/usr/lib/libprotobuf.so;debug;/usr/lib/libprotobuf.so`.
This commit is contained in:
Antonio Perez Barrero 2016-02-11 09:24:27 +01:00 committed by Brad King
parent d83abbf9e3
commit 51b0501a7f
1 changed files with 21 additions and 20 deletions

View File

@ -210,32 +210,33 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_PROTOBUF_ARCH_DIR x64/) set(_PROTOBUF_ARCH_DIR x64/)
endif() endif()
include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
# Internal function: search for normal library as well as a debug one # Internal function: search for normal library as well as a debug one
# if the debug one is specified also include debug/optimized keywords # if the debug one is specified also include debug/optimized keywords
# in *_LIBRARIES variable # in *_LIBRARIES variable
function(_protobuf_find_libraries name filename) function(_protobuf_find_libraries name filename)
find_library(${name}_LIBRARY if(${name}_LIBRARIES)
NAMES ${filename} # Use result recorded by a previous call.
PATHS ${PROTOBUF_SRC_ROOT_FOLDER}/vsprojects/${_PROTOBUF_ARCH_DIR}Release) return()
mark_as_advanced(${name}_LIBRARY) elseif(${name}_LIBRARY)
# Honor cache entry used by CMake 3.5 and lower.
set(${name}_LIBRARIES "${${name}_LIBRARY}" PARENT_SCOPE)
else()
find_library(${name}_LIBRARY_RELEASE
NAMES ${filename}
PATHS ${PROTOBUF_SRC_ROOT_FOLDER}/vsprojects/${_PROTOBUF_ARCH_DIR}Release)
mark_as_advanced(${name}_LIBRARY_RELEASE)
find_library(${name}_LIBRARY_DEBUG find_library(${name}_LIBRARY_DEBUG
NAMES ${filename} NAMES ${filename}
PATHS ${PROTOBUF_SRC_ROOT_FOLDER}/vsprojects/${_PROTOBUF_ARCH_DIR}Debug) PATHS ${PROTOBUF_SRC_ROOT_FOLDER}/vsprojects/${_PROTOBUF_ARCH_DIR}Debug)
mark_as_advanced(${name}_LIBRARY_DEBUG) mark_as_advanced(${name}_LIBRARY_DEBUG)
if(NOT ${name}_LIBRARY_DEBUG) select_library_configurations(${name})
# There is no debug library set(${name}_LIBRARY "${${name}_LIBRARY}" PARENT_SCOPE)
set(${name}_LIBRARY_DEBUG ${${name}_LIBRARY} PARENT_SCOPE) set(${name}_LIBRARIES "${${name}_LIBRARIES}" PARENT_SCOPE)
set(${name}_LIBRARIES ${${name}_LIBRARY} PARENT_SCOPE) endif()
else()
# There IS a debug library
set(${name}_LIBRARIES
optimized ${${name}_LIBRARY}
debug ${${name}_LIBRARY_DEBUG}
PARENT_SCOPE
)
endif()
endfunction() endfunction()
# Internal function: find threads library # Internal function: find threads library