# # FIND_LIBRARY_WITH_DEBUG # -> enhanced FIND_LIBRARY to allow the search for an # optional debug library with a WIN32_DEBUG_POSTFIX similar # to CMAKE_DEBUG_POSTFIX when creating a shared lib # it has to be the second and third argument # Copyright (c) 2007, Christian Ehrlicher, # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. MACRO(FIND_LIBRARY_WITH_DEBUG var_name win32_dbg_postfix_name dgb_postfix libname) IF(NOT "${win32_dbg_postfix_name}" STREQUAL "WIN32_DEBUG_POSTFIX") # no WIN32_DEBUG_POSTFIX -> simply pass all arguments to FIND_LIBRARY FIND_LIBRARY(${var_name} ${win32_dbg_postfix_name} ${dgb_postfix} ${libname} ${ARGN} ) ELSE() IF(NOT WIN32) # on non-win32 we don't need to take care about WIN32_DEBUG_POSTFIX FIND_LIBRARY(${var_name} ${libname} ${ARGN}) ELSE() # 1. get all possible libnames SET(args ${ARGN}) SET(newargs "") SET(libnames_release "") SET(libnames_debug "") IF("${libname}" STREQUAL "NAMES") SET(append_rest 0) LIST(LENGTH args listCount) LIST(APPEND args " ") FOREACH(i RANGE ${listCount}) LIST(GET args ${i} val) IF(append_rest) LIST(APPEND newargs ${val}) ELSE() IF(${val} STREQUAL "PATHS" OR ${val} STREQUAL "HINTS") LIST(APPEND newargs ${val}) SET(append_rest 1) ELSE() LIST(APPEND libnames_release "${val}") LIST(APPEND libnames_debug "${val}${dgb_postfix}") ENDIF() ENDIF() ENDFOREACH() ELSE() # just one name LIST(APPEND libnames_release "${libname}") LIST(APPEND libnames_debug "${libname}${dgb_postfix}") SET(newargs ${args}) ENDIF() # search the release lib FIND_LIBRARY(${var_name}_RELEASE NAMES ${libnames_release} ${newargs} ) # search the debug lib FIND_LIBRARY(${var_name}_DEBUG NAMES ${libnames_debug} ${newargs} ) IF(${var_name}_RELEASE AND ${var_name}_DEBUG) # both libs found SET(${var_name} optimized ${${var_name}_RELEASE} debug ${${var_name}_DEBUG}) ELSE() IF(${var_name}_RELEASE) # only release found SET(${var_name} ${${var_name}_RELEASE}) ELSE() # only debug (or nothing) found SET(${var_name} ${${var_name}_DEBUG}) ENDIF() ENDIF() MARK_AS_ADVANCED(${var_name}_RELEASE) MARK_AS_ADVANCED(${var_name}_DEBUG) ENDIF() ENDIF() ENDMACRO()