Home | History | Annotate | Download | only in external
      1 # Copyright 2016 Google Inc. All rights reserved.
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License");
      4 # you may not use this file except in compliance with the License.
      5 # You may obtain a copy of the License at
      6 #
      7 #     http://www.apache.org/licenses/LICENSE-2.0
      8 #
      9 # Unless required by applicable law or agreed to in writing, software
     10 # distributed under the License is distributed on an "AS IS" BASIS,
     11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
     14 
     15 include (FindProtobuf)
     16 
     17 set(PROTOBUF_TARGET external.protobuf)
     18 set(PROTOBUF_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/${PROTOBUF_TARGET})
     19 
     20 set(PROTOBUF_INCLUDE_DIRS ${PROTOBUF_INSTALL_DIR}/include)
     21 include_directories(${PROTOBUF_INCLUDE_DIRS})
     22 include_directories(${CMAKE_CURRENT_BINARY_DIR})
     23 
     24 IF(CMAKE_BUILD_TYPE MATCHES Debug)
     25   set(PROTOBUF_LIBRARIES protobufd)
     26 ELSE()
     27   set(PROTOBUF_LIBRARIES protobuf)
     28 ENDIF()
     29 
     30 foreach(lib ${PROTOBUF_LIBRARIES})
     31   list(APPEND PROTOBUF_BUILD_BYPRODUCTS ${PROTOBUF_INSTALL_DIR}/lib/lib${lib}.a)
     32 
     33   add_library(${lib} STATIC IMPORTED)
     34   set_property(TARGET ${lib} PROPERTY IMPORTED_LOCATION
     35                ${PROTOBUF_INSTALL_DIR}/lib/lib${lib}.a)
     36   add_dependencies(${lib} ${PROTOBUF_TARGET})
     37 endforeach(lib)
     38 
     39 set(PROTOBUF_PROTOC_EXECUTABLE ${PROTOBUF_INSTALL_DIR}/bin/protoc)
     40 list(APPEND PROTOBUF_BUILD_BYPRODUCTS ${PROTOBUF_PROTOC_EXECUTABLE})
     41 add_executable(protoc IMPORTED)
     42 set_property(TARGET protoc PROPERTY IMPORTED_LOCATION
     43              ${PROTOBUF_PROTOC_EXECUTABLE})
     44 add_dependencies(protoc ${PROTOBUF_TARGET})
     45 
     46 include (ExternalProject)
     47 ExternalProject_Add(${PROTOBUF_TARGET}
     48     PREFIX ${PROTOBUF_TARGET}
     49     GIT_REPOSITORY https://github.com/google/protobuf.git
     50     GIT_TAG 47b7d2c
     51     UPDATE_COMMAND ""
     52     CONFIGURE_COMMAND ${CMAKE_COMMAND} ${PROTOBUF_INSTALL_DIR}/src/${PROTOBUF_TARGET}/cmake
     53         -G${CMAKE_GENERATOR}
     54         -DCMAKE_INSTALL_PREFIX=${PROTOBUF_INSTALL_DIR}
     55         -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
     56         -DCMAKE_POSITION_INDEPENDENT_CODE=ON
     57         -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
     58         -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}
     59         -DCMAKE_C_FLAGS=${PROTOBUF_CFLAGS}
     60         -DCMAKE_CXX_FLAGS=${PROTOBUF_CXXFLAGS}
     61         -Dprotobuf_BUILD_TESTS=OFF
     62     BUILD_BYPRODUCTS ${PROTOBUF_BUILD_BYPRODUCTS}
     63 )
     64 
     65 # cmake 3.7 uses Protobuf_ when 3.5 PROTOBUF_ prefixes.
     66 set(Protobuf_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIRS})
     67 set(Protobuf_LIBRARIES ${PROTOBUF_LIBRARIES})
     68 set(Protobuf_PROTOC_EXECUTABLE ${PROTOBUF_PROTOC_EXECUTABLE})
     69