diff --git a/CMakeLists.txt b/CMakeLists.txt index 836c5ff..6ee66a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,90 +58,148 @@ elseif(UNIX) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--build-id") endif() -enable_testing() +if (ENABLE_TEST) + enable_testing() +endif() +set(UPB_HDRS + ${CMAKE_CURRENT_LIST_DIR}/upb/generated_util.h + ${CMAKE_CURRENT_LIST_DIR}/upb/msg.h + ${CMAKE_CURRENT_LIST_DIR}/upb/table.int.h + ${CMAKE_CURRENT_LIST_DIR}/upb/port_def.inc + ${CMAKE_CURRENT_LIST_DIR}/upb/port_undef.inc + ${CMAKE_CURRENT_LIST_DIR}/upb/decode.h + ${CMAKE_CURRENT_LIST_DIR}/upb/encode.h + ${CMAKE_CURRENT_LIST_DIR}/upb/upb.h +) + +set(UBP_PROJECTS upb) add_library(upb upb/decode.c upb/encode.c - upb/generated_util.h upb/msg.c - upb/msg.h upb/port.c - upb/port_def.inc - upb/port_undef.inc upb/table.c - upb/table.int.h upb/upb.c - upb/decode.h - upb/encode.h - upb/upb.h) + upb/upb.h + ${UPB_HDRS}) + + +set(UBP_PROJECTS ${UBP_PROJECTS} generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me) add_library(generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me INTERFACE) target_link_libraries(generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me INTERFACE upb) + +set(REFLECTION_HDRS + ${CMAKE_CURRENT_LIST_DIR}/upb/def.h + ${CMAKE_CURRENT_LIST_DIR}/upb/msgfactory.h +) + +set(UBP_PROJECTS ${UBP_PROJECTS} reflection) add_library(reflection upb/def.c upb/msgfactory.c - upb/def.h - upb/msgfactory.h) + ${REFLECTION_HDRS}) target_link_libraries(reflection descriptor_upbproto table upb) + +set(UBP_PROJECTS ${UBP_PROJECTS} table) add_library(table INTERFACE) target_link_libraries(table INTERFACE upb) + +set(LEGACY_MSG_HDRS ${CMAKE_CURRENT_LIST_DIR}/upb/legacy_msg_reflection.h) + +set(UBP_PROJECTS ${UBP_PROJECTS} legacy_msg_reflection) add_library(legacy_msg_reflection upb/legacy_msg_reflection.c - upb/legacy_msg_reflection.h) + ${LEGACY_MSG_HDRS}) target_link_libraries(legacy_msg_reflection table upb) + +set(HANDLERS_HDRS + ${CMAKE_CURRENT_LIST_DIR}/upb/handlers-inl.h + ${CMAKE_CURRENT_LIST_DIR}/upb/handlers.h + ${CMAKE_CURRENT_LIST_DIR}/upb/sink.h +) + +set(UBP_PROJECTS ${UBP_PROJECTS} handlers) add_library(handlers upb/handlers.c - upb/handlers-inl.h upb/sink.c - upb/handlers.h - upb/sink.h) + ${HANDLERS_HDRS}) target_link_libraries(handlers reflection table upb) + +set(UPB_PB_HDRS + ${CMAKE_CURRENT_LIST_DIR}/upb/pb/decoder.int.h + ${CMAKE_CURRENT_LIST_DIR}/upb/pb/varint.int.h + ${CMAKE_CURRENT_LIST_DIR}/upb/pb/decoder.h + ${CMAKE_CURRENT_LIST_DIR}/upb/pb/encoder.h + ${CMAKE_CURRENT_LIST_DIR}/upb/pb/textprinter.h +) + +set(UBP_PROJECTS ${UBP_PROJECTS} upb_pb) add_library(upb_pb upb/pb/compile_decoder.c upb/pb/decoder.c - upb/pb/decoder.int.h upb/pb/encoder.c upb/pb/textprinter.c upb/pb/varint.c - upb/pb/varint.int.h - upb/pb/decoder.h - upb/pb/encoder.h - upb/pb/textprinter.h) + ${UPB_PB_HDRS}) target_link_libraries(upb_pb descriptor_upbproto handlers reflection table upb) + +set(UPB_JSON_HDRS + ${CMAKE_CURRENT_LIST_DIR}/upb/json/parser.h + ${CMAKE_CURRENT_LIST_DIR}/upb/json/printer.h +) + +set(UBP_PROJECTS ${UBP_PROJECTS} upb_json) add_library(upb_json generated_for_cmake/upb/json/parser.c upb/json/printer.c - upb/json/parser.h - upb/json/printer.h) + ${UPB_JSON_HDRS}) target_link_libraries(upb_json upb upb_pb) + +set(UBP_PROJECTS ${UBP_PROJECTS} upb_cc_bindings) add_library(upb_cc_bindings INTERFACE) target_link_libraries(upb_cc_bindings INTERFACE descriptor_upbproto handlers upb) -add_library(upb_test - tests/testmain.cc - tests/test_util.h - tests/upb_test.h) -target_link_libraries(upb_test - handlers - upb) - +if (ENABLE_TEST) + set(UBP_PROJECTS ${UBP_PROJECTS} upb_test) + add_library(upb_test + tests/testmain.cc + tests/test_util.h + tests/upb_test.h) + target_link_libraries(upb_test + handlers + upb) +endif() + +install(FILES ${UPB_HDRS} ${REFLECTION_HDRS} ${LEGACY_MSG_HDRS} ${HANDLERS_HDRS} DESTINATION include/upb) +install(FILES ${UPB_PB_HDRS} DESTINATION include/upb/pb) +install(FILES ${UPB_JSON_HDRS} DESTINATION include/upb/json) + +foreach(PROJ ${UBP_PROJECTS}) + install( + TARGETS ${PROJ} + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + ) +endforeach() \ No newline at end of file