Browse Source

Allow dependents to use pkg-config to figure out what flags to pass to link against protobuf.

kenton@google.com 16 years ago
parent
commit
3c66c2e641
6 changed files with 72 additions and 3 deletions
  1. 3 0
      Makefile.am
  2. 38 0
      README.txt
  3. 1 1
      configure.ac
  4. 4 2
      examples/Makefile
  5. 13 0
      protobuf-lite.pc.in
  6. 13 0
      protobuf.pc.in

+ 3 - 0
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                                               \

+ 38 - 0
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

+ 1 - 1
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

+ 4 - 2
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

+ 13 - 0
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

+ 13 - 0
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