Code

Node tool: fix handle retraction with non-cusp nodes
[inkscape.git] / CMakeScripts / UsePkgConfig.cmake
1 # - pkg-config module for CMake
2 #
3 # Defines the following macros:
4 #
5 #  PKGCONFIG_FOUND(package found)
6 #  PKGCONFIG(package includedir libdir linkflags cflags)
7 #  PKGCONFIG_VERSION(package version)
8 #  PKGCONFIG_DEFINITION(package definition)
10 # Calling PKGCONFIG_FOUND will fill into the argument the value of the package search's result
11 # e.g. PKGCONFIG_FOUND(libart-2.0 LIBART_FOUND)
12 #
13 # Calling PKGCONFIG_VERSION will fill the desired version into the argument,
14 # e.g. PKGCONFIG_VERSION(libart-2.0 LIBART_VERSION)
15 # Calling PKGCONFIG will fill the desired information into the 4 given arguments,
16 # e.g. PKGCONFIG(libart-2.0 LIBART_INCLUDE_DIR LIBART_LINK_DIR LIBART_LINK_FLAGS LIBART_CFLAGS)
17 # if pkg-config was NOT found or the specified software package doesn't exist, the
18 # variable will be empty when the function returns, otherwise they will contain the respective information
19 #
20 # Calling PKGCONFIG_VERSION will fill the desired version into the argument,
21 # e.g. PKGCONFIG_VERSION(libart-2.0 LIBART_VERSION)
22 #
23 # Calling PKGCONFIG_DEFINITION will fill the definition (e.g -D_REENTRANT) into the argument,
24 # e.g. PKGCONFIG_DEFINITION(libart-2.0 LIBART_DEFINITION)
26 FIND_PROGRAM(PKGCONFIG_EXECUTABLE NAMES pkg-config PATHS /usr/local/bin )
28 MACRO(STRIP_NEWLINES _string_var)
29   STRING(REGEX REPLACE "[\n\r]+" "" ${_string_var} ${${_string_var}})
30 ENDMACRO(STRIP_NEWLINES _string_var)
32 MACRO(PKGCONFIG_FOUND _package _found)
33   # reset the variable at the beginning
34   SET(${_found})
36 # if pkg-config has been found
37   IF(PKGCONFIG_EXECUTABLE)
39     EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --print-errors --exists RETURN_VALUE _return_VALUE OUTPUT_VARIABLE _pkgconfigDevNull )
40     
41     IF(${_pkgconfigDevNull})
42       MESSAGE(STATUS "${_pkgconfigDevNull}")
43     ENDIF(${_pkgconfigDevNull})
44     
45     IF(NOT _return_VALUE)
46       SET(${_found} "TRUE")
47     ENDIF(NOT _return_VALUE)
48   ENDIF(PKGCONFIG_EXECUTABLE)
50 ENDMACRO(PKGCONFIG_FOUND _found)
52 MACRO(PKGCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
53 # reset the variables at the beginning
54   SET(${_include_DIR})
55   SET(${_link_DIR})
56   SET(${_link_FLAGS})
57   SET(${_cflags})
59   # if pkg-config has been found
60   IF(PKGCONFIG_EXECUTABLE)
62     EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --exists RETURN_VALUE _return_VALUE OUTPUT_VARIABLE _pkgconfigDevNull )
64     # and if the package of interest also exists for pkg-config, then get the information
65     IF(NOT _return_VALUE)
67       EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --variable=includedir OUTPUT_VARIABLE ${_include_DIR} )
69       EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --variable=libdir OUTPUT_VARIABLE ${_link_DIR} )
71       EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --libs OUTPUT_VARIABLE ${_link_FLAGS} )
73       EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --cflags OUTPUT_VARIABLE ${_cflags} )
75       STRIP_NEWLINES(${_cflags})
77     ENDIF(NOT _return_VALUE)
79   ENDIF(PKGCONFIG_EXECUTABLE)
81 ENDMACRO(PKGCONFIG _include_DIR _link_DIR _link_FLAGS _cflags)
83 MACRO(PKGCONFIG_VERSION _package _version)
84 # reset the variables at the beginning
85   SET(${_version})
87 # if pkg-config has been found
88   IF(PKGCONFIG_EXECUTABLE)
89     EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS --print-errors ${_package} --exists RETURN_VALUE _return_VALUE OUTPUT_VARIABLE _pkgconfigDevNull )
91 # and if the package of interest also exists for pkg-config, then get the information
92     IF(NOT _return_VALUE)
93       EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS --print-errors ${_package} --modversion OUTPUT_VARIABLE ${_version} )
94     ENDIF(NOT _return_VALUE)
96   ENDIF(PKGCONFIG_EXECUTABLE)
98 ENDMACRO(PKGCONFIG_VERSION _package _version)
100 MARK_AS_ADVANCED(PKGCONFIG_EXECUTABLE)
102 MACRO(PKGCONFIG_DEFINITION _package _definition)
103 # reset the variables at the beginning
104   SET(${_definition})
106 # if pkg-config has been found
107   IF(PKGCONFIG_EXECUTABLE)
108     EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS --print-errors ${_package} --exists RETURN_VALUE _return_VALUE OUTPUT_VARIABLE _pkgconfigDevNull )
110 # and if the package of interest also exists for pkg-config, then get the information
111     IF(NOT _return_VALUE)
112       EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS --print-errors ${_package} --cflags-only-other OUTPUT_VARIABLE ${_definition} )
113     ENDIF(NOT _return_VALUE)
115   ENDIF(PKGCONFIG_EXECUTABLE)
117 ENDMACRO(PKGCONFIG_DEFINITION _package _definition)
119 MARK_AS_ADVANCED(PKGCONFIG_EXECUTABLE)