[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: What makes cmake variables important?
From:       Oswald Buddenhagen <ossi () kde ! org>
Date:       2007-09-17 8:37:31
Message-ID: 20070917083731.GA5737 () ugly ! local
[Download RAW message or body]

On Sun, Sep 16, 2007 at 08:07:51PM -0400, Alexander Neundorf wrote:
> The correct way to handle this is really to check the results of function 
> calls. Two ways how this can be done:
> 
> find_library(SOME_LIB util)
> 
> ...
> if(SOME_LIB)
>    target_link_libraries(foo ${SOME_LIB})
> endif(SOME_LIB)
> 
> OR:
> 
> set(extraLibraries)
> 
> find_library(SOME_LIB util)
> 
> if(SOME_LIB)
>   set(extraLibraries ${extraLibraries} ${SOME_LIB})
> endif(SOME_LIB)
> 
> ...
> target_link_libraries(foo ... ${extraLibraries})
> 
> I think this second way is nicer.
> 
> With a macro like this:
> 
> macro( APPEND_CONDITIONAL list var)
>   if(${var})
>     set(${list} ${${list}} ${var} )
>   endif(${var})
> endmacro(APPEND_CONDITIONAL)
> 
> it will be shorter:
> 
> set(extraLibraries)
> 
> find_library(SOME_LIB util)
> append_conditional(extraLibraries SOME_LIB)
> 
> ...
> target_link_libraries(foo ... ${extraLibraries})
> 
> But the macro needs a better name.
> Suggestions ?
> 
this all sucks. :-P

after looking at it myself, i noticed that i have the following in kdm
(and that's the reason why it works for those libs, [ade] :):

macro(define_library LIB FN)
        set(varname ${FN}_in_${LIB})
        string(TOUPPER ${LIB}_LIBRARIES libname)
        check_library_exists(${LIB} ${FN} "" ${varname})
        set(${libname})
        if (${varname})
                set(${libname} ${LIB})
        endif (${varname})
endmacro(define_library)

and then:

define_library(s authenticate)
define_library(posix4 sched_yield)
define_library(socket connect)
define_library(resolv dn_expand)



-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!
--
Chaos, panic, and disorder - my work here is done.
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic