[CMake] Cmake replacement for AC_SEARCH_LIBS?

Andreas Pakulat apaku at gmx.de
Thu Feb 26 03:13:14 EST 2009


On 25.02.09 18:39:20, Steve Huston wrote:
> I'm working on replacing a autoconf/automake build with Cmake. One
> thing I'm stuck on is replacing AC_SEARCH_LIBS. For example:
> 
>   AC_SEARCH_LIBS(dlopen, [dl],
> 		 [test "$ac_cv_search_dlopen" = "none required" ||
> 		  LIB_DLOPEN=$ac_cv_search_dlopen])
>   AC_SUBST([LIB_DLOPEN])
> 
> Essentially, you can look through a list of possible libraries for a
> given function/entrypoint. If a library is needed, it's remembered in
> LIB_DLOPEN (in the example). But sometimes there's no library needed
> to get the desired symbol. So, it's not really the same as
> CheckLibraryExists... Is there something that does this in cmake?

Sure, though not in a single command. But you can easily write a macro
that does this yourself and use it everywhere where you want to replace
the above. Something like

macro( AC_SEARCH_LIBS LIB_REQUIRED FUNCTION_NAME TARGET_VAR )
if(${LIB_REQUIRED})
foreach( LIB ${ARGN} )
  FindLibrary(_LIB_PATH ${LIB})
  CheckLibraryExists(${LIB} ${FUNCTION_NAME} ${_LIB_PATH} _LIB_FUNCTION_FOUND )
  if( ${_LIB_FUNCTION_FUND} )
    set(${TARGET_VAR} ${_LIB_PATH})
    break()
  endif
endforeach( LIB )
endif(${LIB_REQUIRED})

Probably needs some finetuning, but I think you get the idea. Not sure I
got the logic of "not required" right though.

Andreas

-- 
A day for firm decisions!!!!!  Or is it?


More information about the CMake mailing list