-
Notifications
You must be signed in to change notification settings - Fork 2
/
protobuf.cmake
81 lines (65 loc) · 3.16 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
include(FetchContent)
set(Protobuf_USE_STATIC_LIBS ON)
cmake_policy(SET CMP0026 OLD)
if(NOT DEFINED CMAKE_NUM_THREADS)
set(CMAKE_NUM_THREADS "8")
endif()
FetchContent_Declare(
protocolbuffers_protobuf
GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git
GIT_TAG v25.1
GIT_SHALLOW true
GIT_PROGRESS true
UPDATE_DISCONNECTED true
OVERRIDE_FIND_PACKAGE
)
FetchContent_MakeAvailable(protocolbuffers_protobuf)
set(Protobuf_ROOT ${protocolbuffers_protobuf_SOURCE_DIR})
message(STATUS "Setting up protobuf ...")
execute_process(
COMMAND
${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -D protobuf_BUILD_TESTS=OFF -D protobuf_BUILD_PROTOC_BINARIES=ON -D CMAKE_POSITION_INDEPENDENT_CODE=ON -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${Protobuf_ROOT})
if(result)
message(FATAL_ERROR "Failed to download protobuf (${result})!")
endif()
message(STATUS "Building protobuf ...")
execute_process(
COMMAND ${CMAKE_COMMAND} --build . --parallel ${CMAKE_NUM_THREADS}
RESULT_VARIABLE result
WORKING_DIRECTORY ${Protobuf_ROOT})
if(result)
message(FATAL_ERROR "Failed to build protobuf (${result})!")
endif()
message(STATUS "Installing protobuf ...")
execute_process(
COMMAND ${CMAKE_COMMAND} --install . --config ${CMAKE_BUILD_TYPE} --prefix ${Protobuf_ROOT}/install
RESULT_VARIABLE result
WORKING_DIRECTORY ${Protobuf_ROOT})
if(result)
message(FATAL_ERROR "Failed to build protobuf (${result})!")
endif()
if(NOT EXISTS ${Protobuf_ROOT}/install/lib64)
file(CREATE_LINK ${Protobuf_ROOT}/install/lib ${Protobuf_ROOT}/install/lib64 SYMBOLIC)
endif()
find_package(Protobuf CONFIG REQUIRED HINTS ${Protobuf_ROOT}/install/lib64/cmake)
set(Protobuf_PROTOC_EXECUTABLE ${Protobuf_ROOT}/install/bin/protoc)
include(${Protobuf_ROOT}/install/lib64/cmake/protobuf/protobuf-config.cmake)
include(${Protobuf_ROOT}/install/lib64/cmake/protobuf/protobuf-module.cmake)
include(${Protobuf_ROOT}/install/lib64/cmake/protobuf/protobuf-options.cmake)
include(${Protobuf_ROOT}/install/lib64/cmake/protobuf/protobuf-targets.cmake)
if(Protobuf_FOUND)
message(STATUS "Protobuf version : ${Protobuf_VERSION}")
message(STATUS "Protobuf include path : ${Protobuf_INCLUDE_DIRS}")
message(STATUS "Protobuf libraries : ${Protobuf_LIBRARIES}")
message(STATUS "Protobuf compiler libraries : ${Protobuf_PROTOC_LIBRARIES}")
message(STATUS "Protobuf lite libraries : ${Protobuf_LITE_LIBRARIES}")
message(STATUS "Protobuf protoc : ${Protobuf_PROTOC_EXECUTABLE}")
else()
message(
FATAL_ERROR
"Protobuf package not found -> specify search path via Protobuf_ROOT variable"
)
endif()
set(Protobuf_ABSL_LIBS absl::absl_check absl::absl_log absl::algorithm absl::base absl::bind_front absl::bits absl::btree absl::cleanup absl::cord absl::core_headers absl::debugging absl::die_if_null absl::dynamic_annotations absl::flags absl::flat_hash_map absl::flat_hash_set absl::function_ref absl::hash absl::layout absl::log_initialize absl::log_severity absl::memory absl::node_hash_map absl::node_hash_set absl::optional absl::span absl::status absl::statusor absl::strings absl::synchronization absl::time absl::type_traits absl::utility absl::variant utf8_range utf8_validity)