xref: /aosp_15_r20/external/cronet/third_party/protobuf/cmake/examples.cmake (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1*6777b538SAndroid Build Coastguard Workerif(protobuf_VERBOSE)
2*6777b538SAndroid Build Coastguard Worker  message(STATUS "Protocol Buffers Examples Configuring...")
3*6777b538SAndroid Build Coastguard Workerendif()
4*6777b538SAndroid Build Coastguard Worker
5*6777b538SAndroid Build Coastguard Workerget_filename_component(examples_dir "${protobuf_SOURCE_DIR}/examples" ABSOLUTE)
6*6777b538SAndroid Build Coastguard Worker
7*6777b538SAndroid Build Coastguard Workerif(protobuf_VERBOSE)
8*6777b538SAndroid Build Coastguard Worker  message(STATUS "Protocol Buffers Examples Configuring done")
9*6777b538SAndroid Build Coastguard Workerendif()
10*6777b538SAndroid Build Coastguard Workerinclude(ExternalProject)
11*6777b538SAndroid Build Coastguard Worker
12*6777b538SAndroid Build Coastguard Worker# Internal utility function: Create a custom target representing a build of examples with custom options.
13*6777b538SAndroid Build Coastguard Workerfunction(add_examples_build NAME)
14*6777b538SAndroid Build Coastguard Worker
15*6777b538SAndroid Build Coastguard Worker  ExternalProject_Add(${NAME}
16*6777b538SAndroid Build Coastguard Worker    PREFIX ${NAME}
17*6777b538SAndroid Build Coastguard Worker    SOURCE_DIR "${examples_dir}"
18*6777b538SAndroid Build Coastguard Worker    BINARY_DIR ${NAME}
19*6777b538SAndroid Build Coastguard Worker    STAMP_DIR ${NAME}/logs
20*6777b538SAndroid Build Coastguard Worker    INSTALL_COMMAND "" #Skip
21*6777b538SAndroid Build Coastguard Worker    LOG_CONFIGURE 1
22*6777b538SAndroid Build Coastguard Worker    CMAKE_CACHE_ARGS "-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}"
23*6777b538SAndroid Build Coastguard Worker                     "-Dprotobuf_VERBOSE:BOOL=${protobuf_VERBOSE}"
24*6777b538SAndroid Build Coastguard Worker                     ${ARGN}
25*6777b538SAndroid Build Coastguard Worker  )
26*6777b538SAndroid Build Coastguard Worker  set_property(TARGET ${NAME} PROPERTY FOLDER "Examples")
27*6777b538SAndroid Build Coastguard Worker  set_property(TARGET ${NAME} PROPERTY EXCLUDE_FROM_ALL TRUE)
28*6777b538SAndroid Build Coastguard Workerendfunction()
29*6777b538SAndroid Build Coastguard Worker
30*6777b538SAndroid Build Coastguard Worker# Add examples as an external project.
31*6777b538SAndroid Build Coastguard Worker# sub_directory cannot be used because the find_package(protobuf) call would cause failures with redefined targets.
32*6777b538SAndroid Build Coastguard Workeradd_examples_build(examples "-Dprotobuf_DIR:PATH=${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}")
33*6777b538SAndroid Build Coastguard Workeradd_dependencies(examples libprotobuf protoc)
34*6777b538SAndroid Build Coastguard Worker
35*6777b538SAndroid Build Coastguard Workeroption(protobuf_BUILD_EXAMPLES_MULTITEST "Build Examples in multiple configurations. Useful for testing." OFF)
36*6777b538SAndroid Build Coastguard Workermark_as_advanced(protobuf_BUILD_EXAMPLES_MULTITEST)
37*6777b538SAndroid Build Coastguard Workerif(protobuf_BUILD_EXAMPLES_MULTITEST)
38*6777b538SAndroid Build Coastguard Worker  set_property(GLOBAL PROPERTY USE_FOLDERS ON)
39*6777b538SAndroid Build Coastguard Worker
40*6777b538SAndroid Build Coastguard Worker  #Build using the legacy compatibility module.
41*6777b538SAndroid Build Coastguard Worker  add_examples_build(examples-legacy
42*6777b538SAndroid Build Coastguard Worker    "-Dprotobuf_DIR:PATH=${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}"
43*6777b538SAndroid Build Coastguard Worker    "-Dprotobuf_MODULE_COMPATIBLE:BOOL=TRUE"
44*6777b538SAndroid Build Coastguard Worker  )
45*6777b538SAndroid Build Coastguard Worker  add_dependencies(examples-legacy libprotobuf protoc)
46*6777b538SAndroid Build Coastguard Worker
47*6777b538SAndroid Build Coastguard Worker  #Build using the installed library.
48*6777b538SAndroid Build Coastguard Worker  add_examples_build(examples-installed
49*6777b538SAndroid Build Coastguard Worker    "-Dprotobuf_DIR:PATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_CMAKEDIR}"
50*6777b538SAndroid Build Coastguard Worker  )
51*6777b538SAndroid Build Coastguard Worker
52*6777b538SAndroid Build Coastguard Worker  #Build using the installed library in legacy compatibility mode.
53*6777b538SAndroid Build Coastguard Worker  add_examples_build(examples-installed-legacy
54*6777b538SAndroid Build Coastguard Worker    "-Dprotobuf_DIR:PATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_CMAKEDIR}"
55*6777b538SAndroid Build Coastguard Worker    "-Dprotobuf_MODULE_COMPATIBLE:BOOL=TRUE"
56*6777b538SAndroid Build Coastguard Worker  )
57*6777b538SAndroid Build Coastguard Workerendif()
58