SelectLibraryConfigurations: Use -NOTFOUND instead of copying the vars

If one of the libraries (_DEBUG or _RELEASE) is not set, the value is
set to the value of the other one.  FindQt4, from which the macro is
extracted, sets the values to XXX_LIBRARY_{DEBUG,RELEASE}-NOTFOUND
instead.  In both cases the XXX_LIBRARY is correct, but using NOTFOUND
makes it easier to understand which one is missing.

Update Tests/CMakeOnly/SelectLibraryConfigurations with the new logic.
This commit is contained in:
Daniele E. Domenichelli 2013-07-08 17:37:18 +02:00 committed by Brad King
parent 07b44e7a1f
commit 04d4dc3374
2 changed files with 31 additions and 41 deletions

View File

@ -3,16 +3,18 @@
# This macro takes a library base name as an argument, and will choose good # This macro takes a library base name as an argument, and will choose good
# values for basename_LIBRARY, basename_LIBRARIES, basename_LIBRARY_DEBUG, and # values for basename_LIBRARY, basename_LIBRARIES, basename_LIBRARY_DEBUG, and
# basename_LIBRARY_RELEASE depending on what has been found and set. If only # basename_LIBRARY_RELEASE depending on what has been found and set. If only
# basename_LIBRARY_RELEASE is defined, basename_LIBRARY, basename_LIBRARY_DEBUG, # basename_LIBRARY_RELEASE is defined, basename_LIBRARY will be set to the
# and basename_LIBRARY_RELEASE will be set to the release value. If only # release value, and basename_LIBRARY_DEBUG will be set to
# basename_LIBRARY_DEBUG is defined, then basename_LIBRARY, # basename_LIBRARY_DEBUG-NOTFOUND. If only basename_LIBRARY_DEBUG is defined,
# basename_LIBRARY_DEBUG and basename_LIBRARY_RELEASE will take the debug value. # then basename_LIBRARY will take the debug value, and basename_LIBRARY_RELEASE
# will be set to basename_LIBRARY_RELEASE-NOTFOUND.
# #
# If the generator supports configuration types, then basename_LIBRARY and # If the generator supports configuration types, then basename_LIBRARY and
# basename_LIBRARIES will be set with debug and optimized flags specifying the # basename_LIBRARIES will be set with debug and optimized flags specifying the
# library to be used for the given configuration. If no build type has been set # library to be used for the given configuration. If no build type has been set
# or the generator in use does not support configuration types, then # or the generator in use does not support configuration types, then
# basename_LIBRARY and basename_LIBRARIES will take only the release values. # basename_LIBRARY and basename_LIBRARIES will take only the release value, or
# the debug value if the release one is not set.
#============================================================================= #=============================================================================
# Copyright 2009 Will Dicharry <wdicharry@stellarscience.com> # Copyright 2009 Will Dicharry <wdicharry@stellarscience.com>
@ -31,37 +33,19 @@
# This macro was adapted from the FindQt4 CMake module and is maintained by Will # This macro was adapted from the FindQt4 CMake module and is maintained by Will
# Dicharry <wdicharry@stellarscience.com>. # Dicharry <wdicharry@stellarscience.com>.
# Utility macro to check if one variable exists while another doesn't, and set
# one that doesn't exist to the one that exists.
macro( _set_library_name basename GOOD BAD )
if( ${basename}_LIBRARY_${GOOD} AND NOT ${basename}_LIBRARY_${BAD} )
set( ${basename}_LIBRARY_${BAD} ${${basename}_LIBRARY_${GOOD}} )
set( ${basename}_LIBRARY ${${basename}_LIBRARY_${GOOD}} )
set( ${basename}_LIBRARIES ${${basename}_LIBRARY_${GOOD}} )
endif()
endmacro()
macro( select_library_configurations basename ) macro( select_library_configurations basename )
# if only the release version was found, set the debug to be the release if(NOT ${basename}_LIBRARY_RELEASE)
# version. set(${basename}_LIBRARY_RELEASE "${basename}_LIBRARY_RELEASE-NOTFOUND" CACHE FILEPATH "Path to a library.")
_set_library_name( ${basename} RELEASE DEBUG ) endif()
# if only the debug version was found, set the release value to be the if(NOT ${basename}_LIBRARY_DEBUG)
# debug value. set(${basename}_LIBRARY_DEBUG "${basename}_LIBRARY_DEBUG-NOTFOUND" CACHE FILEPATH "Path to a library.")
_set_library_name( ${basename} DEBUG RELEASE ) endif()
# Set a default case, which will come into effect if
# -no build type is set and the generator only supports one build type
# at a time (i.e. CMAKE_CONFIGURATION_TYPES is false)
# -${basename}_LIBRARY_DEBUG and ${basename}_LIBRARY_RELEASE are the same
# -${basename}_LIBRARY_DEBUG and ${basename}_LIBRARY_RELEASE are both empty
set( ${basename}_LIBRARY ${${basename}_LIBRARY_RELEASE} )
set( ${basename}_LIBRARIES ${${basename}_LIBRARY_RELEASE} )
if( ${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE AND if( ${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE AND
NOT ${basename}_LIBRARY_DEBUG STREQUAL ${basename}_LIBRARY_RELEASE ) NOT ${basename}_LIBRARY_DEBUG STREQUAL ${basename}_LIBRARY_RELEASE AND
( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE ) )
# if the generator supports configuration types or CMAKE_BUILD_TYPE # if the generator supports configuration types or CMAKE_BUILD_TYPE
# is set, then set optimized and debug options. # is set, then set optimized and debug options.
if( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE )
set( ${basename}_LIBRARY "" ) set( ${basename}_LIBRARY "" )
foreach( _libname IN LISTS ${basename}_LIBRARY_RELEASE ) foreach( _libname IN LISTS ${basename}_LIBRARY_RELEASE )
list( APPEND ${basename}_LIBRARY optimized "${_libname}" ) list( APPEND ${basename}_LIBRARY optimized "${_libname}" )
@ -69,9 +53,15 @@ macro( select_library_configurations basename )
foreach( _libname IN LISTS ${basename}_LIBRARY_DEBUG ) foreach( _libname IN LISTS ${basename}_LIBRARY_DEBUG )
list( APPEND ${basename}_LIBRARY debug "${_libname}" ) list( APPEND ${basename}_LIBRARY debug "${_libname}" )
endforeach() endforeach()
elseif( ${basename}_LIBRARY_RELEASE )
set( ${basename}_LIBRARY ${${basename}_LIBRARY_RELEASE} )
elseif( ${basename}_LIBRARY_DEBUG )
set( ${basename}_LIBRARY ${${basename}_LIBRARY_DEBUG} )
else()
set( ${basename}_LIBRARY "${basename}_LIBRARY-NOTFOUND")
endif()
set( ${basename}_LIBRARIES "${${basename}_LIBRARY}" ) set( ${basename}_LIBRARIES "${${basename}_LIBRARY}" )
endif()
endif()
if( ${basename}_LIBRARY ) if( ${basename}_LIBRARY )
set( ${basename}_FOUND TRUE ) set( ${basename}_FOUND TRUE )

View File

@ -29,7 +29,7 @@ if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug) set(CMAKE_BUILD_TYPE Debug)
endif () endif ()
check_slc(empty "") check_slc(empty "empty_LIBRARY-NOTFOUND")
set(OPTONLY_LIBRARY_RELEASE "opt") set(OPTONLY_LIBRARY_RELEASE "opt")
check_slc(OPTONLY "opt") check_slc(OPTONLY "opt")