summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel Argüelles <manuel.arguelles@gmail.com>2013-08-23 15:31:24 -0500
committerManuel Argüelles <manuel.arguelles@gmail.com>2013-08-23 15:31:24 -0500
commit33ee73fffaf0fb44d280b8bae16ec9dae15956d7 (patch)
tree72543192dae738140bafcf074fcf8326528fa523
parentf8f550e2f0604fd4491c9ff01f9843573a5a9b43 (diff)
Add pkg-config file
Generate and install a toxcore.pc file to be used with pkg-config.
-rw-r--r--cmake/InstallPkgConfigFile.cmake78
-rw-r--r--core/CMakeLists.txt6
2 files changed, 84 insertions, 0 deletions
diff --git a/cmake/InstallPkgConfigFile.cmake b/cmake/InstallPkgConfigFile.cmake
new file mode 100644
index 00000000..7c4e5859
--- /dev/null
+++ b/cmake/InstallPkgConfigFile.cmake
@@ -0,0 +1,78 @@
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_PREFIX/lib/pkgconfig
11# assuming the following install layout:
12# libraries: CMAKE_INSTALL_PREFIX/lib
13# headers : CMAKE_INSTALL_PREFIX/include
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#
25function(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=\${prefix}/lib\n"
67 "includedir=\${prefix}/include\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 lib/pkgconfig)
78endfunction(install_pkg_config_file)
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index 49ca7c83..ecbb65c2 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -37,3 +37,9 @@ if(WIN32)
37 target_link_libraries(toxcore ws2_32) 37 target_link_libraries(toxcore ws2_32)
38endif() 38endif()
39 39
40execute_process(COMMAND git rev-list HEAD --count OUTPUT_VARIABLE COMMIT)
41
42# Write pkgconfig-file:
43include(InstallPkgConfigFile)
44install_pkg_config_file(toxcore CFLAGS LIBS -ltoxcore REQUIRES VERSION 0.1.1_r${COMMIT})
45