From 33ee73fffaf0fb44d280b8bae16ec9dae15956d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Arg=C3=BCelles?= Date: Fri, 23 Aug 2013 15:31:24 -0500 Subject: [PATCH] Add pkg-config file Generate and install a toxcore.pc file to be used with pkg-config. --- cmake/InstallPkgConfigFile.cmake | 78 ++++++++++++++++++++++++++++++++ core/CMakeLists.txt | 6 +++ 2 files changed, 84 insertions(+) create mode 100644 cmake/InstallPkgConfigFile.cmake 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 @@ +# A Macro to simplify creating a pkg-config file + +# install_pkg_config_file( +# [VERSION ] +# [DESCRIPTION ] +# [CFLAGS ...] +# [LIBS ...] +# [REQUIRES ...]) +# +# Create and install a pkg-config .pc file to CMAKE_INSTALL_PREFIX/lib/pkgconfig +# assuming the following install layout: +# libraries: CMAKE_INSTALL_PREFIX/lib +# headers : CMAKE_INSTALL_PREFIX/include +# +# example: +# add_library(mylib mylib.c) +# install_pkg_config_file(mylib +# DESCRIPTION My Library +# CFLAGS +# LIBS -lmylib +# REQUIRES glib-2.0 lcm +# VERSION 0.0.1) +# +# +function(install_pkg_config_file) + list(GET ARGV 0 pc_name) + # TODO error check + + set(pc_version 0.0.1) + set(pc_description ${pc_name}) + set(pc_requires "") + set(pc_libs "") + set(pc_cflags "") + set(pc_fname "${CMAKE_BINARY_DIR}/lib/pkgconfig/${pc_name}.pc") + + set(modewords LIBS CFLAGS REQUIRES VERSION DESCRIPTION) + set(curmode "") + + # parse function arguments and populate pkg-config parameters + list(REMOVE_AT ARGV 0) + foreach(word ${ARGV}) + list(FIND modewords ${word} mode_index) + if(${mode_index} GREATER -1) + set(curmode ${word}) + elseif(curmode STREQUAL LIBS) + set(pc_libs "${pc_libs} ${word}") + elseif(curmode STREQUAL CFLAGS) + set(pc_cflags "${pc_cflags} ${word}") + elseif(curmode STREQUAL REQUIRES) + set(pc_requires "${pc_requires} ${word}") + elseif(curmode STREQUAL VERSION) + set(pc_version ${word}) + set(curmode "") + elseif(curmode STREQUAL DESCRIPTION) + set(pc_description "${word}") + set(curmode "") + else(${mode_index} GREATER -1) + message("WARNING incorrect use of install_pkg_config_file (${word})") + break() + endif(${mode_index} GREATER -1) + endforeach(word) + + # write the .pc file out + file(WRITE ${pc_fname} + "prefix=${CMAKE_INSTALL_PREFIX}\n" + "libdir=\${prefix}/lib\n" + "includedir=\${prefix}/include\n" + "\n" + "Name: ${pc_name}\n" + "Description: ${pc_description}\n" + "Requires: ${pc_requires}\n" + "Version: ${pc_version}\n" + "Libs: -L\${libdir} ${pc_libs}\n" + "Cflags: -I\${includedir} ${pc_cflags}\n") + + # mark the .pc file for installation to the lib/pkgconfig directory + install(FILES ${pc_fname} DESTINATION lib/pkgconfig) +endfunction(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) target_link_libraries(toxcore ws2_32) endif() +execute_process(COMMAND git rev-list HEAD --count OUTPUT_VARIABLE COMMIT) + +# Write pkgconfig-file: +include(InstallPkgConfigFile) +install_pkg_config_file(toxcore CFLAGS LIBS -ltoxcore REQUIRES VERSION 0.1.1_r${COMMIT}) +