Debian Codegraph @

dynamicEDT3D/CMakeModules/InstallPkgConfigFile.cmake

raw
1 # A Macro to simplify creating a pkg-config file
2
3 # install_pkg_config_file(<package-name>
4 # [VERSION <version>]
5 # [DESCRIPTION <description>]
6 # [CFLAGS <cflag> ...]
7 # [LIBS <lflag> ...]
8 # [REQUIRES <required-package-name> ...])
9 #
10 # Create and install a pkg-config .pc file to CMAKE_INSTALL_LIBDIR/pkgconfig
11 # assuming the following install layout:
12 # libraries: CMAKE_INSTALL_LIBDIR
13 # headers : CMAKE_INSTALL_INCLUDEDIR
14 #
15 # example:
16 # add_library(mylib mylib.c)
17 # install_pkg_config_file(mylib
18 # DESCRIPTION My Library
19 # CFLAGS
20 # LIBS -lmylib
21 # REQUIRES glib-2.0 lcm
22 # VERSION 0.0.1)
23 #
24 #
25 function(install_pkg_config_file)
26 list(GET ARGV 0 pc_name)
27 # TODO error check
28
29 set(pc_version 0.0.1)
30 set(pc_description ${pc_name})
31 set(pc_requires "")
32 set(pc_libs "")
33 set(pc_cflags "")
34 set(pc_fname "${CMAKE_BINARY_DIR}/lib/pkgconfig/${pc_name}.pc")
35
36 set(modewords LIBS CFLAGS REQUIRES VERSION DESCRIPTION)
37 set(curmode "")
38
39 # parse function arguments and populate pkg-config parameters
40 list(REMOVE_AT ARGV 0)
41 foreach(word ${ARGV})
42 list(FIND modewords ${word} mode_index)
43 if(${mode_index} GREATER -1)
44 set(curmode ${word})
45 elseif(curmode STREQUAL LIBS)
46 set(pc_libs "${pc_libs} ${word}")
47 elseif(curmode STREQUAL CFLAGS)
48 set(pc_cflags "${pc_cflags} ${word}")
49 elseif(curmode STREQUAL REQUIRES)
50 set(pc_requires "${pc_requires} ${word}")
51 elseif(curmode STREQUAL VERSION)
52 set(pc_version ${word})
53 set(curmode "")
54 elseif(curmode STREQUAL DESCRIPTION)
55 set(pc_description "${word}")
56 set(curmode "")
57 else(${mode_index} GREATER -1)
58 message("WARNING incorrect use of install_pkg_config_file (${word})")
59 break()
60 endif(${mode_index} GREATER -1)
61 endforeach(word)
62
63 # write the .pc file out
64 file(WRITE ${pc_fname}
65 "prefix=${CMAKE_INSTALL_PREFIX}\n"
66 "libdir=${CMAKE_INSTALL_FULL_LIBDIR}\n"
67 "includedir=${CMAKE_INSTALL_FULL_INCLUDEDIR}\n"
68 "\n"
69 "Name: ${pc_name}\n"
70 "Description: ${pc_description}\n"
71 "Requires: ${pc_requires}\n"
72 "Version: ${pc_version}\n"
73 "Libs: -L\${libdir} ${pc_libs}\n"
74 "Cflags: -I\${includedir} ${pc_cflags}\n")
75
76 # mark the .pc file for installation to the lib/pkgconfig directory
77 install(FILES ${pc_fname} DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
78 endfunction(install_pkg_config_file)