1# cmake/modules/pkg-config.cmake
2#
3# Copyright (C) 2006-2018 Alan W. Irwin
4#
5# This file is part of PLplot.
6#
7# PLplot is free software; you can redistribute it and/or modify
8# it under the terms of the GNU Library General Public License as published
9# by the Free Software Foundation; version 2 of the License.
10#
11# PLplot is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU Library General Public License for more details.
15#
16# You should have received a copy of the GNU Library General Public License
17# along with the file PLplot; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
19
20# Module for determining pkg-config configuration variables related to the
21# install-tree build of the examples.
22# Also create useful macros called pkg_check_pkgconfig to emulate the
23# pkgconfig macro using the pkg_check_modules macro;
24# pkg_config_link_flags to process CMake link flags into
25# pkg-config standard form for the configured output *.pc files, and
26# cmake_link_flags to process input link flags delivered
27# by pkg-config into CMake standard form.
28
29# The following variables are set:
30# PKG_CONFIG_EXECUTABLE	  - name of pkg-config executable, but can also be
31# 			    used for logical control with, e.g.,
32# 			    if(PKG_CONFIG_EXECUTABLE)
33# PKG_CONFIG_ENV	  - the string PKG_CONFIG_PATH=
34#                           ${PKG_CONFIG_DIR}:$ENV{PKG_CONFIG_PATH} which
35#  			    is used in example builds.
36include(FindPkgConfig)
37
38if(PKG_CONFIG_EXECUTABLE)
39  message(STATUS "Looking for pkg-config - found")
40  set(env_PKG_CONFIG_PATH $ENV{PKG_CONFIG_PATH})
41
42  set(
43    PKG_CONFIG_DIR
44    ${CMAKE_INSTALL_PKG_CONFIG_DIR}
45    CACHE PATH "PLplot install location for (architecture-independent) pkg-config files (*.pc)"
46    )
47  list(APPEND INSTALL_LOCATION_VARIABLES_LIST PKG_CONFIG_DIR)
48
49  # Will likely need WIN32 and CYGWIN stanzas as well
50  if(MINGW)
51    if(env_PKG_CONFIG_PATH)
52      # On MinGW (and probably Cygwin and bare Windows) env_PKG_CONFIG_PATH
53      # is semi-colon delimited.
54      set(_pkg_config_path "${PKG_CONFIG_DIR};${env_PKG_CONFIG_PATH}")
55    else(env_PKG_CONFIG_PATH)
56      set(_pkg_config_path "${PKG_CONFIG_DIR}")
57    endif(env_PKG_CONFIG_PATH)
58    # Convert semi-colon delimited path string with colon drive
59    # letters to a colong delimited path form with slash drive letters
60    # that pkg-config configuration files can use.
61    determine_msys_path(_pkg_config_path "${_pkg_config_path}")
62  else(MINGW)
63    # Only tested on Unix (Linux) so far where env_PKG_CONFIG_PATH
64    # is colon-delimited.
65    if(env_PKG_CONFIG_PATH)
66      set(_pkg_config_path "${PKG_CONFIG_DIR}:${env_PKG_CONFIG_PATH}")
67    else(env_PKG_CONFIG_PATH)
68      set(_pkg_config_path "${PKG_CONFIG_DIR}")
69    endif(env_PKG_CONFIG_PATH)
70  endif(MINGW)
71
72  set(PKG_CONFIG_ENV PKG_CONFIG_PATH="${_pkg_config_path}")
73
74  # Figure out C++ special library support for traditional build system by
75  # copying CMake's knowledge of those libraries (held in the CMake lists,
76  # CMAKE_CXX_IMPLICIT_LINK_LIBRARIES and CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES)
77  # for the C++ compiler chosen by the user.
78  set(cxx_compiler_library_pathname_list)
79  if(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES)
80    foreach(cmake_cxx_implicit_link_library ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES})
81      if(cmake_cxx_implicit_link_library)
82	unset(library_pathname CACHE)
83	find_library(library_pathname ${cmake_cxx_implicit_link_library} HINTS ${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES})
84	if(library_pathname)
85	  list(APPEND cxx_compiler_library_pathname_list ${library_pathname})
86	elseif(EXISTS ${cmake_cxx_implicit_link_library})
87	  # Sometimes ${cmake_cxx_implicit_link_library} is the name of an existing file.
88          # In this case assume it is the name of a library.
89	  list(APPEND cxx_compiler_library_pathname_list ${cmake_cxx_implicit_link_library})
90	else(library_pathname)
91	  message(STATUS "WARNING: could not find special C++ library ${cmake_cxx_implicit_link_library} as an
92   existing full pathname of a library or anywhere in CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES =
93   ${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES}.
94   So ${cmake_cxx_implicit_link_library} has been ignored in forming cxx_compiler_library_pathname_list")
95	endif(library_pathname)
96      endif(cmake_cxx_implicit_link_library)
97    endforeach(cmake_cxx_implicit_link_library ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES})
98  endif(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES)
99  # Some cmake versions (e.g., CMake-3.12.2) produce duplicate libraries in this
100  # list, but don't remove them in case these are needed for static linking.
101  # list(REMOVE_DUPLICATES cxx_compiler_library_pathname_list)
102  message(STATUS "cxx_compiler_library_pathname_list = ${cxx_compiler_library_pathname_list}")
103
104else(PKG_CONFIG_EXECUTABLE)
105  message(STATUS "Looking for pkg-config - not found")
106  message(STATUS
107  "WARNING: Makefile+pkg-config version of examples build in the install tree will not work.")
108endif(PKG_CONFIG_EXECUTABLE)
109
110macro(pkg_check_pkgconfig _package _include_DIR _link_DIR _link_FLAGS _cflags _version)
111  # Similar to legacy pkgconfig only these results are derived from
112  # pkg_check_modules and therefore are returned as lists rather than
113  # blank-delimited strings.  Also, the _link_FLAGS value is converted
114  # to the list of full library paths preferred by CMake via the
115  # cmake_link_flags macro.
116
117  # N.B. if using this macro in more than one context, cache clashes will
118  # occur unless optional trailing prefix argument is specified to distinguish
119  # different contexts.
120  set(_prefix ${ARGN})
121  if(NOT _prefix)
122    set(_prefix "_PKGCONFIG_TMP")
123  endif(NOT _prefix)
124
125  if(FORCE_EXTERNAL_STATIC)
126    set(_xprefix ${_prefix}_STATIC)
127  else(FORCE_EXTERNAL_STATIC)
128    set(_xprefix ${_prefix})
129  endif(FORCE_EXTERNAL_STATIC)
130
131  pkg_check_modules(${_prefix} "${_package}")
132
133  if(${_prefix}_FOUND)
134    cmake_link_flags(${_link_FLAGS} "${${_xprefix}_LDFLAGS}")
135    # If libraries cannot be not found, then that is equivalent to whole
136    # pkg-config module not being found.
137    if(NOT ${_link_FLAGS})
138      set(${_prefix}_FOUND)
139    endif(NOT ${_link_FLAGS})
140  endif(${_prefix}_FOUND)
141
142  if(${_prefix}_FOUND)
143    set(${_include_DIR} ${${_xprefix}_INCLUDE_DIRS})
144    set(${_link_DIR}    ${${_xprefix}_LIBRARY_DIRS})
145    set(${_cflags}      ${${_xprefix}_CFLAGS})
146    # N.B. must use ${_prefix}_VERSION} rather than ${_xprefix}_VERSION}
147    # because the latter is not defined.
148    set(${_version}     ${${_prefix}_VERSION})
149    set(_return_VALUE 0)
150  else(${_prefix}_FOUND)
151    set(${_include_DIR})
152    set(${_link_DIR})
153    set(${_link_FLAGS})
154    set(${_cflags})
155    set(${_version})
156    set(_return_VALUE 1)
157  endif(${_prefix}_FOUND)
158  #message("DEBUG: ${_prefix}_FOUND = ${${_prefix}_FOUND}")
159  #message("DEBUG: ${_include_DIR} = ${${_include_DIR}}")
160  #message("DEBUG: ${_link_DIR} = ${${_link_DIR}}")
161  #message("DEBUG: ${_link_FLAGS} = ${${_link_FLAGS}}")
162  #message("DEBUG: ${_cflags} = ${${_cflags}}")
163  #message("DEBUG: ${_version} = ${${_version}}")
164endmacro(pkg_check_pkgconfig)
165
166function(pkg_config_link_flags link_flags_out link_flags_in)
167  # Transform link flags into a form that is suitable to be used for
168  # output pkg-config (*.pc) files.
169  # N.B. ${link_flags_in} must be in quoted "${list_variable}" form
170  # where list_variable is a CMake list.
171
172  #message("(original link flags) = ${link_flags_in}")
173  # First strip out optimized / debug options which are not needed
174  # Currently only FindQt4 seems to need this.
175  if(CMAKE_BUILD_TYPE MATCHES "Debug")
176    # Get rid of the optimized keyword and immediately following library as
177    # well as the debug keyword anywhere such patterns occur in the list.
178    string(REGEX REPLACE "(^|;)optimized;[^;]*;" "\\1" link_flags "${link_flags_in}")
179    string(REGEX REPLACE "(^|;)debug;" "\\1" link_flags "${link_flags}")
180  else(CMAKE_BUILD_TYPE MATCHES "Debug")
181    # Get rid of the debug keyword and immediately following library as
182    # well as the optimized keyword anywhere such patterns occur in the list.
183    string(REGEX REPLACE "(^|;)debug;[^;]*;" "\\1" link_flags "${link_flags_in}")
184    string(REGEX REPLACE "(^|;)optimized;" "\\1" link_flags "${link_flags}")
185  endif(CMAKE_BUILD_TYPE MATCHES "Debug")
186
187  #message("(stripped link flags) = ${link_flags}")
188
189  # Replace actual library names with the -LPATHNAME and -lLIBRARYNAME form
190  # since it appears pkg-config handles that latter form much better (with
191  # regard to keeping the correct order and eliminating duplicates).
192
193  # These suffix patterns for library pathnames appear to work fine on
194  # Linux, Mac OS X, and MinGW/MSYS but it may need some
195  # generalization on other platforms such as Cygwin.
196
197  if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
198    set(suffix_pattern "(\\.so.*|\\.a)")
199  elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
200    set(suffix_pattern "(\\.so.*|\\.a|\\.dylib)")
201  elseif(WIN32_OR_CYGWIN)
202    # Order is important here.
203    set(suffix_pattern "(\\.dll\\.a|\\.a)")
204  else(CMAKE_SYSTEM_NAME STREQUAL "Linux")
205    # Probably a non-Linux, non-Mac OS X, Unix platform
206    # For this case we assume the same as Linux.
207    set(suffix_pattern "(\\.so.*|\\.a)")
208  endif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
209
210  set(_link_flags)
211  foreach(link_flag IN LISTS link_flags)
212    #message(STATUS "link_flag = ${link_flag}")
213    if(WIN32_OR_CYGWIN)
214      # Look for colon-delimited drive-letter form on these platforms.
215      string(REGEX REPLACE "^([a-zA-Z]:/.*)/lib(.*)${suffix_pattern}$" "-L\"\\1\" -l\\2" link_flag "${link_flag}")
216    endif(WIN32_OR_CYGWIN)
217    # Look for form starting with "/" on all platforms.
218    string(REGEX REPLACE "^(/.*)/lib(.*)${suffix_pattern}$" "-L\"\\1\" -l\\2" link_flag "${link_flag}")
219    #message(STATUS "(-L form of link_flag = ${link_flag}")
220    list(APPEND _link_flags ${link_flag})
221  endforeach(link_flag IN LISTS link_flags)
222  set(link_flags ${_link_flags})
223  set(_link_flags)
224  #message("(-L form of link_flags) = ${link_flags}")
225
226  # Convert link flags to a blank-delimited string.
227  string(REGEX REPLACE ";" " " link_flags "${link_flags}")
228  #message("(blank-delimited) link_flags = ${link_flags}")
229
230  if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
231    # For Mac OS X transform frameworks information into correct form.
232    string(
233    REGEX REPLACE
234    "/System/Library/Frameworks/([^ ]*)\\.framework"
235    "-framework \\1"
236    link_flags
237    "${link_flags}"
238    )
239    #message("(frameworks) link_flags = ${link_flags}")
240  endif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
241
242  set(${link_flags_out} ${link_flags} PARENT_SCOPE)
243
244endfunction(pkg_config_link_flags)
245
246macro(cmake_link_flags _link_flags_out _link_flags_in)
247  # Transform link flags delivered by pkg-config into the best form
248  # for CMake.
249  # N.B. may need revision for windows since the current assumption
250  # is pkg-config delivers link flags using the -L and -l options which
251  # may not be the case for windows.
252  # N.B. ${_link_flags_in} must be a string and not a list.
253
254  if("${_link_flags_in}" STREQUAL "")
255    set(${_link_flags_out})
256  else("${_link_flags_in}" STREQUAL "")
257    #message("(original link flags) = ${_link_flags_in}")
258    # Convert link flags to a list.  Note some link flags are blank-delimited
259    # (such as "-framework whatever") so preserve those by splitting into
260    # separate list elements only if the next element starts with a hyphen.
261    string(REGEX REPLACE " -" ";-" _link_flags_list "${_link_flags_in}")
262    if(NOT MATH_LIB)
263      # On systems (normally Windows) where MATH_LIB is not defined
264      # filter out -lm from link flags.  This works around a pkg-config
265      # configuration bug on Windows for the GTK+ stack of libraries where
266      # -lm is supplied as a required library flag when that library does
267      # not exist on Windows platforms.
268      list(REMOVE_ITEM _link_flags_list "-lm")
269    endif(NOT MATH_LIB)
270    #message("_link_flags_list = ${_link_flags_list}")
271
272    # Extract list of directories from -L options.
273    list(LENGTH _link_flags_list _link_flags_length)
274    math(EXPR _link_flags_length "${_link_flags_length} - 1")
275    set(_index_list)
276    set(_link_directory_list)
277    foreach(_list_index RANGE ${_link_flags_length})
278      list(GET _link_flags_list ${_list_index} _list_element)
279      string(REGEX REPLACE "^-L" "" _list_element1 "${_list_element}")
280      if(_list_element STREQUAL "-L${_list_element1}")
281        list(APPEND _index_list ${_list_index})
282        list(APPEND _link_directory_list ${_list_element1})
283      endif(_list_element STREQUAL "-L${_list_element1}")
284    endforeach(_list_index RANGE ${_link_flags_length})
285    #message("_index_list = ${_index_list}")
286    if(NOT "${_index_list}" STREQUAL "")
287      # Remove -L options from list.
288      list(REMOVE_AT _link_flags_list ${_index_list})
289    endif(NOT "${_index_list}" STREQUAL "")
290    #message("_link_directory_list = ${_link_directory_list}")
291    #message("_link_flags_list (without -L options) = ${_link_flags_list}")
292
293    # Derive ${_link_flags_out} from _link_flags_list with -l options
294    # replaced by complete pathname of library.
295    list(LENGTH _link_flags_list _link_flags_length)
296    math(EXPR _link_flags_length "${_link_flags_length} - 1")
297    set(${_link_flags_out})
298    set(_success ON)
299    set(_not_found_list)
300    foreach(_list_index RANGE ${_link_flags_length})
301      list(GET _link_flags_list ${_list_index} _list_element)
302      string(REGEX REPLACE "^-l" "" _list_element1 "${_list_element}")
303      if(_list_element STREQUAL "-l${_list_element1}")
304        set(_library_pathname "_library_pathname-NOTFOUND")
305        find_library(
306         _library_pathname
307         ${_list_element1}
308         PATHS ${_link_directory_list}
309         NO_DEFAULT_PATH
310        )
311	# Try second time (without NO_DEFAULT_PATH) just in case pkg-config
312	# specified some system libraries without corresponding -L options.
313        find_library(
314         _library_pathname
315         ${_list_element1}
316         PATHS ${_link_directory_list}
317        )
318        if(NOT _library_pathname)
319	  set(_success OFF)
320	  list(APPEND _not_found_list ${_list_element1})
321        endif(NOT _library_pathname)
322        list(APPEND ${_link_flags_out} ${_library_pathname})
323      else(_list_element STREQUAL "-L${_list_element1}")
324        # link options that are not -L or -l passed through in correct order
325        # in ${_link_flags_out}.
326        list(APPEND ${_link_flags_out} ${_list_element})
327      endif(_list_element STREQUAL "-l${_list_element1}")
328    endforeach(_list_index RANGE ${_link_flags_length})
329    #message("${_link_flags_out} = ${${_link_flags_out}}")
330
331    # If one or more of the libraries cannot be found, then return an
332    # empty ${_link_flags_out} as a sign of that failure.
333    if(NOT _success)
334      message(STATUS "WARNING: Library inconsistency detected.  Your pkg-config files claim certain libraries are present, but CMake cannot find them.")
335      message(STATUS "The unfound library basenames are as follows:")
336      foreach(_not_found IN LISTS _not_found_list)
337	message(STATUS "${_not_found}")
338      endforeach(_not_found IN LISTS _not_found_list)
339      message(STATUS "Some library installation and/or adjustment of find-related environment variables or corresponding CMake variables will be required before CMake will be able to find these libraries.")
340      message(STATUS "cmake_link_flags WARNING: (original link flags) = ${_link_flags_in}")
341      message(STATUS "cmake_link_flags WARNING: (corresponding link flags with found libraries = ${_link_flags_out}) = ${${_link_flags_out}}")
342      message(STATUS "cmake_link_flags WARNING: ${_link_flags_out} is invalid so it is set to nothing to signal the failure of cmake_link_flags for the original link flags printed out above.")
343      set(${_link_flags_out})
344    endif(NOT _success)
345  endif("${_link_flags_in}" STREQUAL "")
346endmacro(cmake_link_flags)
347
348function(pkg_config_file BINDING PC_SHORT_NAME PC_LONG_NAME PC_LIBRARY_NAME PC_COMPILE_FLAGS PC_LINK_FLAGS)
349  # Configure and install pkg-config *.pc file corresponding to the core PLplot library
350  # or one of the language bindings libraries which depend on that core library.
351  # The arguments are the following:
352  # BINDING 	      	  - ENABLE_${BINDING} keeps track of whether a
353  # 			    binding has been enabled (ON) or not (OFF).
354  #			    Also, ${BINDING} used to determine PC_FILE_SUFFIX
355  #			    which helps to determine name of configured
356  #			    *.pc file.
357  # PC_SHORT_NAME	  - Used in *.pc NAME: field
358  # PC_LONG_NAME	  - Used in *.pc Description: field.  Must have trailing ", "
359  #                         if you want additional precision information appended.
360  # PC_LIBRARY_NAME	  - Used in *.pc Libs: field
361  #                         Also used to determine PC_LINK_FLAGS and
362  #                         PC_COMPILE_FLAGS used in *.pc Libs: and Cflags:
363  #			    fields.
364  # PC_COMPILE_FLAGS      - Space-delimited string of compile flags for this library.
365  # PC_LINK_Flags         - List of libraries that this library depends on.  These will
366  #                         be added to the public libraries for NON_TRANSITIVE OFF
367  #                         and added to the private libraries for NON_TRANSITIVE ON
368  #
369  # There may be one additional optional argument (accessed with ${ARGN}) containing
370  # a list of additional libraries to be added to the public libraries regardless of
371  # NON_TRANSITIVE value.
372
373  # An example of a call of this function using these arguments is
374  # pkg_config_file("tcl" "Tcl/Tk" "Tcl/Tk bindings, " "plplottcltk" "${libplplottcltk_COMPILE_FLAGS}" "${libplplottcltk_LINK_FLAGS}")
375
376  # This function depends on the following non-argument CMake variables being set.
377  # PKG_CONFIG_EXECUTABLE
378  # PL_DOUBLE
379  # NON_TRANSITIVE
380  # PKG_CONFIG_DIR
381  # These last non-argument CMake variables required for configuring
382  # pkgcfg/plplot-template.pc.in
383  # PLPLOT_VERSION
384  # INCLUDE_DIR
385  # LIB_DIR
386
387  if(PKG_CONFIG_EXECUTABLE)
388    #message(STATUS "pkg_config_file called with ARGV = ${ARGV}")
389
390    if(PC_LONG_NAME MATCHES "^ ")
391      if(PL_DOUBLE)
392	set(PC_PRECISION "Double precision")
393      else(PL_DOUBLE)
394	set(PC_PRECISION "Single precision")
395      endif(PL_DOUBLE)
396    else(PC_LONG_NAME MATCHES "^ ")
397      set(PC_PRECISION)
398    endif(PC_LONG_NAME MATCHES "^ ")
399
400    # Filter all build-tree or source-tree -I options from
401    # compile-flags.  These occur, for example, for libplplot in the
402    # -DENABLE_DYNDRIVERS=OFF case because the compile flags of
403    # certain device drivers (e.g., tk) depend on build-tree
404    # directories, but libraries or applications that are built
405    # against libplplot should _never_ include those build-tree
406    # headers.
407    string(REGEX REPLACE "-I[^ ]*${CMAKE_SOURCE_DIR}[^ ]*" "" PC_COMPILE_FLAGS "${PC_COMPILE_FLAGS}")
408    string(REGEX REPLACE "-I[^ ]*${CMAKE_BINARY_DIR}[^ ]*" "" PC_COMPILE_FLAGS "${PC_COMPILE_FLAGS}")
409    # Clean up extra blanks
410    string(REGEX REPLACE "  *" " " PC_COMPILE_FLAGS "${PC_COMPILE_FLAGS}")
411
412    # Transform PC_LINK_FLAGS from list of libraries to the standard pkg-config form.
413    #message(STATUS "input PC_LINK_FLAGS = ${PC_LINK_FLAGS}")
414    pkg_config_link_flags(PC_LINK_FLAGS "${PC_LINK_FLAGS}")
415    #message(STATUS "pkg-config form of PC_LINK_FLAGS = ${PC_LINK_FLAGS}")
416    if(NON_TRANSITIVE)
417      set(PC_PRIVATE_LINK_FLAGS ${PC_LINK_FLAGS})
418    else(NON_TRANSITIVE)
419      set(PC_PUBLIC_LINK_FLAGS ${PC_LINK_FLAGS})
420    endif(NON_TRANSITIVE)
421
422    if(ARGC EQUAL 7)
423      #message(STATUS "pkg_config_file called with ARGN = ${ARGN}")
424      pkg_config_link_flags(added_private_libraries "${ARGN}")
425      set(PC_PUBLIC_LINK_FLAGS "${PC_PUBLIC_LINK_FLAGS} ${added_private_libraries}")
426    elseif(ARGC LESS 6)
427      message(STATUS "pkg_config_file called with ARGV = ${ARGV}")
428      message(FATAL_ERROR "pkg_config_file called with wrong number of arguments")
429    endif(ARGC EQUAL 7)
430
431    # N.B. all the tests on "X${BINDING}X" below rather than BINDING
432    # are to beat a potential dereferencing problem for strings in if statements.
433    # This problem only occurs with old CMake versions that don't
434    # have CMP0054 set to NEW.
435
436    if("X${BINDING}X" STREQUAL "XcX")
437      set(PC_FILE_SUFFIX "")
438      set(PC_REQUIRES "")
439    elseif("X${BINDING}X" STREQUAL "XwxwidgetsX")
440      set(PC_FILE_SUFFIX "-${BINDING}")
441      set(PC_REQUIRES "plplot-c++")
442    else("X${BINDING}X" STREQUAL "XcX")
443      set(PC_FILE_SUFFIX "-${BINDING}")
444      set(PC_REQUIRES "plplot")
445    endif("X${BINDING}X" STREQUAL "XcX")
446
447    if(NON_TRANSITIVE)
448      if("X${BINDING}X" STREQUAL "XocamlX")
449	# Don't know how to do non-transitive linking for
450        # Ocaml binding of PLplot.
451	set(PC_REQUIRES_TAG "Requires")
452      else("X${BINDING}X" STREQUAL "XocamlX")
453	set(PC_REQUIRES_TAG "Requires.private")
454      endif("X${BINDING}X" STREQUAL "XocamlX")
455    else(NON_TRANSITIVE)
456      set(PC_REQUIRES_TAG "Requires")
457    endif(NON_TRANSITIVE)
458
459    # Include library itself in space-separated list of public libraries for
460    # this package.
461    set(PC_PUBLIC_LINK_FLAGS "-l${PC_LIBRARY_NAME} ${PC_PUBLIC_LINK_FLAGS}")
462
463    set(PC_CONFIGURED_FILE
464      ${CMAKE_BINARY_DIR}/pkgcfg/plplot${PC_FILE_SUFFIX}.pc
465      )
466    configure_file(
467      ${CMAKE_SOURCE_DIR}/pkgcfg/plplot-template.pc.in
468      ${PC_CONFIGURED_FILE}
469      @ONLY
470      )
471    install(FILES ${PC_CONFIGURED_FILE} DESTINATION ${PKG_CONFIG_DIR})
472
473  endif(PKG_CONFIG_EXECUTABLE)
474endfunction(pkg_config_file)
475