aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2009-08-03 21:31:25 +0000
committerGravatar kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2009-08-03 21:31:25 +0000
commit3c66c2e6418246e8b802a6ad101ac752ac11eb25 (patch)
treef8f6720f22f1ecc9bd45c82f9b8b722fcbb6dfc9
parentad2cfe03751debb67a61bc4e4a2047ff9a235a8f (diff)
Allow dependents to use pkg-config to figure out what flags to pass to link against protobuf.
-rw-r--r--Makefile.am3
-rw-r--r--README.txt38
-rw-r--r--configure.ac2
-rw-r--r--examples/Makefile6
-rw-r--r--protobuf-lite.pc.in13
-rw-r--r--protobuf.pc.in13
6 files changed, 72 insertions, 3 deletions
diff --git a/Makefile.am b/Makefile.am
index ff3835c5..c311fe02 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -32,6 +32,9 @@ clean-local:
cd gtest && $(MAKE) $(AM_MAKEFLAGS) clean; \
fi
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = protobuf.pc protobuf-lite.pc
+
EXTRA_DIST = \
autogen.sh \
generate_descriptor_proto.sh \
diff --git a/README.txt b/README.txt
index daacfb26..a8f66044 100644
--- a/README.txt
+++ b/README.txt
@@ -33,6 +33,44 @@ For advanced usage information on configure and make, see INSTALL.txt.
If you already built the package with a different prefix, make sure
to run "make clean" before building again.
+** Compiling dependent packages **
+
+ To compile a package that uses Protocol Buffers, you need to pass
+ various flags to your compiler and linker. As of version 2.2.0,
+ Protocol Buffers integrates with pkg-config to manage this. If you
+ have pkg-config installed, then you can invoke it to get a list of
+ flags like so:
+
+ pkg-config --cflags protobuf # print compiler flags
+ pkg-config --libs protobuf # print linker flags
+ pkg-config --cflags --libs protobuf # print both
+
+ For example:
+
+ c++ my_program.cc my_proto.pb.cc `pkg-config --cflags --libs protobuf`
+
+ Note that packages written prior to the 2.2.0 release of Protocol
+ Buffers may not yet integrate with pkg-config to get flags, and may
+ not pass the correct set of flags to correctly link against
+ libprotobuf. If the package in question uses autoconf, you can
+ often fix the problem by invoking its configure script like:
+
+ configure CXXFLAGS="$(pkg-config --cflags protobuf)" \
+ LIBS="$(pkg-config --libs protobuf)"
+
+ This will force it to use the correct flags.
+
+ If you are writing an autoconf-based package that uses Protocol
+ Buffers, you should probably use the PKG_CHECK_MODULES macro in your
+ configure script like:
+
+ PKG_CHECK_MODULES([protobuf], [protobuf])
+
+ See the pkg-config man page for more info.
+
+ If you only want protobuf-lite, substitute "protobuf-lite" in place
+ of "protobuf" in these examples.
+
** Note for cross-compiling **
The makefiles normally invoke the protoc executable that they just
diff --git a/configure.ac b/configure.ac
index 075d935c..42a7fe70 100644
--- a/configure.ac
+++ b/configure.ac
@@ -119,5 +119,5 @@ AC_CXX_STL_HASH
AC_CONFIG_SUBDIRS([gtest])
-AC_CONFIG_FILES([Makefile src/Makefile ])
+AC_CONFIG_FILES([Makefile src/Makefile protobuf.pc protobuf-lite.pc])
AC_OUTPUT
diff --git a/examples/Makefile b/examples/Makefile
index 36d0280b..8dc90836 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -22,10 +22,12 @@ protoc_middleman: addressbook.proto
@touch protoc_middleman
add_person_cpp: add_person.cc protoc_middleman
- c++ add_person.cc addressbook.pb.cc -lprotobuf -lpthread -o add_person_cpp
+ pkg-config --cflags protobuf # fails if protobuf is not installed
+ c++ add_person.cc addressbook.pb.cc -o add_person_cpp `pkg-config --cflags --libs protobuf`
list_people_cpp: list_people.cc protoc_middleman
- c++ list_people.cc addressbook.pb.cc -lprotobuf -lpthread -o list_people_cpp
+ pkg-config --cflags protobuf # fails if protobuf is not installed
+ c++ list_people.cc addressbook.pb.cc -o list_people_cpp `pkg-config --cflags --libs protobuf`
javac_middleman: AddPerson.java ListPeople.java protoc_middleman
javac AddPerson.java ListPeople.java com/example/tutorial/AddressBookProtos.java
diff --git a/protobuf-lite.pc.in b/protobuf-lite.pc.in
new file mode 100644
index 00000000..29c218e5
--- /dev/null
+++ b/protobuf-lite.pc.in
@@ -0,0 +1,13 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: Protocol Buffers
+Description: Google's Data Interchange Format
+Version: @VERSION@
+Libs: -L${libdir} -lprotobuf-lite @PTHREAD_CFLAGS@ @PTHREAD_LIBS@
+Cflags: -I${includedir} @PTHREAD_CFLAGS@
+# Commented out because it crashes pkg-config *sigh*:
+# http://bugs.freedesktop.org/show_bug.cgi?id=13265
+# Conflicts: protobuf
diff --git a/protobuf.pc.in b/protobuf.pc.in
new file mode 100644
index 00000000..8a53a431
--- /dev/null
+++ b/protobuf.pc.in
@@ -0,0 +1,13 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: Protocol Buffers
+Description: Google's Data Interchange Format
+Version: @VERSION@
+Libs: -L${libdir} -lprotobuf @LIBS@ @PTHREAD_CFLAGS@ @PTHREAD_LIBS@
+Cflags: -I${includedir} @PTHREAD_CFLAGS@
+# Commented out because it crashes pkg-config *sigh*:
+# http://bugs.freedesktop.org/show_bug.cgi?id=13265
+# Conflicts: protobuf-lite