What makes cmake variables important?

Oswald Buddenhagen ossi at kde.org
Mon Sep 17 09:37:31 BST 2007


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.




More information about the kde-core-devel mailing list