1# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2# file Copyright.txt or https://cmake.org/licensing for details.
3
4#[=======================================================================[.rst:
5SelectLibraryConfigurations
6---------------------------
7
8.. code-block:: cmake
9
10  select_library_configurations(basename)
11
12This macro takes a library base name as an argument, and will choose
13good values for the variables
14
15::
16
17  basename_LIBRARY
18  basename_LIBRARIES
19  basename_LIBRARY_DEBUG
20  basename_LIBRARY_RELEASE
21
22depending on what has been found and set.
23
24If only ``basename_LIBRARY_RELEASE`` is defined, ``basename_LIBRARY`` will
25be set to the release value, and ``basename_LIBRARY_DEBUG`` will be set
26to ``basename_LIBRARY_DEBUG-NOTFOUND``.  If only ``basename_LIBRARY_DEBUG``
27is defined, then ``basename_LIBRARY`` will take the debug value, and
28``basename_LIBRARY_RELEASE`` will be set to ``basename_LIBRARY_RELEASE-NOTFOUND``.
29
30If the generator supports configuration types, then ``basename_LIBRARY``
31and ``basename_LIBRARIES`` will be set with debug and optimized flags
32specifying the library to be used for the given configuration.  If no
33build type has been set or the generator in use does not support
34configuration types, then ``basename_LIBRARY`` and ``basename_LIBRARIES``
35will take only the release value, or the debug value if the release one
36is not set.
37#]=======================================================================]
38
39# This macro was adapted from the FindQt4 CMake module and is maintained by Will
40# Dicharry <[email protected]>.
41
42macro(select_library_configurations basename)
43    if(NOT ${basename}_LIBRARY_RELEASE)
44        set(${basename}_LIBRARY_RELEASE "${basename}_LIBRARY_RELEASE-NOTFOUND" CACHE FILEPATH "Path to a library.")
45    endif()
46    if(NOT ${basename}_LIBRARY_DEBUG)
47        set(${basename}_LIBRARY_DEBUG "${basename}_LIBRARY_DEBUG-NOTFOUND" CACHE FILEPATH "Path to a library.")
48    endif()
49
50    get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
51    if( ${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE AND
52           NOT ${basename}_LIBRARY_DEBUG STREQUAL ${basename}_LIBRARY_RELEASE AND
53           ( _isMultiConfig OR CMAKE_BUILD_TYPE ) )
54        # if the generator is multi-config or if CMAKE_BUILD_TYPE is set for
55        # single-config generators, set optimized and debug libraries
56        set( ${basename}_LIBRARY "" )
57        foreach( _libname IN LISTS ${basename}_LIBRARY_RELEASE )
58            list( APPEND ${basename}_LIBRARY optimized "${_libname}" )
59        endforeach()
60        foreach( _libname IN LISTS ${basename}_LIBRARY_DEBUG )
61            list( APPEND ${basename}_LIBRARY debug "${_libname}" )
62        endforeach()
63    elseif( ${basename}_LIBRARY_RELEASE )
64        set( ${basename}_LIBRARY ${${basename}_LIBRARY_RELEASE} )
65    elseif( ${basename}_LIBRARY_DEBUG )
66        set( ${basename}_LIBRARY ${${basename}_LIBRARY_DEBUG} )
67    else()
68        set( ${basename}_LIBRARY "${basename}_LIBRARY-NOTFOUND")
69    endif()
70
71    set( ${basename}_LIBRARIES "${${basename}_LIBRARY}" )
72
73    if( ${basename}_LIBRARY )
74        set( ${basename}_FOUND TRUE )
75    endif()
76
77    mark_as_advanced( ${basename}_LIBRARY_RELEASE
78        ${basename}_LIBRARY_DEBUG
79    )
80endmacro()
81