mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Add pkg-config file
Generate and install a toxcore.pc file to be used with pkg-config.
This commit is contained in:
parent
f8f550e2f0
commit
33ee73fffa
78
cmake/InstallPkgConfigFile.cmake
Normal file
78
cmake/InstallPkgConfigFile.cmake
Normal file
|
@ -0,0 +1,78 @@
|
|||
# A Macro to simplify creating a pkg-config file
|
||||
|
||||
# install_pkg_config_file(<package-name>
|
||||
# [VERSION <version>]
|
||||
# [DESCRIPTION <description>]
|
||||
# [CFLAGS <cflag> ...]
|
||||
# [LIBS <lflag> ...]
|
||||
# [REQUIRES <required-package-name> ...])
|
||||
#
|
||||
# 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)
|
|
@ -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})
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user