| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 | # Minimum CMake requiredcmake_minimum_required(VERSION 2.8.12)# Projectproject(protobuf-examples)# Find required protobuf packagefind_package(protobuf CONFIG REQUIRED)if(protobuf_VERBOSE)  message(STATUS "Using Protocol Buffers ${Protobuf_VERSION}")endif()set(CMAKE_INCLUDE_CURRENT_DIR TRUE)# http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3Fif(MSVC AND protobuf_MSVC_STATIC_RUNTIME)  foreach(flag_var      CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE      CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)    if(${flag_var} MATCHES "/MD")      string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")    endif(${flag_var} MATCHES "/MD")  endforeach()endif()foreach(example add_person list_people)  set(${example}_SRCS ${example}.cc)  set(${example}_PROTOS addressbook.proto)  #Code Generation  if(protobuf_MODULE_COMPATIBLE) #Legacy Support    protobuf_generate_cpp(${example}_PROTO_SRCS ${example}_PROTO_HDRS ${${example}_PROTOS})    list(APPEND ${example}_SRCS ${${example}_PROTO_SRCS} ${${example}_PROTO_HDRS})  endif()  #Executable setup  set(executable_name ${example}_cpp)  add_executable(${executable_name} ${${example}_SRCS} ${${example}_PROTOS})  if(protobuf_MODULE_COMPATIBLE) #Legacy mode    target_include_directories(${executable_name} PUBLIC ${PROTOBUF_INCLUDE_DIRS})    target_link_libraries(${executable_name} ${PROTOBUF_LIBRARIES})  else()    target_link_libraries(${executable_name} protobuf::libprotobuf)    protobuf_generate(TARGET ${executable_name})  endif()endforeach()
 |