cmake_modules/FindLibraryWithDebug.cmake
changeset 1843 16cdd1745b73
child 8442 535a00ca0d35
equal deleted inserted replaced
1842:96a4757dfeb8 1843:16cdd1745b73
       
     1 #
       
     2 #  FIND_LIBRARY_WITH_DEBUG
       
     3 #  -> enhanced FIND_LIBRARY to allow the search for an
       
     4 #     optional debug library with a WIN32_DEBUG_POSTFIX similar
       
     5 #     to CMAKE_DEBUG_POSTFIX when creating a shared lib
       
     6 #     it has to be the second and third argument
       
     7 
       
     8 # Copyright (c) 2007, Christian Ehrlicher, <ch.ehrlicher@gmx.de>
       
     9 # Redistribution and use is allowed according to the terms of the BSD license.
       
    10 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
       
    11 
       
    12 MACRO(FIND_LIBRARY_WITH_DEBUG var_name win32_dbg_postfix_name dgb_postfix libname)
       
    13 
       
    14   IF(NOT "${win32_dbg_postfix_name}" STREQUAL "WIN32_DEBUG_POSTFIX")
       
    15 
       
    16      # no WIN32_DEBUG_POSTFIX -> simply pass all arguments to FIND_LIBRARY
       
    17      FIND_LIBRARY(${var_name}
       
    18                   ${win32_dbg_postfix_name}
       
    19                   ${dgb_postfix}
       
    20                   ${libname}
       
    21                   ${ARGN}
       
    22      )
       
    23 
       
    24   ELSE(NOT "${win32_dbg_postfix_name}" STREQUAL "WIN32_DEBUG_POSTFIX")
       
    25 
       
    26     IF(NOT WIN32)
       
    27       # on non-win32 we don't need to take care about WIN32_DEBUG_POSTFIX
       
    28 
       
    29       FIND_LIBRARY(${var_name} ${libname} ${ARGN})
       
    30 
       
    31     ELSE(NOT WIN32)
       
    32 
       
    33       # 1. get all possible libnames
       
    34       SET(args ${ARGN})
       
    35       SET(newargs "")
       
    36       SET(libnames_release "")
       
    37       SET(libnames_debug "")
       
    38 
       
    39       LIST(LENGTH args listCount)
       
    40 
       
    41       IF("${libname}" STREQUAL "NAMES")
       
    42         SET(append_rest 0)
       
    43         LIST(APPEND args " ")
       
    44 
       
    45         FOREACH(i RANGE ${listCount})
       
    46           LIST(GET args ${i} val)
       
    47 
       
    48           IF(append_rest)
       
    49             LIST(APPEND newargs ${val})
       
    50           ELSE(append_rest)
       
    51             IF("${val}" STREQUAL "PATHS")
       
    52               LIST(APPEND newargs ${val})
       
    53               SET(append_rest 1)
       
    54             ELSE("${val}" STREQUAL "PATHS")
       
    55               LIST(APPEND libnames_release "${val}")
       
    56               LIST(APPEND libnames_debug   "${val}${dgb_postfix}")
       
    57             ENDIF("${val}" STREQUAL "PATHS")
       
    58           ENDIF(append_rest)
       
    59 
       
    60         ENDFOREACH(i)
       
    61 
       
    62       ELSE("${libname}" STREQUAL "NAMES")
       
    63 
       
    64         # just one name
       
    65         LIST(APPEND libnames_release "${libname}")
       
    66         LIST(APPEND libnames_debug   "${libname}${dgb_postfix}")
       
    67 
       
    68         SET(newargs ${args})
       
    69 
       
    70       ENDIF("${libname}" STREQUAL "NAMES")
       
    71 
       
    72       # search the release lib
       
    73       FIND_LIBRARY(${var_name}_RELEASE
       
    74                    NAMES ${libnames_release}
       
    75                    ${newargs}
       
    76       )
       
    77 
       
    78       # search the debug lib
       
    79       FIND_LIBRARY(${var_name}_DEBUG
       
    80                    NAMES ${libnames_debug}
       
    81                    ${newargs}
       
    82       )
       
    83 
       
    84       IF(${var_name}_RELEASE AND ${var_name}_DEBUG)
       
    85 
       
    86         # both libs found
       
    87         SET(${var_name} optimized ${${var_name}_RELEASE}
       
    88                         debug     ${${var_name}_DEBUG})
       
    89 
       
    90       ELSE(${var_name}_RELEASE AND ${var_name}_DEBUG)
       
    91 
       
    92         IF(${var_name}_RELEASE)
       
    93 
       
    94           # only release found
       
    95           SET(${var_name} ${${var_name}_RELEASE})
       
    96 
       
    97         ELSE(${var_name}_RELEASE)
       
    98 
       
    99           # only debug (or nothing) found
       
   100           SET(${var_name} ${${var_name}_DEBUG})
       
   101 
       
   102         ENDIF(${var_name}_RELEASE)
       
   103        
       
   104       ENDIF(${var_name}_RELEASE AND ${var_name}_DEBUG)
       
   105 
       
   106       MARK_AS_ADVANCED(${var_name}_RELEASE)
       
   107       MARK_AS_ADVANCED(${var_name}_DEBUG)
       
   108 
       
   109     ENDIF(NOT WIN32)
       
   110 
       
   111   ENDIF(NOT "${win32_dbg_postfix_name}" STREQUAL "WIN32_DEBUG_POSTFIX")
       
   112 
       
   113 ENDMACRO(FIND_LIBRARY_WITH_DEBUG)