[Cmake] Re: cmake: writing Find modules

Bill Hoffman bill.hoffman at kitware.com
Wed May 9 17:24:24 EDT 2001


I have just changed FIND_LIBARY to work a bit different.

FIND_LIBARY (DEF NAME lib1 lib2 lib3 ... PATHS path1 path2 path3)
If the library is found DEF will have the lib( lib1, lib2, lib3 ..) it found
in a FULL path to the library.  The generator for unix breaks it into -L and -l now.

-Bill


At 04:45 PM 5/9/2001 -0400, Amitha Perera wrote:
>Comments on this?
>
>Thanks,
>Amitha.
>
>--
>In general, a FindABC module should deal with four variables, all of
>which are cached:
>
>  HAS_ABC           ("YES" or "NO")
>  ABC_INCLUDE_PATH  ("/opt/abc/include")
>  ABC_LIB_PATH      ("/opt/abc/lib")
>  ABC_LIBRARY       ( "-labc" or "-labc -ldef" )
>
>HAS_ABC="YES" indicates that the library is available _and_ should be
>used.
>
>If the library is available, ABC_LIBRARY is set to the libraries that
>should be linked against. If the library is not available, ABC_LIBRARY
>should be set to something like "not available". It should _not_ be
>undefined. Since the search process is guaranteed to set ABC_LIBRARY,
>we use that as a guard to prevent multiple searches, which prevents us
>from overwriting user settings when the cache is rebuilt.
>
>Take, for example, the case where a native jpeg library exists, but we
>want to link against v3p/jpeg. The initial run of CMake will build the
>non-existent CMakeCache.txt. In doing so, it will search for jpeg,
>find the system library and set HAS_NATIVE_JPEG="YES" and so on. Now,
>we go
>and edit CMakeCache.txt and set HAS_NATIVE_JPEG="NO". It is vital that
>the next cache rebuild does not then redo the search and reset
>HAS_NATIVE_JPEG to "YES".
>
>Therefore, a skeleton FindABC.cmake would look something like this:
>
>
>IF(NOT ABC_LIBRARY)
>
>  SET( ABC_LIBRARY "not available" CACHE )
>  SET( HAS_ABC "NO" CACHE )
>
>  FIND_PATH( ABC_INCLUDE_PATH abc/conf.h
>     /place1/include   /place2/include
>  )
>
>  FIND_PATH( ABC_LIB_PATH abc
>     /place1/lib /place2/lib /place3/lib
>  )
>
>  IF(ABC_INCLUDE_PATH)
>    IF(ABC_LIB_PATH)
>      SET( ABC_LIBRARY "-labc -ldef" CACHE )
>      SET( HAS_ABC "YES" CACHE )
>    ENDIF(ABC_LIB_PATH)
>  ENDIF(ABC_INCLUDE_PATH)
>ENDIF(NOT ABC_LIBRARY)
>
>
>Note that you should include the "-l" in the library name when you
>have more than one library. CMake translates "abc def" to "-labc def",
>and translates "-labc -ldef" to "-labc -ldef".
>--





More information about the CMake mailing list