From 269925f77539436045d8a1c2a7d8325d3e8d8c7f Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Wed, 2 Aug 2017 15:03:31 +0200 Subject: [PATCH] Protobuf: CMake (#4846) * Protobuf: CMake This rebuilds protobuf to be build with CMake, so cmake config packages are created and installed, too. Unfurtunately, this drops support for protobuf < 3. * Protobuf CMake: Add .pc files * libprotobuf.a: -fPIC * Protobuf: Minor Updates Updates from upstream review and planned patch inclusion. --- .../builtin/packages/protobuf/package.py | 28 +++++---- .../builtin/packages/protobuf/pkgconfig.patch | 58 +++++++++++++++++++ 2 files changed, 71 insertions(+), 15 deletions(-) create mode 100644 var/spack/repos/builtin/packages/protobuf/pkgconfig.patch diff --git a/var/spack/repos/builtin/packages/protobuf/package.py b/var/spack/repos/builtin/packages/protobuf/package.py index 50b190f70ea..4183330938a 100644 --- a/var/spack/repos/builtin/packages/protobuf/package.py +++ b/var/spack/repos/builtin/packages/protobuf/package.py @@ -25,31 +25,29 @@ from spack import * -class Protobuf(AutotoolsPackage): +class Protobuf(CMakePackage): """Google's data interchange format.""" homepage = "https://developers.google.com/protocol-buffers" url = "https://github.com/google/protobuf/archive/v3.2.0.tar.gz" + root_cmakelists_dir = "cmake" version('3.2.0', '61d899b8369781f6dd1e62370813392d') version('3.1.0', '14a532a7538551d5def317bfca41dace') version('3.0.2', '845b39e4b7681a2ddfd8c7f528299fbb') - version('2.5.0', '9c21577a03adc1879aba5b52d06e25cf') + # does not build with CMake: + # version('2.5.0', '9c21577a03adc1879aba5b52d06e25cf') - depends_on('automake', type='build') - depends_on('autoconf', type='build') - depends_on('libtool', type='build') - depends_on('m4', type='build') + depends_on('zlib') conflicts('%gcc@:4.6') # Requires c++11 - variant('shared', default=True, description='Build shared libraries.') + # first fixed in 3.4.0: https://github.com/google/protobuf/pull/3406 + patch('pkgconfig.patch', when='@:3.3.2') - def configure_args(self): - if '+shared' in self.spec: - return ['--enable-shared=yes', - '--enable-static=no'] - else: - return ['--enable-shared=no', - '--enable-static=yes', - '--with-pic=yes'] + def cmake_args(self): + args = [ + '-Dprotobuf_BUILD_TESTS:BOOL=OFF', + '-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON' + ] + return args diff --git a/var/spack/repos/builtin/packages/protobuf/pkgconfig.patch b/var/spack/repos/builtin/packages/protobuf/pkgconfig.patch new file mode 100644 index 00000000000..a0e8b4b3b72 --- /dev/null +++ b/var/spack/repos/builtin/packages/protobuf/pkgconfig.patch @@ -0,0 +1,58 @@ +diff --git a/cmake/install.cmake b/cmake/install.cmake +index 28dc90d..441bf55 100644 +--- a/cmake/install.cmake ++++ b/cmake/install.cmake +@@ -1,5 +1,10 @@ + include(GNUInstallDirs) + ++configure_file(${CMAKE_CURRENT_SOURCE_DIR}/protobuf.pc.cmake ++ ${CMAKE_CURRENT_BINARY_DIR}/protobuf.pc @ONLY) ++configure_file(${CMAKE_CURRENT_SOURCE_DIR}/protobuf-lite.pc.cmake ++ ${CMAKE_CURRENT_BINARY_DIR}/protobuf-lite.pc @ONLY) ++ + foreach(_library + libprotobuf-lite + libprotobuf +@@ -17,6 +22,8 @@ endforeach() + install(TARGETS protoc EXPORT protobuf-targets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc) + ++install(FILES ${CMAKE_CURRENT_BINARY_DIR}/protobuf.pc ${CMAKE_CURRENT_BINARY_DIR}/protobuf-lite.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") ++ + file(STRINGS extract_includes.bat.in _extract_strings + REGEX "^copy") + foreach(_extract_string ${_extract_strings}) +diff --git a/cmake/protobuf-lite.pc.cmake b/cmake/protobuf-lite.pc.cmake +new file mode 100644 +index 0000000..cbe5426 +--- /dev/null ++++ b/cmake/protobuf-lite.pc.cmake +@@ -0,0 +1,11 @@ ++prefix=@CMAKE_INSTALL_PREFIX@ ++exec_prefix=@CMAKE_INSTALL_PREFIX@ ++libdir=@CMAKE_INSTALL_FULL_LIBDIR@ ++includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ ++ ++Name: Protocol Buffers ++Description: Google's Data Interchange Format ++Version: @protobuf_VERSION@ ++Libs: -L${libdir} -lprotobuf-lite @CMAKE_THREAD_LIBS_INIT@ ++Cflags: -I${includedir} @CMAKE_THREAD_LIBS_INIT@ ++Conflicts: protobuf +diff --git a/cmake/protobuf.pc.cmake b/cmake/protobuf.pc.cmake +new file mode 100644 +index 0000000..2e30763 +--- /dev/null ++++ b/cmake/protobuf.pc.cmake +@@ -0,0 +1,11 @@ ++prefix=@CMAKE_INSTALL_PREFIX@ ++exec_prefix=@CMAKE_INSTALL_PREFIX@ ++libdir=@CMAKE_INSTALL_FULL_LIBDIR@ ++includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ ++ ++Name: Protocol Buffers ++Description: Google's Data Interchange Format ++Version: @protobuf_VERSION@ ++Libs: -L${libdir} -lprotobuf @CMAKE_THREAD_LIBS_INIT@ ++Cflags: -I${includedir} @CMAKE_THREAD_LIBS_INIT@ ++Conflicts: protobuf-lite