-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
114 lines (91 loc) · 4.97 KB
/
CMakeLists.txt
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
cmake_minimum_required(VERSION 3.12)
project(protobuf)
include_guard(GLOBAL)
find_package(Python COMPONENTS Interpreter)
# Use waf to resolve dependencies
if (NOT DEFINED STEINWURF_RESOLVE)
message(STATUS "Resolving dependencies...")
execute_process(
COMMAND ${Python_EXECUTABLE} waf resolve ${STEINWURF_RESOLVE_OPTIONS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE STATUS)
if (STATUS AND NOT STATUS EQUAL 0)
message(FATAL_ERROR "Failed: ${STATUS}")
endif ()
set(STEINWURF_RESOLVE "${CMAKE_CURRENT_SOURCE_DIR}/resolve_symlinks")
set(STEINWURF_TOP_NAME ${PROJECT_NAME})
endif ()
# Abseil
file(GLOB_RECURSE sw_protobuf_abseil_sources ${STEINWURF_RESOLVE}/protobuf-source/third_party/abseil-cpp/absl/**/*.cc)
list(FILTER sw_protobuf_abseil_sources EXCLUDE REGEX .*absl\/.*\/.*_benchmark.*)
list(FILTER sw_protobuf_abseil_sources EXCLUDE REGEX .*absl\/.*\/.*benchmark.*)
list(FILTER sw_protobuf_abseil_sources EXCLUDE REGEX .*absl\/.*\/.*test_.*)
list(FILTER sw_protobuf_abseil_sources EXCLUDE REGEX .*absl\/.*\/.*_test.*)
list(FILTER sw_protobuf_abseil_sources EXCLUDE REGEX .*absl\/.*\/.*mock_.*)
list(FILTER sw_protobuf_abseil_sources EXCLUDE REGEX .*absl\/.*\/.*_mock_.*)
add_library(sw_protobuf_abseil STATIC ${sw_protobuf_abseil_sources})
target_compile_features(sw_protobuf_abseil PUBLIC cxx_std_17)
target_include_directories(sw_protobuf_abseil PUBLIC ${STEINWURF_RESOLVE}/protobuf-source/third_party/abseil-cpp)
# Abseil has to be compiled with -D_LARGEFILE64_SOURCE
target_compile_options(sw_protobuf_abseil PUBLIC -D_LARGEFILE64_SOURCE)
if(ANDROID)
target_link_libraries(sw_protobuf_abseil log)
endif()
if (APPLE)
target_link_libraries(sw_protobuf_abseil "-framework CoreFoundation")
endif ()
# utf8_range
file(GLOB_RECURSE sw_protobuf_utf8_range_sources
${STEINWURF_RESOLVE}/protobuf-source/third_party/utf8_range/*.cc
${STEINWURF_RESOLVE}/protobuf-source/third_party/utf8_range/**/*.cc)
list(FILTER sw_protobuf_utf8_range_sources EXCLUDE REGEX .*test\.cc)
list(FILTER sw_protobuf_utf8_range_sources EXCLUDE REGEX .*fuzz.*\.cc) # Prevents missing cstdint include
add_library(sw_protobuf_utf8_range STATIC ${sw_protobuf_utf8_range_sources})
target_compile_features(sw_protobuf_utf8_range PUBLIC cxx_std_17)
target_link_libraries(sw_protobuf_utf8_range PRIVATE sw_protobuf_abseil)
target_include_directories(sw_protobuf_utf8_range PUBLIC ${STEINWURF_RESOLVE}/protobuf-source/third_party/utf8_range)
if (DEFINED MSVC)
target_compile_options(sw_protobuf_abseil PRIVATE "/DNOMINMAX")
endif ()
file(GLOB_RECURSE sw_protobuf_sources ${STEINWURF_RESOLVE}/protobuf-source/src/google/**/*.cc)
list(FILTER sw_protobuf_sources EXCLUDE REGEX .*src/google/protobuf\/compiler\/.*)
list(FILTER sw_protobuf_sources EXCLUDE REGEX .*src/google/protobuf\/.*test.*)
add_library(sw_protobuf STATIC ${sw_protobuf_sources})
target_compile_features(sw_protobuf PUBLIC cxx_std_17)
target_link_libraries(sw_protobuf PUBLIC sw_protobuf_abseil sw_protobuf_utf8_range)
target_include_directories(sw_protobuf PUBLIC ${STEINWURF_RESOLVE}/protobuf-source/src)
message(STATUS "STEINWURF_PROTOC: ${STEINWURF_PROTOC}")
if (STEINWURF_PROTOC)
file(GLOB_RECURSE sw_protobuf_protoc_sources ${STEINWURF_RESOLVE}/protobuf-source/src/google/protobuf/compiler/*.cc)
list(FILTER sw_protobuf_protoc_sources EXCLUDE REGEX .*src/google/protobuf\/compiler\/.*test.*)
list(FILTER sw_protobuf_protoc_sources EXCLUDE REGEX .*src/google/protobuf\/compiler\/.*mock.*)
list(FILTER sw_protobuf_protoc_sources EXCLUDE REGEX .*src/google/protobuf\/compiler\/.*fake.*)
list(FILTER sw_protobuf_protoc_sources EXCLUDE REGEX .*src/google/protobuf\/compiler\/allowlists\/.*_test.*)
add_executable(protoc ${sw_protobuf_protoc_sources})
target_link_libraries(protoc PRIVATE sw_protobuf)
target_include_directories(protoc PRIVATE ${STEINWURF_RESOLVE}/protobuf-source/src)
target_compile_features(protoc PRIVATE cxx_std_17)
endif ()
# Ignore -Wattribute warnings for GCC and Clang
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
target_compile_options(sw_protobuf PRIVATE -Wno-attributes)
endif ()
add_library(steinwurf::protobuf ALIAS sw_protobuf)
# Is top level project?
if (${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
enable_testing()
if (CMAKE_C_COMPILER_ID MATCHES "MSVC")
# For Windows: Prevent overriding the parent project's compiler/linker
# settings
set(gtest_force_shared_crt
ON
CACHE BOOL "" FORCE)
endif ()
# Google Test dependency
add_subdirectory("${STEINWURF_RESOLVE}/gtest-source")
file(GLOB_RECURSE sw_protobuf_test_sources ./test/cpp/*.cc ./test/cpp/*.cpp)
add_executable(sw_protobuf_test ${sw_protobuf_test_sources})
target_include_directories(sw_protobuf_test PRIVATE ${STEINWURF_RESOLVE}/test/cpp)
target_link_libraries(sw_protobuf_test PUBLIC gtest_main sw_protobuf)
add_test(sw_protobuf_test sw_protobuf_test)
endif ()