Commit 12215b47 authored by Robert Edmonds's avatar Robert Edmonds

remove the current build system

parent 1d1ad931
cmake_minimum_required(VERSION 2.8)
project(protobuf-c)
set(PROTOBUF_C_VERSION_MAJOR 0)
set(PROTOBUF_C_VERSION_MINOR 14)
set(PROTOBUF_C_VERSION_PATCH 1)
set(PROTOBUF_C_VERSION ${PROTOBUF_C_VERSION_MAJOR}.${PROTOBUF_C_VERSION_MINOR})
set(CMAKE_ROOT_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/${PROJECT_NAME}-${CMAKE_SYSTEM}
CACHE PATH "root output directory in which to locate target files")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_ROOT_OUTPUT_DIRECTORY}/bin
CACHE PATH "output directory in which to build runtime target files")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_ROOT_OUTPUT_DIRECTORY}/lib
CACHE PATH "output directory in which to build library target files")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ROOT_OUTPUT_DIRECTORY}/lib
CACHE PATH "output directory in which to build archive target files")
function(process_libprotobuf_c_pc)
set(prefix ${PROTOBUF_C_INSTALL_PREFIX})
set(exec_prefix ${PROTOBUF_C_INSTALL_EXEC_PREFIX})
set(libdir ${PROTOBUF_C_INSTALL_LIBDIR})
set(includedir ${PROTOBUF_C_INSTALL_INCLUDEDIR})
set(VERSION ${PROTOBUF_C_VERSION})
configure_file(libprotobuf-c.pc.in
${CMAKE_ROOT_OUTPUT_DIRECTORY}/pkgconfig/libprotobuf-c.pc @ONLY)
install(DIRECTORY ${CMAKE_ROOT_OUTPUT_DIRECTORY}/pkgconfig DESTINATION
${PROTOBUF_C_INSTALL_LIBDIR})
endfunction()
set(PROTOBUF_C_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}
CACHE PATH "install location for architecture-independent files")
set(PROTOBUF_C_INSTALL_EXEC_PREFIX ${CMAKE_INSTALL_PREFIX}
CACHE PATH "install location for architecture-dependent files")
if ( UNIX )
set(PROTOBUF_C_INSTALL_BINDIR ${PROTOBUF_C_INSTALL_EXEC_PREFIX}/bin
CACHE PATH "install location for executable files")
set(PROTOBUF_C_INSTALL_LIBDIR ${PROTOBUF_C_INSTALL_EXEC_PREFIX}/lib
CACHE PATH "install location for object code libraries")
set(PROTOBUF_C_INSTALL_INCLUDEDIR ${PROTOBUF_C_INSTALL_PREFIX}/include
CACHE PATH "install location for public header files")
process_libprotobuf_c_pc()
else()
set(PROTOBUF_C_INSTALL_BINDIR bin
CACHE PATH "install location for executable files")
set(PROTOBUF_C_INSTALL_LIBDIR lib
CACHE PATH "install location for object code libraries")
set(PROTOBUF_C_INSTALL_INCLUDEDIR include
CACHE PATH "install location for public header files")
endif()
enable_testing()
add_subdirectory(src)
# Use "make package" or something like that to create a protobuf-c package.
set(CPACK_PACKAGE_CONTACT "David Benson <daveb@ffem.org>")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "C bindings for protocol-buffers")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_VERSION_MAJOR "${PROTOBUF_C_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${PROTOBUF_C_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${PROTOBUF_C_VERSION_PATCH}")
if ( WIN32 )
set(CPACK_GENERATOR ZIP)
else()
# Look at http://public.kitware.com/Bug/view.php?id=7000
set(CPACK_SET_DESTDIR "ON")
set(CPACK_GENERATOR DEB)
set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
set(CPACK_DEBIAN_PACKAGE_PRIORITY "low")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://code.google.com/p/protobuf-c")
endif()
include(CPack)
SUBDIRS = src
EXTRA_DIST = scripts pkgwriteinfo.in CMakeLists.txt LICENSE
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libprotobuf-c.pc
dist-hook:
scripts/assert-version-numbers-match
# --- packages ---
DEBARCH = `dpkg --print-architecture`
deb:
test -r protobuf-c-@VERSION@.tar.gz || $(MAKE) dist
$(srcdir)/scripts/pkgwrite --format=debian \
--tarball=protobuf-c-@VERSION@.tar.gz \
--output=protobuf-c-packages \
--pkgwriteinfo-file=pkgwriteinfo \
--arch=$(DEBARCH)
#! /bin/sh -e
./bootstrap
./configure "$@"
#! /bin/sh -e
libtoolize
aclocal$automake_version
autoconf
automake$automake_version -a --foreign
AC_INIT([protobuf-c], [0.15])
AM_INIT_AUTOMAKE([1.9 foreign])
PACKAGE=protobuf-c
AC_PROG_CC
AC_PROG_CXX
AC_PROG_LIBTOOL
AC_PATH_PROG(PROTOC, protoc)
AC_CHECK_HEADERS(inttypes.h)
AC_CHECK_HEADERS(sys/poll.h)
AC_CHECK_HEADERS(sys/select.h)
AC_CHECK_HEADERS(alloca.h)
AC_CHECK_HEADERS(malloc.h)
AC_CHECK_HEADERS(winsock.h)
AC_CHECK_HEADERS(io.h)
AC_CHECK_HEADERS(sys/uio.h)
AC_CHECK_HEADERS(unistd.h)
BUILD_PROTOC_C=1
AC_ARG_ENABLE(protoc, [ --disable-protoc Suppress build of protoc_c],
if test "x$enableval" = xno ; then
BUILD_PROTOC_C=0
fi)
AM_CONDITIONAL(BUILD_PROTOC_C, test $BUILD_PROTOC_C = 1)
# --- Check for the protobuf library. ---
if test $BUILD_PROTOC_C = 1; then
AC_LANG_PUSH([C++])
AC_CHECK_HEADER(google/protobuf/stubs/common.h,,
[AC_MSG_ERROR([
ERROR: protobuf headers are required.
You must either install protobuf from google,
or if you have it installed in a custom location
you must add '-Iincludedir' to CXXFLAGS
and '-Llibdir' to LDFLAGS.
You can download the google's protobuf library from
the following page:
http://code.google.com/p/protobuf/downloads/list
If you did not specify a prefix when installing
protobuf, try
'./configure CXXFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib'
In some 64-bit environments, try LDFLAGS=-L/usr/local/lib64.
])])
pbc_savelibs="$LIBS"
LIBS="$LIBS -lprotoc -lprotobuf -lpthread"
AC_TRY_LINK([#include <google/protobuf/compiler/command_line_interface.h>],
[google::protobuf::compiler::CommandLineInterface cli;],
[],
[AC_MSG_ERROR([
ERROR:
protobuf test program failed to link:
perhaps you need to add -Llibdir to your LDFLAGS.])])
LIBS="$pbc_savelibs"
AC_LANG_POP()
dnl We need $PROTOC around for the test code generation.
dnl This is merely needed for c++ packed-data comparison.
if test "x$PROTOC" = x; then
echo "ERROR: missing google's protoc program; adjust \$PATH (or use --disable-protoc)" 1>&2
exit 1
fi
fi
dnl ------ define IS_LITTLE_ENDIAN ------
# We try to use, where possible the headers <endian.h>, <mach/endian.h>,
# and <machine/endian.h>, in that order. They must define the macros
# __LITTLE_ENDIAN and __BYTE_ORDER. We structure the test so that if they
# do NOT define __LITTLE_ENDIAN or __BYTE_ORDER then we will disable
# the little-endian optimizations, so the resulting code should be correct,
# but not as fast, if there's a broken endian.h somewhere.
#
# If none of those headers exist, we fallback on a runtime test.
knows_endianness=0
AC_ARG_WITH([endianness],
[AS_HELP_STRING([--with-endianness=[little|big]],
[use the given endianness instead of testing headers (useful for mingw)])],
[],[with_endianness=no])
AS_IF([test "$with_endianness" != "no"], [
AS_IF([test "$with_endianness" == "little"], [
is_little_endian=1
], [
AS_IF([test "$with_endianness" == "big"], [
is_little_endian=0
], [
AC_MSG_FAILURE([--with-endianness argument must be 'little' or 'big'])
])
])
knows_endianness=1
])
AS_IF([test $knows_endianness = 0], [
AC_CHECK_HEADERS([endian.h], [has_endian_h=1; knows_endianness=1], [has_endian_h=0])
if test $knows_endianness = 1 ; then
AC_TRY_COMPILE([#include <endian.h>], [
switch (1) { case __LITTLE_ENDIAN: break;
case __BYTE_ORDER: break; } ],
[is_little_endian=0], [is_little_endian=1])
else
# ------------------ try <mach/endian.h> ------------------
AC_CHECK_HEADERS([mach/endian.h], [has_mach_endian_h=1; knows_endianness=1], [has_mach_endian_h=0])
if test $knows_endianness = 1 ; then
AC_TRY_COMPILE([#include <mach/endian.h>],[
switch (1) { case __LITTLE_ENDIAN: break;
case __BYTE_ORDER: break; } ],
[is_little_endian=0], [is_little_endian=1])
fi
# ------------------ try <machine/endian.h> ------------------
if test $knows_endianness = 0; then
AC_CHECK_HEADERS([machine/endian.h], [has_machine_endian_h=1; knows_endianness=1], [has_machine_endian_h=0])
if test $knows_endianness = 1 ; then
AC_TRY_COMPILE([#include <machine/endian.h>],[
switch (1) { case __LITTLE_ENDIAN: break;
case __BYTE_ORDER: break; } ],
[is_little_endian=0], [is_little_endian=1])
fi
fi
if test $knows_endianness = 0; then
AC_MSG_CHECKING([for little-endianness via runtime check])
AC_RUN_IFELSE([#include <inttypes.h>
int main() {
uint32_t v = 0x01020304;
return memcmp (&v, "\4\3\2\1", 4) == 0 ? 0 : 1;
}
], [is_little_endian=1; result=yes], [is_little_endian=0; result=no])
AC_MSG_RESULT($result)
fi
fi
])
if test $is_little_endian = 1; then
echo "Your system IS little-endian" 1>&2
else
echo "Your system IS NOT little-endian" 1>&2
fi
AC_DEFINE_UNQUOTED(IS_LITTLE_ENDIAN, $is_little_endian)
AC_OUTPUT(Makefile src/Makefile src/test/Makefile pkgwriteinfo libprotobuf-c.pc)
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: libprotobuf-c
Description: C-API for Google's protocol buffers
Version: @VERSION@
URL: http://code.google.com/p/protobuf-c/
Requires:
Libs: -L${libdir} -lprotobuf-c
Cflags: -I${includedir}
Package: protobuf-c
Section: libs
Group: Development/Libraries
Priority: low
Author: David Benson <daveb@ffem.org>
Packager: Dave Benson
Packager-Email: daveb@ffem.org
Version: @VERSION@
Release: 1
License: private
Synopsis: C bindings for protocol-buffers
Description: protobuf or protocol-buffers is google's
language for describing extensible binary data formats.
Build: normal
Target: {MAIN}
Files: /usr/bin/protoc-c
Files: /usr/include/google/protobuf-c/*.h
Files: /usr/lib/libprotobuf-c.*
Which-Build: normal
Synopsis: C bindings for protocol-buffers
Description: protobuf or protocol-buffers is google's
language for describing extensible binary data formats.
#! /usr/bin/perl
my $srcdir = $ENV{srcdir} || ".";
# get numbers from ChangeLog
open IN, "<$srcdir/ChangeLog" or die "error opening $srcdir/ChangeLog";
my $line = scalar(<IN>);
if ($line =~ /\d+\.\d+ \((NOT.*)\)/) {
die "ChangeLog still bears $1 (line 1)";
}
if ($line !~ /^(\d+\.\d+):\s*/) {
die "ChangeLog parse error (line 1)";
}
my $changelog_version = $1;
# get numbers from protobuf-c.h
open IN, "<$srcdir/src/google/protobuf-c/protobuf-c.h" or die "error opening $srcdir/src/google/protobuf-c/protobuf-c.h";
while (<IN>)
{
if (/^\#define\s+PROTOBUF_C_MAJOR\s+(\d+)\s*$/)
{ $c_major = $1; }
if (/^\#define\s+PROTOBUF_C_MINOR\s+(\d+)\s*$/)
{ $c_minor = $1; }
}
if (!defined $c_minor || !defined $c_major)
{ die "missing PROTOBUF_C_MINOR or PROTOBUF_C_MAJOR in protobuf-c.h" }
$c_version = "$c_major.$c_minor";
# get numbers from configure.ac
open IN, "<$srcdir/configure.ac" or die "error opening $srcdir/configure.ac";
my $line = scalar(<IN>);
die "first line of configure.ac did not match our expectations"
unless $line =~ /AC_INIT\(\[protobuf-c\], \[(\d+\.\d+)\]\)/;
my $configure_version = $1;
if ($c_version ne $configure_version || $c_version ne $changelog_version)
{
print STDERR <<"EOF";
Versions mismatched:
from configure.ac $configure_version
from ChangeLog $changelog_version
from protobuf-c.h $c_version
EOF
exit(1);
}
exit(0);
#! /bin/sh
die () {
echo "$1" 1>&2
exit 1
}
die_unless_set () {
eval "isset=\$$1"
test -z "$isset" && die "$1 not set"
}
# test_is_equal DEFINE_TYPE SIZEOF_TYPE EVAL_IF_TRUE
test_is_equal () {
# Write out C file
cat > test-compile-for-structure-packing-0.c <<EOF
#include <inttypes.h>
$1;
int main ()
{
/* Program does not compile iff alignof(int32_t) is 2 */
switch (0) { case $2: case sizeof(TYPE): ; }
}
EOF
# If it DOESN'T compile, then the values are equal.
$CC -o /dev/null test-compile-for-structure-packing-0.c > /dev/null 2>&1 || { eval "$3" ; }
rm -f test-compile-for-structure-packing-0.c
}
test_is_not_equal () {
# Write out C file
cat > test-compile-for-structure-packing-0.c <<EOF
#include <inttypes.h>
$1;
int main ()
{
/* Program does not compile iff alignof(int32_t) is 2 */
switch (0) { case $2: case sizeof(TYPE): ; }
}
EOF
# If it DOESN'T compile, then the values are equal.
$CC -o /dev/null test-compile-for-structure-packing-0.c > /dev/null 2>&1 && { eval "$3" ; }
rm -f test-compile-for-structure-packing-0.c
}
test_is_equal "typedef int TYPE" 2 "SIZEOF_INT=2"
test_is_equal "typedef int TYPE" 4 "SIZEOF_INT=4"
test_is_equal "typedef int TYPE" 8 "SIZEOF_INT=8"
die_unless_set SIZEOF_INT
test_is_equal "typedef void* TYPE" 2 "SIZEOF_POINTER=2"
test_is_equal "typedef void* TYPE" 4 "SIZEOF_POINTER=4"
test_is_equal "typedef void* TYPE" 8 "SIZEOF_POINTER=8"
die_unless_set SIZEOF_POINTER
test_is_not_equal "typedef float TYPE" 4 'die "expecting float to be 4 bytes"'
test_is_not_equal "typedef double TYPE" 8 'die "expecting double to be 4 bytes"'
test_is_equal "typedef struct { char c; int32_t i; }" 5 "ALIGNOF_INT32=1"
test_is_equal "typedef struct { char c; int32_t i; }" 6 "ALIGNOF_INT32=2"
test_is_equal "typedef struct { char c; int32_t i; }" 8 "ALIGNOF_INT32=4"
die_unless_set ALIGNOF_INT32
test_is_equal "typedef struct { char c; int64_t i; }" 9 "ALIGNOF_INT64=1"
test_is_equal "typedef struct { char c; int64_t i; }" 10 "ALIGNOF_INT64=2"
test_is_equal "typedef struct { char c; int64_t i; }" 12 "ALIGNOF_INT64=4"
test_is_equal "typedef struct { char c; int64_t i; }" 16 "ALIGNOF_INT64=8"
die_unless_set ALIGNOF_INT64
test_is_equal "typedef struct { char c; float i; }" 5 "ALIGNOF_FLOAT=1"
test_is_equal "typedef struct { char c; float i; }" 6 "ALIGNOF_FLOAT=2"
test_is_equal "typedef struct { char c; float i; }" 8 "ALIGNOF_FLOAT=4"
die_unless_set ALIGNOF_FLOAT
test_is_equal "typedef struct { char c; double i; }" 9 "ALIGNOF_DOUBLE=1"
test_is_equal "typedef struct { char c; double i; }" 10 "ALIGNOF_DOUBLE=2"
test_is_equal "typedef struct { char c; double i; }" 12 "ALIGNOF_DOUBLE=4"
test_is_equal "typedef struct { char c; double i; }" 16 "ALIGNOF_DOUBLE=8"
die_unless_set ALIGNOF_DOUBLE
case "$SIZEOF_POINTER" in
2)
test_is_equal "typedef struct { char c; void *i; }" 3 "ALIGNOF_POINTER=1"
test_is_equal "typedef struct { char c; void *i; }" 4 "ALIGNOF_POINTER=2"
;;
4)
test_is_equal "typedef struct { char c; void *i; }" 5 "ALIGNOF_POINTER=1"
test_is_equal "typedef struct { char c; void *i; }" 6 "ALIGNOF_POINTER=2"
test_is_equal "typedef struct { char c; void *i; }" 8 "ALIGNOF_POINTER=4"
;;
8)
test_is_equal "typedef struct { char c; void *i; }" 9 "ALIGNOF_POINTER=1"
test_is_equal "typedef struct { char c; void *i; }" 10 "ALIGNOF_POINTER=2"
test_is_equal "typedef struct { char c; void *i; }" 12 "ALIGNOF_POINTER=4"
test_is_equal "typedef struct { char c; void *i; }" 16 "ALIGNOF_POINTER=8"
;;
*)
die "bad SIZEOF_POINTER=$SIZEOF_POINTER"
esac
die_unless_set ALIGNOF_POINTER
case "$SIZEOF_INT" in
2) ALIGNOF_INT=$ALIGNOF_INT16 ;;
4) ALIGNOF_INT=$ALIGNOF_INT32 ;;
8) ALIGNOF_INT=$ALIGNOF_INT64 ;;
*) die "bad SIZEOF_INT=$SIZEOF_INT" ;;
esac
for a in SIZEOF_INT SIZEOF_POINTER \
ALIGNOF_INT16 ALIGNOF_INT32 ALIGNOF_INT64 ALIGNOF_INT ALIGNOF_POINTER
do
eval "v=\$$a"
echo "#define $a $v"
done
This source diff could not be displayed because it is too large. You can view the blob instead.
set(BUILD_PROTOBUF_C_COMPILER ON
CACHE BOOL "build protobuf-c compiler (aka protoc-c)")
if ( BUILD_PROTOBUF_C_COMPILER )
find_package(Protobuf REQUIRED)
include_directories(${PROTOBUF_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR})
set(PROTOC_C_SOURCES
google/protobuf/compiler/c/c_service.cc
google/protobuf/compiler/c/c_helpers.cc
google/protobuf/compiler/c/c_enum.cc
google/protobuf/compiler/c/c_enum_field.cc
google/protobuf/compiler/c/c_string_field.cc
google/protobuf/compiler/c/c_primitive_field.cc
google/protobuf/compiler/c/c_extension.cc
google/protobuf/compiler/c/c_file.cc
google/protobuf/compiler/c/c_field.cc
google/protobuf/compiler/c/c_message.cc
google/protobuf/compiler/c/c_generator.cc
google/protobuf/compiler/c/c_message_field.cc
google/protobuf/compiler/c/main.cc
google/protobuf/compiler/c/c_bytes_field.cc)
add_executable(protoc-c ${PROTOC_C_SOURCES})
target_link_libraries(protoc-c ${PROTOBUF_LIBRARY}
${PROTOBUF_PROTOC_LIBRARY})
if ( UNIX )
find_package(Threads REQUIRED)
target_link_libraries(protoc-c ${CMAKE_THREAD_LIBS_INIT})
endif()
install(TARGETS protoc-c DESTINATION ${PROTOBUF_C_INSTALL_BINDIR})
endif()
include(CheckIncludeFiles)
check_include_files("alloca.h" HAVE_ALLOCA_H)
check_include_files("malloc.h" HAVE_MALLOC_H)
check_include_files("sys/poll.h" HAVE_SYS_POLL_H)
check_include_files("sys/select.h" HAVE_SYS_SELECT_H)
check_include_files("inttypes.h" HAVE_INTTYPES_H)
check_include_files("sys/uio.h" HAVE_SYS_UIO_H)
check_include_files("unistd.h" HAVE_UNISTD_H)
check_include_files("io.h" HAVE_IO_H)
include(TestBigEndian)
test_big_endian(IS_BIG_ENDIAN)
if ( NOT IS_BIG_ENDIAN )
set(IS_LITTLE_ENDIAN 1)
endif()
add_definitions(-DHAVE_PROTOBUF_C_CONFIG_H=1)
configure_file(google/protobuf-c/protobuf-c-config.h.in
google/protobuf-c/protobuf-c-config.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/google/protobuf-c)
set(BUILD_PROTOBUF_C_STATIC_LIB ON
CACHE BOOL "build static protobuf-c library")
set(BUILD_PROTOBUF_C_SHARED_LIB ON
CACHE BOOL "build shared protobuf-c library")
if ( WIN32 )
set(PROTOBUF_C_SOURCES
google/protobuf-c/protobuf-c-data-buffer.c
google/protobuf-c/protobuf-c.c)
else()
set(PROTOBUF_C_SOURCES
google/protobuf-c/protobuf-c-dispatch.c
google/protobuf-c/protobuf-c-data-buffer.c
google/protobuf-c/protobuf-c-rpc.c
google/protobuf-c/protobuf-c.c)
endif()
if ( BUILD_PROTOBUF_C_STATIC_LIB )
add_library(protobuf-c-static STATIC ${PROTOBUF_C_SOURCES})
install(TARGETS protobuf-c-static
ARCHIVE DESTINATION ${PROTOBUF_C_INSTALL_LIBDIR})
set_target_properties(protobuf-c-static PROPERTIES OUTPUT_NAME protobuf-c)
get_target_property(DIRECTORY protobuf-c-static ARCHIVE_OUTPUT_DIRECTORY)
set_target_properties(protobuf-c-static PROPERTIES ARCHIVE_OUTPUT_DIRECTORY
${DIRECTORY}/static)
endif()
if ( BUILD_PROTOBUF_C_SHARED_LIB )
add_library(protobuf-c-shared SHARED ${PROTOBUF_C_SOURCES})
install(TARGETS protobuf-c-shared
RUNTIME DESTINATION ${PROTOBUF_C_INSTALL_BINDIR}
LIBRARY DESTINATION ${PROTOBUF_C_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${PROTOBUF_C_INSTALL_LIBDIR}/dllimport)
set_target_properties(protobuf-c-shared PROPERTIES OUTPUT_NAME protobuf-c)
set_target_properties(protobuf-c-shared PROPERTIES VERSION
${PROTOBUF_C_VERSION})
get_target_property(DIRECTORY protobuf-c-shared ARCHIVE_OUTPUT_DIRECTORY)
set_target_properties(protobuf-c-shared PROPERTIES ARCHIVE_OUTPUT_DIRECTORY
${DIRECTORY}/shared)
get_target_property(DIRECTORY protobuf-c-shared LIBRARY_OUTPUT_DIRECTORY)
set_target_properties(protobuf-c-shared PROPERTIES LIBRARY_OUTPUT_DIRECTORY
${DIRECTORY}/shared)
if ( WIN32 )
set_target_properties(protobuf-c-shared PROPERTIES COMPILE_DEFINITIONS
"PROTOBUF_C_USE_SHARED_LIB;PROTOBUF_C_EXPORT")
endif()
endif()
if ( BUILD_PROTOBUF_C_STATIC_LIB OR BUILD_PROTOBUF_C_SHARED_LIB )
if ( WIN32 )
set(PROTOBUF_C_PUBLIC_HEADERS
google/protobuf-c/protobuf-c.h
google/protobuf-c/protobuf-c-private.h)
else()
set(PROTOBUF_C_PUBLIC_HEADERS
google/protobuf-c/protobuf-c.h
google/protobuf-c/protobuf-c-private.h
google/protobuf-c/protobuf-c-dispatch.h
google/protobuf-c/protobuf-c-rpc.h)
endif()
install(FILES ${PROTOBUF_C_PUBLIC_HEADERS} DESTINATION
${PROTOBUF_C_INSTALL_INCLUDEDIR})
endif()
add_subdirectory(test)
if BUILD_PROTOC_C
SUBDIRS = . test
bin_PROGRAMS = protoc-c
protoc_c_SOURCES = \
google/protobuf/compiler/c/c_service.cc \
google/protobuf/compiler/c/c_helpers.cc \
google/protobuf/compiler/c/c_enum.cc \
google/protobuf/compiler/c/c_enum_field.cc \
google/protobuf/compiler/c/c_string_field.cc \
google/protobuf/compiler/c/c_primitive_field.cc \
google/protobuf/compiler/c/c_extension.cc \
google/protobuf/compiler/c/c_file.cc \
google/protobuf/compiler/c/c_field.cc \
google/protobuf/compiler/c/c_message.cc \
google/protobuf/compiler/c/c_generator.cc \
google/protobuf/compiler/c/c_message_field.cc \
google/protobuf/compiler/c/main.cc \
google/protobuf/compiler/c/c_bytes_field.cc
protoc_c_LDADD = \
-lprotoc -lprotobuf -lpthread
endif
lib_LTLIBRARIES = libprotobuf-c.la
protobufcincludedir = $(includedir)/google/protobuf-c
EXTRA_DIST = CMakeLists.txt test/CMakeLists.txt
libprotobuf_c_la_SOURCES = \
google/protobuf-c/protobuf-c-dispatch.c \
google/protobuf-c/protobuf-c-data-buffer.c \
google/protobuf-c/protobuf-c-rpc.c \
google/protobuf-c/protobuf-c.c
# ah, -no-undefined, goofball windows hack.
# the documentation for this is rather confusing to me,
# but suffice it to say this is needed
# on a few garbage platforms (AIX, windows),
# and it compiles to a no-op on sensible platforms (elf)
libprotobuf_c_la_LDFLAGS = \
-no-undefined \
-version-info 0:0:0
noinst_HEADERS = \
google/protobuf/compiler/c/c_message_field.h \
google/protobuf/compiler/c/c_service.h \
google/protobuf/compiler/c/c_helpers.h \
google/protobuf/compiler/c/c_enum.h \
google/protobuf/compiler/c/c_enum_field.h \
google/protobuf/compiler/c/c_string_field.h \
google/protobuf/compiler/c/c_primitive_field.h \
google/protobuf/compiler/c/c_extension.h \
google/protobuf/compiler/c/c_file.h \
google/protobuf/compiler/c/c_field.h \
google/protobuf/compiler/c/c_message.h \
google/protobuf/compiler/c/c_generator.h \
google/protobuf/compiler/c/c_bytes_field.h \
google/protobuf-c/protobuf-c-data-buffer.h \
google/protobuf-c/gskrbtreemacros.h \
google/protobuf-c/gsklistmacros.h
protobufcinclude_HEADERS = \
google/protobuf-c/protobuf-c.h \
google/protobuf-c/protobuf-c-private.h \
google/protobuf-c/protobuf-c-dispatch.h \
google/protobuf-c/protobuf-c-rpc.h
if ( BUILD_PROTOBUF_C_COMPILER AND BUILD_PROTOBUF_C_STATIC_LIB )
function(BUILD_C_TEST target_name proto_name)
set(TMP_OUTPUT_DIR ${CMAKE_BINARY_DIR}/${target_name}/generated-code)
file(MAKE_DIRECTORY ${TMP_OUTPUT_DIR})
set(GENERATED_SOURCES ${TMP_OUTPUT_DIR}/${proto_name}.pb-c.h
${TMP_OUTPUT_DIR}/${proto_name}.pb-c.c)
add_executable(${target_name} ${target_name}.c ${GENERATED_SOURCES}
${ARGN})
set_target_properties(${target_name} PROPERTIES COMPILE_FLAGS
"-I${CMAKE_BINARY_DIR}/${target_name}")
target_link_libraries(${target_name} protobuf-c-static)
add_custom_command(OUTPUT ${GENERATED_SOURCES}
COMMAND protoc-c -I${CMAKE_CURRENT_SOURCE_DIR}
--c_out=${TMP_OUTPUT_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/${proto_name}.proto
DEPENDS protoc-c ${CMAKE_CURRENT_SOURCE_DIR}/${proto_name}.proto
COMMENT "Running C protocol buffer compiler on ${proto_name}"
VERBATIM)
endfunction()
function(BUILD_CPP_TEST target_name proto_name)
set(TMP_OUTPUT_DIR ${CMAKE_BINARY_DIR}/${target_name}/generated-code)
file(MAKE_DIRECTORY ${TMP_OUTPUT_DIR})
set(GENERATED_SOURCES ${TMP_OUTPUT_DIR}/${proto_name}.pb.h
${TMP_OUTPUT_DIR}/${proto_name}.pb.cc)
add_executable(${target_name} ${target_name}.cc ${GENERATED_SOURCES}
${ARGN})
set_target_properties(${target_name} PROPERTIES COMPILE_FLAGS
"-I${CMAKE_BINARY_DIR}/${target_name} -I${PROTOBUF_INCLUDE_DIRS}")
target_link_libraries(${target_name} ${PROTOBUF_LIBRARIES})
if ( UNIX )
find_package(Threads REQUIRED)
target_link_libraries(${target_name} ${CMAKE_THREAD_LIBS_INIT})
endif()
add_custom_command(OUTPUT ${GENERATED_SOURCES}
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} -I${CMAKE_CURRENT_SOURCE_DIR}
--cpp_out=${TMP_OUTPUT_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/${proto_name}.proto
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${proto_name}.proto
COMMENT "Running C++ protocol buffer compiler on ${proto_name}"
VERBATIM)
endfunction()
build_cpp_test(cxx-generate-packed-data test-full)
set(TMP_OUTPUT_DIR ${CMAKE_BINARY_DIR}/cxx-generate-packed-data)
file(MAKE_DIRECTORY ${TMP_OUTPUT_DIR}/generated-code)
set(GENERATED_INC_FILE ${TMP_OUTPUT_DIR}/generated-code/test-full-cxx-output.inc)
add_custom_command(OUTPUT ${GENERATED_INC_FILE}
COMMAND cxx-generate-packed-data > ${GENERATED_INC_FILE}
DEPENDS cxx-generate-packed-data)
build_c_test(test-generated-code2 test-full ${GENERATED_INC_FILE})
get_target_property(EXTRA_COMPILE_FLAGS test-generated-code2
COMPILE_FLAGS)
set(EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -I${TMP_OUTPUT_DIR}")
set_target_properties(test-generated-code2 PROPERTIES COMPILE_FLAGS
${EXTRA_COMPILE_FLAGS})
add_test(NAME test-generated-code2 COMMAND test-generated-code2)
build_c_test(test-generated-code test)
add_test(NAME test-generated-code COMMAND test-generated-code)
if ( UNIX )
build_c_test(test-rpc test)
build_c_test(example-client test)
build_c_test(example-server test)
add_test(NAME test-rpc COMMAND test-rpc)
endif()
endif()
check_PROGRAMS = test-generated-code test-generated-code2 test-rpc
noinst_PROGRAMS = cxx-generate-packed-data example-server example-client
INCLUDES = -I$(srcdir)/..
test_generated_code_SOURCES = \
test-generated-code.c \
generated-code/test.pb-c.c
test_generated_code_LDADD = \
../libprotobuf-c.la
test_generated_code2_SOURCES = \
test-generated-code2.c \
generated-code/test-full.pb-c.c
test_generated_code2_LDADD = \
../libprotobuf-c.la
test_rpc_SOURCES = \
test-rpc.c \
generated-code/test.pb-c.c
test_rpc_LDADD = \
../libprotobuf-c.la
cxx_generate_packed_data_SOURCES = \
cxx-generate-packed-data.cc generated-code/test-full.pb.cc
cxx-generate-packed-data.$(OBJEXT): generated-code/test-full.pb.h
cxx_generate_packed_data_LDADD = -lprotobuf
cxx_generate_packed_data_LDFLAGS = -pthread
example_server_SOURCES = \
example-server.c generated-code/test.pb-c.c
example_server_LDADD = ../libprotobuf-c.la
example_client_SOURCES = \
example-client.c generated-code/test.pb-c.c
example_client_LDADD = ../libprotobuf-c.la
generated-code/test.pb-c.c generated-code/test.pb-c.h: ../protoc-c$(EXEEXT) $(srcdir)/test.proto
mkdir -p generated-code
../protoc-c -I$(srcdir) --c_out=generated-code $(srcdir)/test.proto
generated-code/test-full.pb-c.c generated-code/test-full.pb-c.h: ../protoc-c $(srcdir)/test-full.proto
mkdir -p generated-code
../protoc-c -I$(srcdir) --c_out=generated-code $(srcdir)/test-full.proto
generated-code/test-full.pb.cc generated-code/test-full.pb.h: $(srcdir)/test-full.proto @PROTOC@
mkdir -p generated-code
@PROTOC@ -I$(srcdir) --cpp_out=generated-code $(srcdir)/test-full.proto
generated-code/test-full-cxx-output.inc: cxx-generate-packed-data$(EXEEXT)
./cxx-generate-packed-data > generated-code/test-full-cxx-output.inc
BUILT_SOURCES = generated-code/test.pb-c.c generated-code/test.pb-c.h \
generated-code/test-full.pb-c.c generated-code/test-full.pb-c.h \
generated-code/test-full.pb.cc generated-code/test-full.pb.h \
generated-code/test-full-cxx-output.inc
DISTCLEANFILES = $(BUILT_SOURCES)
TESTS = test-generated-code test-generated-code2 test-rpc
EXTRA_DIST = test.proto test-full.proto common-test-arrays.h
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment