Skip to content

Commit

Permalink
Added pkg-config creation (thx to Abe Bachrach)
Browse files Browse the repository at this point in the history
  • Loading branch information
Armin Hornung committed Jun 10, 2011
1 parent 3b89dd5 commit 64d2eec
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ SET(CPACK_PACKAGE_VENDOR "University of Freiburg")
SET(CPACK_GENERATOR "DEB")
SET(CPACK_SOURCE_GENERATOR "TGZ")


include(CMakeModules/InstallPkgConfigFile.cmake)
install_pkg_config_file(octomap
CFLAGS
LIBS -loctomap -loctomath
REQUIRES
VERSION ${V_MAJOR}.${V_MINOR}.${V_PATCH})


INCLUDE(CPack)


Expand Down
78 changes: 78 additions & 0 deletions CMakeModules/InstallPkgConfigFile.cmake
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 64d2eec

Please sign in to comment.