summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorBignaux Ronan <ronan@aimao.org>2018-10-20 08:15:27 +0200
committerPierre GRANDIN <pgrandin@users.noreply.github.com>2018-10-19 23:15:27 -0700
commitce949480009e8ac4df6e81173c4e312958913605 (patch)
treea9c6cee1e88b19d92cd228ea90e274356088d258 /cmake
parentd1eefc90619a6357e7a52f1145f961182674d813 (diff)
downloadnavit-ce949480009e8ac4df6e81173c4e312958913605.tar.gz
Refactoring:navit/maptool:build with external protobuf-c (#650)
Diffstat (limited to 'cmake')
-rw-r--r--cmake/FindProtobuf-c.cmake121
1 files changed, 121 insertions, 0 deletions
diff --git a/cmake/FindProtobuf-c.cmake b/cmake/FindProtobuf-c.cmake
new file mode 100644
index 000000000..170c1a03d
--- /dev/null
+++ b/cmake/FindProtobuf-c.cmake
@@ -0,0 +1,121 @@
+# Locate and configure the Google Protocol Buffers library.
+# Defines the following variables:
+#
+# PROTOBUF_C_FOUND - Found the Google Protocol Buffers library
+# PROTOBUF_C_INCLUDE_DIRS - Include directories for Google Protocol Buffers
+# PROTOBUF_C_LIBRARIES - The protobuf library
+#
+# The following cache variables are also defined:
+# PROTOBUF_C_LIBRARY - The protobuf library
+# PROTOBUF_C_PROTOC_LIBRARY - The protoc library
+# PROTOBUF_C_INCLUDE_DIR - The include directory for protocol buffers
+# PROTOBUF_C_PROTOC_EXECUTABLE - The protoc compiler
+#
+# ====================================================================
+# Example:
+#
+# find_package(Protobuf-c REQUIRED)
+# include_directories(${PROTOBUF_C_INCLUDE_DIRS})
+#
+# include_directories(${CMAKE_CURRENT_BINARY_DIR})
+# PROTOBUF_C_GENERATE_C(PROTO_SRCS PROTO_HDRS foo.proto)
+# add_executable(bar bar.c ${PROTO_SRCS} ${PROTO_HDRS})
+# target_link_libraries(bar ${PROTOBUF_C_LIBRARY})
+#
+# NOTE: You may need to link against pthreads, depending
+# on the platform.
+# ====================================================================
+#
+# PROTOBUF_C_GENERATE_C (public function)
+# SRCS = Variable to define with autogenerated
+# source files
+# HDRS = Variable to define with autogenerated
+# header files
+# ARGN = proto files
+#
+# ====================================================================
+
+
+#=============================================================================
+# Copyright 2009 Kitware, Inc.
+# Copyright 2009 Philip Lowman <philip@yhbt.com>
+# Copyright 2008 Esben Mose Hansen, Ange Optimization ApS
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distributed this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+function(PROTOBUF_C_GENERATE_C SRCS HDRS)
+ if(NOT ARGN)
+ message(SEND_ERROR "Error: PROTOBUF_C_GENERATE_C() called without any proto files")
+ return()
+ endif(NOT ARGN)
+
+ set(${SRCS})
+ set(${HDRS})
+ foreach(FIL ${ARGN})
+ get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
+ get_filename_component(FIL_WE ${FIL} NAME_WE)
+
+ list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb-c.c")
+ list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb-c.h")
+
+ add_custom_command(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb-c.c"
+ "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb-c.h"
+ COMMAND ${PROTOBUF_C_PROTOC_EXECUTABLE}
+ ARGS --c_out=${CMAKE_CURRENT_BINARY_DIR} --proto_path ${CMAKE_CURRENT_SOURCE_DIR} ${ABS_FIL}
+ DEPENDS ${ABS_FIL}
+ COMMENT "Running C protocol buffer compiler on ${FIL}"
+ VERBATIM )
+ endforeach()
+
+ set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
+ set(${SRCS} ${${SRCS}} PARENT_SCOPE)
+ set(${HDRS} ${${HDRS}} PARENT_SCOPE)
+endfunction()
+
+
+find_path(PROTOBUF_C_INCLUDE_DIR google/protobuf-c/protobuf-c.h)
+
+# Google's provided vcproj files generate libraries with a "lib"
+# prefix on Windows
+if(WIN32)
+ set(PROTOBUF_C_ORIG_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}")
+ set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "")
+endif()
+
+find_library(PROTOBUF_C_LIBRARY NAMES protobuf-c
+ DOC "The Google Protocol Buffers Library"
+)
+find_library(PROTOBUF_C_PROTOC_LIBRARY NAMES protoc-c
+ DOC "The Google Protocol Buffers Compiler Library"
+)
+find_program(PROTOBUF_C_PROTOC_EXECUTABLE NAMES protoc-c
+ DOC "The Google Protocol Buffers Compiler"
+)
+
+mark_as_advanced(PROTOBUF_C_INCLUDE_DIR
+ PROTOBUF_C_LIBRARY
+ PROTOBUF_C_PROTOC_LIBRARY
+ PROTOBUF_C_PROTOC_EXECUTABLE)
+
+# Restore original find library prefixes
+if(WIN32)
+ set(CMAKE_FIND_LIBRARY_PREFIXES "${PROTOBUF_C_ORIG_FIND_LIBRARY_PREFIXES}")
+endif()
+
+include(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(PROTOBUF_C DEFAULT_MSG
+ PROTOBUF_C_LIBRARY PROTOBUF_C_INCLUDE_DIR)
+
+if(PROTOBUF_C_FOUND)
+ set(PROTOBUF_C_INCLUDE_DIRS ${PROTOBUF_C_INCLUDE_DIR})
+ set(PROTOBUF_C_LIBRARIES ${PROTOBUF_C_LIBRARY})
+endif()