[cmake-developers] [PATCH] FindProtobuf: prevent redundant PROTOBUF_LIBRARIES

2016-02-11 Thread Antonio Perez Barrero
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'
---
 Modules/FindProtobuf.cmake | 39 +++
 1 file changed, 19 insertions(+), 20 deletions(-)

diff --git a/Modules/FindProtobuf.cmake b/Modules/FindProtobuf.cmake
index 2f13b09..02aca1c 100644
--- a/Modules/FindProtobuf.cmake
+++ b/Modules/FindProtobuf.cmake
@@ -213,28 +213,27 @@ endif()
 # Internal function: search for normal library as well as a debug one
 #if the debug one is specified also include debug/optimized keywords
 #in *_LIBRARIES variable
+include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations)
+
 function(_protobuf_find_libraries name filename)
-   find_library(${name}_LIBRARY
-   NAMES ${filename}
-   PATHS 
${PROTOBUF_SRC_ROOT_FOLDER}/vsprojects/${_PROTOBUF_ARCH_DIR}Release)
-   mark_as_advanced(${name}_LIBRARY)
-
-   find_library(${name}_LIBRARY_DEBUG
-   NAMES ${filename}
-   PATHS ${PROTOBUF_SRC_ROOT_FOLDER}/vsprojects/${_PROTOBUF_ARCH_DIR}Debug)
-   mark_as_advanced(${name}_LIBRARY_DEBUG)
-
-   if(NOT ${name}_LIBRARY_DEBUG)
-  # There is no debug library
-  set(${name}_LIBRARY_DEBUG ${${name}_LIBRARY} PARENT_SCOPE)
-  set(${name}_LIBRARIES ${${name}_LIBRARY} PARENT_SCOPE)
+   if(${name}_LIBRARY)
+   set(${name}_LIBRARIES "${${name}_LIBRARY}" PARENT_SCOPE)
else()
-  # There IS a debug library
-  set(${name}_LIBRARIES
-  optimized ${${name}_LIBRARY}
-  debug ${${name}_LIBRARY_DEBUG}
-  PARENT_SCOPE
-  )
+   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
+   NAMES ${filename}
+   PATHS 
${PROTOBUF_SRC_ROOT_FOLDER}/vsprojects/${_PROTOBUF_ARCH_DIR}Debug)
+   mark_as_advanced(${name}_LIBRARY_DEBUG)
+
+   select_library_configurations(${name})
+   set(${name}_LIBRARY_RELEASE ${${name}_LIBRARY_RELEASE} PARENT_SCOPE)
+   set(${name}_LIBRARY_DEBUG ${${name}_LIBRARY_DEBUG} PARENT_SCOPE)
+   set(${name}_LIBRARY ${${name}_LIBRARY} PARENT_SCOPE)
+   set(${name}_LIBRARIES ${${name}_LIBRARIES} PARENT_SCOPE)
endif()
 endfunction()
 
-- 
1.9.1

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers


Re: [cmake-developers] [PATCH] FindProtobuf: prevent redundant PROTOBUF_LIBRARIES

2016-02-10 Thread Rolf Eike Beer
Am Mittwoch, 10. Februar 2016, 10:36:31 schrieb Antonio Perez Barrero:
> 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'
> ---
>  Modules/FindProtobuf.cmake | 18 ++
>  1 file changed, 6 insertions(+), 12 deletions(-)
> 
> diff --git a/Modules/FindProtobuf.cmake b/Modules/FindProtobuf.cmake
> index 2f13b09..57c6e62 100644
> --- a/Modules/FindProtobuf.cmake
> +++ b/Modules/FindProtobuf.cmake
> @@ -213,6 +213,8 @@ endif()
>  # Internal function: search for normal library as well as a debug one
>  #if the debug one is specified also include debug/optimized keywords
>  #in *_LIBRARIES variable
> +include(SelectLibraryConfigurations)

For modules that are part of CMake use

  include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)

This makes sure exactly the version of SLC the module was designed to use will 
be used, i.e. those shipped with the exact same version of CMake.

Greetings,

Eike

signature.asc
Description: This is a digitally signed message part.
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Re: [cmake-developers] [PATCH] FindProtobuf: prevent redundant PROTOBUF_LIBRARIES

2016-02-10 Thread Brad King
On 02/10/2016 04:36 AM, Antonio Perez Barrero wrote:
> find_library(${name}_LIBRARY
[snip]
> +   select_library_configurations(${name})
> +   set(${name}_LIBRARY_DEBUG ${${name}_LIBRARY_DEBUG} PARENT_SCOPE)
> +   set(${name}_LIBRARY ${${name}_LIBRARY} PARENT_SCOPE)
> +   set(${name}_LIBRARIES ${${name}_LIBRARIES} PARENT_SCOPE)

Thanks.  IIRC select_library_configurations needs the two inputs
to be _LIBRARY_DEBUG and _LIBRARY_RELEASE.  We'll
have to change the first find_library call to use _RELEASE.
The whole block can be arranged in the form

 if(${name}_LIBRARY)
   set(${name}_LIBRARIES "${${name}_LIBRARY}")
 else()
   ...current block, but with _RELEASE name...
 endif()

in order to be compatible with build scripts that expect to
set just ${name}_LIBRARY in the cache.

-Brad

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers