1 # select_library_configurations( basename )
3 # This macro takes a library base name as an argument, and will choose good
4 # values for basename_LIBRARY, basename_LIBRARIES, basename_LIBRARY_DEBUG, and
5 # basename_LIBRARY_RELEASE depending on what has been found and set. If only
6 # basename_LIBRARY_RELEASE is defined, basename_LIBRARY, basename_LIBRARY_DEBUG,
7 # and basename_LIBRARY_RELEASE will be set to the release value. If only
8 # basename_LIBRARY_DEBUG is defined, then basename_LIBRARY,
9 # basename_LIBRARY_DEBUG and basename_LIBRARY_RELEASE will take the debug value.
11 # If the generator supports configuration types, then basename_LIBRARY and
12 # basename_LIBRARIES will be set with debug and optimized flags specifying the
13 # library to be used for the given configuration. If no build type has been set
14 # or the generator in use does not support configuration types, then
15 # basename_LIBRARY and basename_LIBRARIES will take only the release values.
17 #=============================================================================
18 # Copyright 2009 Will Dicharry <wdicharry@stellarscience.com>
19 # Copyright 2005-2009 Kitware, Inc.
21 # Distributed under the OSI-approved BSD License (the "License");
22 # see accompanying file Copyright.txt for details.
24 # This software is distributed WITHOUT ANY WARRANTY; without even the
25 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
26 # See the License for more information.
27 #=============================================================================
28 # (To distribute this file outside of CMake, substitute the full
29 # License text for the above reference.)
31 # This macro was adapted from the FindQt4 CMake module and is maintained by Will
32 # Dicharry <wdicharry@stellarscience.com>.
34 # Utility macro to check if one variable exists while another doesn't, and set
35 # one that doesn't exist to the one that exists.
36 macro( _set_library_name basename GOOD BAD )
37 if( ${basename}_LIBRARY_${GOOD} AND NOT ${basename}_LIBRARY_${BAD} )
38 set( ${basename}_LIBRARY_${BAD} ${${basename}_LIBRARY_${GOOD}} )
39 set( ${basename}_LIBRARY ${${basename}_LIBRARY_${GOOD}} )
40 set( ${basename}_LIBRARIES ${${basename}_LIBRARY_${GOOD}} )
44 macro( select_library_configurations basename )
45 # if only the release version was found, set the debug to be the release
47 _set_library_name( ${basename} RELEASE DEBUG )
48 # if only the debug version was found, set the release value to be the
50 _set_library_name( ${basename} DEBUG RELEASE )
52 # Set a default case, which will come into effect if
53 # -no build type is set and the generator only supports one build type
54 # at a time (i.e. CMAKE_CONFIGURATION_TYPES is false)
55 # -${basename}_LIBRARY_DEBUG and ${basename}_LIBRARY_RELEASE are the same
56 # -${basename}_LIBRARY_DEBUG and ${basename}_LIBRARY_RELEASE are both empty
57 set( ${basename}_LIBRARY ${${basename}_LIBRARY_RELEASE} )
58 set( ${basename}_LIBRARIES ${${basename}_LIBRARY_RELEASE} )
60 if( ${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE AND
61 NOT ${basename}_LIBRARY_DEBUG STREQUAL ${basename}_LIBRARY_RELEASE )
62 # if the generator supports configuration types or CMAKE_BUILD_TYPE
63 # is set, then set optimized and debug options.
64 if( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE )
65 set( ${basename}_LIBRARY )
66 foreach( _libname IN LISTS ${basename}_LIBRARY_RELEASE )
67 list( APPEND ${basename}_LIBRARY optimized "${_libname}" )
69 foreach( _libname IN LISTS ${basename}_LIBRARY_DEBUG )
70 list( APPEND ${basename}_LIBRARY debug "${_libname}" )
72 set( ${basename}_LIBRARIES "${${basename}_LIBRARY}" )
76 set( ${basename}_LIBRARY ${${basename}_LIBRARY} CACHE FILEPATH
77 "The ${basename} library" )
79 if( ${basename}_LIBRARY )
80 set( ${basename}_FOUND TRUE )
83 mark_as_advanced( ${basename}_LIBRARY
84 ${basename}_LIBRARY_RELEASE
85 ${basename}_LIBRARY_DEBUG