[Cmake] Automatic dependency building under Unix

Cross, Geoff (CRD) crossge at crd.ge.com
Wed May 9 14:37:25 EDT 2001



> 2) Is there a way to specify a library as an external dependency? Say
> LINK_EXTERNAL_LIBRARIES( jpeg )? In vxl, there is a v3p/jpeg library
> in the project for those that don't have an external jpeg library. The
> idea is to use the external one if you have it. However, if I simply
> LINK_LIBRARIES( jpeg ), the CMake system will emit a dependency for
> v3p/jpeg, since it just goes by the name.

I thought this was solved:

First we search for the external (native) jpeg library:

FIND_PATH(NATIVE_JPEG_INCLUDE_PATH jpeglib.h
/usr/local/include
/usr/include
)

FIND_LIBRARY(NATIVE_JPEG_LIB_PATH jpeg
/usr/lib
/usr/local/lib
)

If we find it, we set HAS_NATIVE_JPEG to yes

SET(HAS_NATIVE_JPEG "NO")

IF(NATIVE_JPEG_LIB_PATH)
  IF(NATIVE_JPEG_INCLUDE_PATH)
    SET(NATIVE_JPEG_LIBRARY "jpeg" CACHE)
    SET(HAS_NATIVE_JPEG "YES")
  ENDIF(NATIVE_JPEG_INCLUDE_PATH)
ENDIF(NATIVE_JPEG_LIB_PATH)

Then when we come to compiling v3p, we just do a 

IF(HAS_NATIVE_JPEG)
  SUBDIRS(jpeg)
ENDIF(HAS_NATIVE_JPEG)

When we want to link

IF(HAS_NATIVE_JPEG)
  LINK_LIBRARIES(jpeg)
  LINK_DIRECTORIES(${NATIVE_JPEG_LIB_PATH})
ELSE()
  LINK_LIBRARIES(jpeg)
  LINK_LIBRARIES(${allvxl_SOURCE_DIR}/v3p/jpeg)
ENDIF()




More information about the CMake mailing list