1ffe3c632Sopenharmony_ci# Minimum CMake required 2ffe3c632Sopenharmony_cicmake_minimum_required(VERSION 2.8.12) 3ffe3c632Sopenharmony_ci 4ffe3c632Sopenharmony_ci# Project 5ffe3c632Sopenharmony_ciproject(protobuf-examples) 6ffe3c632Sopenharmony_ci 7ffe3c632Sopenharmony_ci# Find required protobuf package 8ffe3c632Sopenharmony_cifind_package(protobuf CONFIG REQUIRED) 9ffe3c632Sopenharmony_ci 10ffe3c632Sopenharmony_ciif(protobuf_VERBOSE) 11ffe3c632Sopenharmony_ci message(STATUS "Using Protocol Buffers ${Protobuf_VERSION}") 12ffe3c632Sopenharmony_ciendif() 13ffe3c632Sopenharmony_ci 14ffe3c632Sopenharmony_ciset(CMAKE_INCLUDE_CURRENT_DIR TRUE) 15ffe3c632Sopenharmony_ci 16ffe3c632Sopenharmony_ci# http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F 17ffe3c632Sopenharmony_ciif(MSVC AND protobuf_MSVC_STATIC_RUNTIME) 18ffe3c632Sopenharmony_ci foreach(flag_var 19ffe3c632Sopenharmony_ci CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE 20ffe3c632Sopenharmony_ci CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) 21ffe3c632Sopenharmony_ci if(${flag_var} MATCHES "/MD") 22ffe3c632Sopenharmony_ci string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") 23ffe3c632Sopenharmony_ci endif(${flag_var} MATCHES "/MD") 24ffe3c632Sopenharmony_ci endforeach() 25ffe3c632Sopenharmony_ciendif() 26ffe3c632Sopenharmony_ci 27ffe3c632Sopenharmony_ciforeach(example add_person list_people) 28ffe3c632Sopenharmony_ci set(${example}_SRCS ${example}.cc) 29ffe3c632Sopenharmony_ci set(${example}_PROTOS addressbook.proto) 30ffe3c632Sopenharmony_ci 31ffe3c632Sopenharmony_ci #Code Generation 32ffe3c632Sopenharmony_ci if(protobuf_MODULE_COMPATIBLE) #Legacy Support 33ffe3c632Sopenharmony_ci protobuf_generate_cpp(${example}_PROTO_SRCS ${example}_PROTO_HDRS ${${example}_PROTOS}) 34ffe3c632Sopenharmony_ci list(APPEND ${example}_SRCS ${${example}_PROTO_SRCS} ${${example}_PROTO_HDRS}) 35ffe3c632Sopenharmony_ci endif() 36ffe3c632Sopenharmony_ci 37ffe3c632Sopenharmony_ci #Executable setup 38ffe3c632Sopenharmony_ci set(executable_name ${example}_cpp) 39ffe3c632Sopenharmony_ci add_executable(${executable_name} ${${example}_SRCS} ${${example}_PROTOS}) 40ffe3c632Sopenharmony_ci if(protobuf_MODULE_COMPATIBLE) #Legacy mode 41ffe3c632Sopenharmony_ci target_include_directories(${executable_name} PUBLIC ${PROTOBUF_INCLUDE_DIRS}) 42ffe3c632Sopenharmony_ci target_link_libraries(${executable_name} ${PROTOBUF_LIBRARIES}) 43ffe3c632Sopenharmony_ci else() 44ffe3c632Sopenharmony_ci target_link_libraries(${executable_name} protobuf::libprotobuf) 45ffe3c632Sopenharmony_ci protobuf_generate(TARGET ${executable_name}) 46ffe3c632Sopenharmony_ci endif() 47ffe3c632Sopenharmony_ci 48ffe3c632Sopenharmony_ciendforeach() 49