-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathprotobuf.cmake
63 lines (60 loc) · 2.57 KB
/
protobuf.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
include (FindProtobuf)
if(NOT COMMAND protobuf_generate_cpp)
include(ExternalProject)
set(PROTOBUF_TARGET external.protobuf)
set(PROTOBUF_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/${PROTOBUF_TARGET})
set(PROTOBUF_INCLUDE_DIRS ${PROTOBUF_INSTALL_DIR}/include)
include_directories(${PROTOBUF_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
IF(CMAKE_BUILD_TYPE MATCHES Debug)
set(PROTOBUF_LIBRARIES protobufd)
ELSE()
set(PROTOBUF_LIBRARIES protobuf)
ENDIF()
foreach(lib ${PROTOBUF_LIBRARIES})
if (MSVC)
set(LIB_PATH ${PROTOBUF_INSTALL_DIR}/lib/lib${lib}.lib)
else()
set(LIB_PATH ${PROTOBUF_INSTALL_DIR}/lib/lib${lib}.a)
endif()
list(APPEND PROTOBUF_BUILD_BYPRODUCTS ${LIB_PATH})
add_library(${lib} STATIC IMPORTED)
set_property(TARGET ${lib} PROPERTY IMPORTED_LOCATION
${LIB_PATH})
add_dependencies(${lib} ${PROTOBUF_TARGET})
endforeach(lib)
set(PROTOBUF_PROTOC_EXECUTABLE ${PROTOBUF_INSTALL_DIR}/bin/protoc)
list(APPEND PROTOBUF_BUILD_BYPRODUCTS ${PROTOBUF_PROTOC_EXECUTABLE})
if(${CMAKE_VERSION} VERSION_LESS "3.10.0")
set(PROTOBUF_PROTOC_TARGET protoc)
else()
set(PROTOBUF_PROTOC_TARGET protobuf::protoc)
endif()
if(NOT TARGET ${PROTOBUF_PROTOC_TARGET})
add_executable(${PROTOBUF_PROTOC_TARGET} IMPORTED)
endif()
set_property(TARGET ${PROTOBUF_PROTOC_TARGET} PROPERTY IMPORTED_LOCATION
${PROTOBUF_PROTOC_EXECUTABLE})
add_dependencies(${PROTOBUF_PROTOC_TARGET} ${PROTOBUF_TARGET})
ExternalProject_Add(${PROTOBUF_TARGET}
PREFIX ${PROTOBUF_TARGET}
GIT_REPOSITORY https://android.googlesource.com/platform/external/protobuf
GIT_TAG ca15ad7fb89a626c0d2a98240b11a2523727f9be
UPDATE_COMMAND ""
CONFIGURE_COMMAND ${CMAKE_COMMAND} ${PROTOBUF_INSTALL_DIR}/src/${PROTOBUF_TARGET}/cmake
-G${CMAKE_GENERATOR}
-DCMAKE_INSTALL_PREFIX=${PROTOBUF_INSTALL_DIR}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}
-DCMAKE_C_FLAGS=${PROTOBUF_CFLAGS}
-DCMAKE_CXX_FLAGS=${PROTOBUF_CXXFLAGS}
-Dprotobuf_BUILD_TESTS=OFF
BUILD_BYPRODUCTS ${PROTOBUF_BUILD_BYPRODUCTS}
)
# cmake 3.7 uses Protobuf_ when 3.5 PROTOBUF_ prefixes.
set(Protobuf_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIRS})
set(Protobuf_LIBRARIES ${PROTOBUF_LIBRARIES})
set(Protobuf_PROTOC_EXECUTABLE ${PROTOBUF_PROTOC_EXECUTABLE})
endif()