[CMake] Linking library with custom target

Reza Housseini reza.housseini at gmx.ch
Thu Dec 13 04:35:09 EST 2012


Hello

I want to link a library to a custom target:

add_custom_command(
  OUTPUT ${FILE}
  DEPENDS ${SRC}
  COMMAND ${EXECUTABLE}
  ARGS ${SRC}
  COMMENT "Generating ${FILE}"
  VERBATIM)

add_custom_target(mytarget ALL
  DEPENDS ${FILE})

target_link_libraries(mytarget /usr/local/lib/libmylib.so)

But it don't seems to work instead I have to use:

add_custom_command(
  OUTPUT ${FILE}
  DEPENDS ${SRC}
  COMMAND ${EXECUTABLE}
  ARGS ${SRC}
  ARGS -I${CPPLIB_INCLUDE_DIR} -L${CPPLIB_DIR} -lmylib
  COMMENT "Generating ${FILE}"
  VERBATIM)

add_custom_target(mytarget ALL
  DEPENDS ${FILE})

Why is this so? Can't I use target_link_library with add_custom_target?

Thnaks for clarification!

Cheers Reza


More information about the CMake mailing list