1 # Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
6 # This function applies external (out of source tree) dependencies
7 # to given target. Arguments are:
8 # TARGET - valid cmake target
9 # PRIVACY - dependency can be inherited by dependent targets or not:
10 # PUBLIC - this should be used by default, cause compile/link flags passing
11 # PRIVATE - do not passes any settings to dependent targets,
12 # may be usefull for static libraries from the inside of the project
13 # Argument ARGV2 and following are supposed to be names of checked pkg config
14 # packages. This function will use variables created by check_pkg_modules().
15 # - ${DEP_NAME}_LIBRARIES
16 # - ${DEP_NAME}_INCLUDE_DIRS
17 # - ${DEP_NAME}_CFLAGS
19 FUNCTION(APPLY_PKG_CONFIG TARGET PRIVACY)
20 MATH(EXPR DEST_INDEX "${ARGC}-1")
21 FOREACH(I RANGE 2 ${DEST_INDEX})
22 IF(NOT ${ARGV${I}}_FOUND)
23 MESSAGE(FATAL_ERROR "Not found dependency - ${ARGV${I}}_FOUND")
24 ENDIF(NOT ${ARGV${I}}_FOUND)
25 TARGET_LINK_LIBRARIES(${TARGET} ${PRIVACY} "${${ARGV${I}}_LIBRARIES}")
26 TARGET_INCLUDE_DIRECTORIES(${TARGET} ${PRIVACY} SYSTEM "${${ARGV${I}}_INCLUDE_DIRS}")
27 STRING(REPLACE ";" " " CFLAGS_STR "${${ARGV${I}}_CFLAGS}")
28 SET(CFLAGS_LIST ${CFLAGS_STR})
29 SEPARATE_ARGUMENTS(CFLAGS_LIST)
30 FOREACH(OPTION ${CFLAGS_LIST})
31 TARGET_COMPILE_OPTIONS(${TARGET} ${PRIVACY} ${OPTION})
33 SET_TARGET_PROPERTIES(${TARGET} PROPERTIES SKIP_BUILD_RPATH true)
34 ENDFOREACH(I RANGE 2 ${DEST_INDEX})
35 ENDFUNCTION(APPLY_PKG_CONFIG TARGET PRIVACY)