diff options
author | Joshua Haberman <jhaberman@gmail.com> | 2018-08-27 20:07:33 -0700 |
---|---|---|
committer | Joshua Haberman <jhaberman@gmail.com> | 2018-08-27 20:07:33 -0700 |
commit | b7cad62b5f4a7f5fd2b4337bbdeae54132d9a8ae (patch) | |
tree | 49be0ca24a18ffd4062c3b276e49399e963d237a | |
parent | 62318cadcefec2d2bfd0d84fdd628be313ff6201 (diff) |
Got CMake build working on macOS, and updated CMake build.
-rw-r--r-- | CMakeLists.txt | 62 | ||||
-rw-r--r-- | tests/conformance_upb.c | 29 | ||||
m--------- | third_party/protobuf | 0 |
3 files changed, 59 insertions, 32 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index ef68296..b192d75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,10 +16,10 @@ if(NOT CMAKE_BUILD_TYPE) endif() # Check out Git submodules. -if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.gitmodules") - execute_process (COMMAND git submodule update --init --recursive - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) -endif() +#if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.gitmodules") +# execute_process (COMMAND git submodule update --init --recursive +# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) +#endif() set(protobuf_BUILD_TESTS OFF CACHE BOOL "enable tests for proto2" FORCE) set(protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "enable shared libs for proto2" FORCE) @@ -45,8 +45,10 @@ endif() include_directories(.) include_directories(${CMAKE_CURRENT_BINARY_DIR}) +set(CMAKE_CXX_FLAGS "-std=c++11 -W -Wall -Wno-sign-compare") if(APPLE) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup -flat_namespace") elseif(UNIX) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--build-id") endif() @@ -78,12 +80,14 @@ if(LUA_FOUND) set_target_properties(upb_c PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "lua" - PREFIX "") + LIBRARY_OUTPUT_DIRECTORY "upb/bindings/lua" + PREFIX "" + SUFFIX ".so") set_target_properties(table_c pb_c PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "lua/upb" - PREFIX "") + LIBRARY_OUTPUT_DIRECTORY "upb/bindings/lua/upb" + PREFIX "" + SUFFIX ".so") add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/tools/upbc @@ -111,7 +115,7 @@ if(LUA_FOUND) DEPENDS ${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb.lua COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb.lua - ${CMAKE_CURRENT_BINARY_DIR}/lua) + ${CMAKE_CURRENT_BINARY_DIR}/upb/bindings/lua) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lua/upb/pb.lua DEPENDS ${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb/table.lua @@ -119,7 +123,7 @@ if(LUA_FOUND) COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb/table.lua ${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb/pb.lua - ${CMAKE_CURRENT_BINARY_DIR}/lua/upb) + ${CMAKE_CURRENT_BINARY_DIR}/upb/bindings/lua/upb) add_custom_target( upbc ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/tools/upbc @@ -129,6 +133,14 @@ if(LUA_FOUND) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/conformance.upb.h + ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/test_messages_proto3.upb.h + ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/test_messages_proto3.upb.c + ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/any.upb.c + ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/duration.upb.c + ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/field_mask.upb.c + ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/struct.upb.c + ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/timestamp.upb.c + ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/wrappers.upb.c ${CMAKE_CURRENT_BINARY_DIR}/conformance.upb.c DEPENDS upbc ${CMAKE_CURRENT_SOURCE_DIR}/third_party/protobuf/conformance/conformance.proto COMMAND protoc --include_imports @@ -156,6 +168,21 @@ if(LUA_FOUND) DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/conformance.upb.h ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/descriptor.upb.h ) + + add_executable(conformance_upb + tests/conformance_upb.c + ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/test_messages_proto3.upb.c + ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/any.upb.c + ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/duration.upb.c + ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/field_mask.upb.c + ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/struct.upb.c + ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/timestamp.upb.c + ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/wrappers.upb.c + ${CMAKE_CURRENT_BINARY_DIR}/conformance.upb.c + ) + target_link_libraries(conformance_upb LINK_PRIVATE + upb +) endif() set(UPB_SRCS @@ -211,18 +238,3 @@ set_property(TARGET upbhandlers_pic PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET upbpb_pic PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET upbjson_pic PROPERTY POSITION_INDEPENDENT_CODE ON) -add_executable(conformance_upb - tests/conformance_upb.c - ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/test_messages_proto3.upb.c - ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/any.upb.c - ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/duration.upb.c - ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/field_mask.upb.c - ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/struct.upb.c - ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/test_messages_proto3.upb.c - ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/timestamp.upb.c - ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/wrappers.upb.c - ${CMAKE_CURRENT_BINARY_DIR}/conformance.upb.c - ) -target_link_libraries(conformance_upb LINK_PRIVATE - upb -) diff --git a/tests/conformance_upb.c b/tests/conformance_upb.c index 70ea300..5c0ce88 100644 --- a/tests/conformance_upb.c +++ b/tests/conformance_upb.c @@ -39,17 +39,30 @@ void CheckedWrite(int fd, const void *buf, size_t len) { } } +static const char *proto3_msg = + "protobuf_test_messages.proto3.TestAllTypesProto3"; + void DoTest( const conformance_ConformanceRequest* request, conformance_ConformanceResponse *response, upb_env *env) { - conformance_ConformanceResponse_new(env); - protobuf_test_messages_proto3_TestAllTypes *test_message; + upb_stringview message_type = + conformance_ConformanceRequest_message_type(request); + if (strcmp(message_type.data, proto3_msg) != 0) { + static const char msg[] = "Only proto3 for now."; + conformance_ConformanceResponse_set_skipped( + response, upb_stringview_make(msg, sizeof(msg))); + return; + } + + protobuf_test_messages_proto3_TestAllTypesProto3 *test_message; switch (conformance_ConformanceRequest_payload_case(request)) { - case conformance_ConformanceRequest_payload_protobuf_payload: - test_message = protobuf_test_messages_proto3_TestAllTypes_parsenew( - conformance_ConformanceRequest_protobuf_payload(request), env); + case conformance_ConformanceRequest_payload_protobuf_payload: { + upb_stringview payload = + conformance_ConformanceRequest_protobuf_payload(request); + test_message = protobuf_test_messages_proto3_TestAllTypesProto3_parsenew( + payload, env); if (!test_message) { /* TODO(haberman): return details. */ @@ -59,6 +72,7 @@ void DoTest( return; } break; + } case conformance_ConformanceRequest_payload_json_payload: { static const char msg[] = "JSON support not yet implemented."; @@ -79,8 +93,9 @@ void DoTest( case conformance_PROTOBUF: { size_t serialized_len; - char *serialized = protobuf_test_messages_proto3_TestAllTypes_serialize( - test_message, env, &serialized_len); + char *serialized = + protobuf_test_messages_proto3_TestAllTypesProto3_serialize( + test_message, env, &serialized_len); if (!serialized) { static const char msg[] = "Error serializing."; conformance_ConformanceResponse_set_serialize_error( diff --git a/third_party/protobuf b/third_party/protobuf -Subproject 6bd51a59df41b99058ec8c2b03a177a218267ce +Subproject 45d03a977193d1dcce5251e4bffe17bf0ba738e |