capnproto

FORK: Cap'n Proto serialization/RPC system - core tools and C++ library
git clone https://git.neptards.moe/neptards/capnproto.git
Log | Files | Refs | README | LICENSE

CMakeLists.txt (10600B)


      1 
      2 # capnp ========================================================================
      3 
      4 set(capnp_sources_lite
      5   c++.capnp.c++
      6   blob.c++
      7   arena.c++
      8   layout.c++
      9   list.c++
     10   any.c++
     11   message.c++
     12   schema.capnp.c++
     13   stream.capnp.c++
     14   serialize.c++
     15   serialize-packed.c++
     16 )
     17 set(capnp_sources_heavy
     18   schema.c++
     19   schema-loader.c++
     20   dynamic.c++
     21   stringify.c++
     22 )
     23 if(NOT CAPNP_LITE)
     24   set(capnp_sources ${capnp_sources_lite} ${capnp_sources_heavy})
     25 else()
     26   set(capnp_sources ${capnp_sources_lite})
     27 endif()
     28 
     29 set(capnp_headers
     30   c++.capnp.h
     31   common.h
     32   blob.h
     33   endian.h
     34   layout.h
     35   orphan.h
     36   list.h
     37   any.h
     38   message.h
     39   capability.h
     40   membrane.h
     41   dynamic.h
     42   schema.h
     43   schema.capnp.h
     44   stream.capnp.h
     45   schema-lite.h
     46   schema-loader.h
     47   schema-parser.h
     48   pretty-print.h
     49   serialize.h
     50   serialize-async.h
     51   serialize-packed.h
     52   serialize-text.h
     53   pointer-helpers.h
     54   generated-header-support.h
     55   raw-schema.h
     56 )
     57 set(capnp_compat_headers
     58   compat/std-iterator.h
     59 )
     60 set(capnp_schemas
     61   c++.capnp
     62   schema.capnp
     63   stream.capnp
     64 )
     65 add_library(capnp ${capnp_sources})
     66 add_library(CapnProto::capnp ALIAS capnp)
     67 target_link_libraries(capnp PUBLIC kj)
     68 #make sure external consumers don't need to manually set the include dirs
     69 get_filename_component(PARENT_DIR ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY)
     70 target_include_directories(capnp INTERFACE
     71   $<BUILD_INTERFACE:${PARENT_DIR}>
     72   $<INSTALL_INTERFACE:include>
     73 )
     74 # Ensure the library has a version set to match autotools build
     75 set_target_properties(capnp PROPERTIES VERSION ${VERSION})
     76 install(TARGETS capnp ${INSTALL_TARGETS_DEFAULT_ARGS})
     77 install(FILES ${capnp_headers} ${capnp_schemas} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/capnp")
     78 install(FILES ${capnp_compat_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/capnp/compat")
     79 
     80 set(capnp-rpc_sources
     81   serialize-async.c++
     82   capability.c++
     83   membrane.c++
     84   dynamic-capability.c++
     85   rpc.c++
     86   rpc.capnp.c++
     87   rpc-twoparty.c++
     88   rpc-twoparty.capnp.c++
     89   persistent.capnp.c++
     90   ez-rpc.c++
     91 )
     92 set(capnp-rpc_headers
     93   rpc-prelude.h
     94   rpc.h
     95   rpc-twoparty.h
     96   rpc.capnp.h
     97   rpc-twoparty.capnp.h
     98   persistent.capnp.h
     99   ez-rpc.h
    100 )
    101 set(capnp-rpc_schemas
    102   rpc.capnp
    103   rpc-twoparty.capnp
    104   persistent.capnp
    105 )
    106 if(NOT CAPNP_LITE)
    107   add_library(capnp-rpc ${capnp-rpc_sources})
    108   add_library(CapnProto::capnp-rpc ALIAS capnp-rpc)
    109   target_link_libraries(capnp-rpc PUBLIC capnp kj-async kj)
    110   # Ensure the library has a version set to match autotools build
    111   set_target_properties(capnp-rpc PROPERTIES VERSION ${VERSION})
    112   install(TARGETS capnp-rpc ${INSTALL_TARGETS_DEFAULT_ARGS})
    113   install(FILES ${capnp-rpc_headers} ${capnp-rpc_schemas} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/capnp")
    114 endif()
    115 
    116 # capnp-json ========================================================================
    117 
    118 set(capnp-json_sources
    119   compat/json.c++
    120   compat/json.capnp.c++
    121 )
    122 set(capnp-json_headers
    123   compat/json.h
    124   compat/json.capnp.h
    125 )
    126 set(capnp-json_schemas
    127   compat/json.capnp
    128 )
    129 if(NOT CAPNP_LITE)
    130   add_library(capnp-json ${capnp-json_sources})
    131   add_library(CapnProto::capnp-json ALIAS capnp-json)
    132   target_link_libraries(capnp-json PUBLIC capnp kj-async kj)
    133   # Ensure the library has a version set to match autotools build
    134   set_target_properties(capnp-json PROPERTIES VERSION ${VERSION})
    135   install(TARGETS capnp-json ${INSTALL_TARGETS_DEFAULT_ARGS})
    136   install(FILES ${capnp-json_headers} ${capnp-json_schemas} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/capnp/compat")
    137 endif()
    138 
    139 # capnp-websocket ========================================================================
    140 
    141 set(capnp-websocket_sources
    142   compat/websocket-rpc.c++
    143 )
    144 set(capnp-websocket_headers
    145   compat/websocket-rpc.h
    146 )
    147 if(NOT CAPNP_LITE)
    148   add_library(capnp-websocket ${capnp-websocket_sources})
    149   add_library(CapnProto::capnp-websocket ALIAS capnp-websocket)
    150   target_link_libraries(capnp-websocket PUBLIC capnp capnp-rpc kj-http kj-async kj)
    151   # Ensure the library has a version set to match autotools build
    152   set_target_properties(capnp-websocket PROPERTIES VERSION ${VERSION})
    153   install(TARGETS capnp-websocket ${INSTALL_TARGETS_DEFAULT_ARGS})
    154   install(FILES ${capnp-websocket_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/capnp/compat")
    155 endif()
    156 
    157 # Tools/Compilers ==============================================================
    158 
    159 set(capnpc_sources
    160   compiler/type-id.c++
    161   compiler/error-reporter.c++
    162   compiler/lexer.capnp.c++
    163   compiler/lexer.c++
    164   compiler/grammar.capnp.c++
    165   compiler/parser.c++
    166   compiler/generics.c++
    167   compiler/node-translator.c++
    168   compiler/compiler.c++
    169   schema-parser.c++
    170   serialize-text.c++
    171 )
    172 if(NOT CAPNP_LITE)
    173   add_library(capnpc ${capnpc_sources})
    174   target_link_libraries(capnpc PUBLIC capnp kj)
    175   # Ensure the library has a version set to match autotools build
    176   set_target_properties(capnpc PROPERTIES VERSION ${VERSION})
    177   install(TARGETS capnpc ${INSTALL_TARGETS_DEFAULT_ARGS})
    178   install(FILES ${capnpc_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/capnp")
    179 endif()
    180 
    181 if(NOT CAPNP_LITE)
    182   add_executable(capnp_tool
    183     compiler/module-loader.c++
    184     compiler/capnp.c++
    185   )
    186   target_link_libraries(capnp_tool capnpc capnp-json capnp kj)
    187   set_target_properties(capnp_tool PROPERTIES OUTPUT_NAME capnp)
    188   set_target_properties(capnp_tool PROPERTIES CAPNP_INCLUDE_DIRECTORY
    189     $<JOIN:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>,$<INSTALL_INTERFACE:${CMAKE_INSTALL_BINDIR}/..>>
    190   )
    191   target_compile_definitions(capnp_tool PRIVATE
    192     "CAPNP_INCLUDE_DIR=\"${CMAKE_INSTALL_FULL_INCLUDEDIR}\""
    193     "VERSION=\"${VERSION}\""
    194   )
    195 
    196   add_executable(capnpc_cpp
    197     compiler/capnpc-c++.c++
    198   )
    199   target_link_libraries(capnpc_cpp capnp kj)
    200   set_target_properties(capnpc_cpp PROPERTIES OUTPUT_NAME capnpc-c++)
    201   #Capnp tool needs capnpc_cpp location. But cmake deprecated LOCATION property.
    202   #So we use custom property to pass location
    203   set_target_properties(capnpc_cpp PROPERTIES CAPNPC_CXX_EXECUTABLE
    204     $<TARGET_FILE:capnpc_cpp>
    205   )
    206 
    207   add_executable(capnpc_capnp
    208     compiler/capnpc-capnp.c++
    209   )
    210   target_link_libraries(capnpc_capnp capnp kj)
    211   set_target_properties(capnpc_capnp PROPERTIES OUTPUT_NAME capnpc-capnp)
    212 
    213   install(TARGETS capnp_tool capnpc_cpp capnpc_capnp ${INSTALL_TARGETS_DEFAULT_ARGS})
    214 
    215   if(WIN32)
    216     # On Windows platforms symlinks are not guranteed to support. Also differnt version of CMake handle create_symlink in a different way.
    217     # The most portable way in this case just copy the file.
    218     install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E copy \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_BINDIR}/capnp${CMAKE_EXECUTABLE_SUFFIX}\" \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_BINDIR}/capnpc${CMAKE_EXECUTABLE_SUFFIX}\")")
    219   else()
    220     # Symlink capnpc -> capnp
    221     install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink capnp${CMAKE_EXECUTABLE_SUFFIX} \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_BINDIR}/capnpc${CMAKE_EXECUTABLE_SUFFIX}\")")
    222   endif()
    223 endif()  # NOT CAPNP_LITE
    224 
    225 # Tests ========================================================================
    226 
    227 if(BUILD_TESTING)
    228   set(test_capnp_files
    229     test.capnp
    230     test-import.capnp
    231     test-import2.capnp
    232     compat/json-test.capnp
    233   )
    234 
    235   set(CAPNPC_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/test_capnp")
    236   include_directories("${CAPNPC_OUTPUT_DIR}")
    237   file(MAKE_DIRECTORY "${CAPNPC_OUTPUT_DIR}")
    238   # Tell capnp_generate_cpp to set --src-prefix to our parent directory. This allows us to pass our
    239   # .capnp files relative to this directory, but have their canonical name end up as
    240   # capnp/test.capnp, capnp/test-import.capnp, etc.
    241   get_filename_component(CAPNPC_SRC_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}" DIRECTORY)
    242 
    243   capnp_generate_cpp(test_capnp_cpp_files test_capnp_h_files ${test_capnp_files})
    244 
    245   # TODO(cleanup): capnp-tests and capnp-heavy-tests both depend on the test.capnp output files. In
    246   #   a parallel Makefile-based build (maybe others?), they can race and cause the custom capnp
    247   #   command in capnp_generate_cpp() to run twice. To get around this I'm using a custom target to
    248   #   force CMake to generate race-free Makefiles. Remove this garbage when we move to a
    249   #   target-based capnp_generate() command, as that will make CMake do the right thing by default.
    250   add_custom_target(test_capnp DEPENDS ${test_capnp_cpp_files} ${test_capnp_h_files})
    251 
    252   if(CAPNP_LITE)
    253     set(test_libraries capnp kj-test kj)
    254   else()
    255     set(test_libraries capnp-json capnp-rpc capnp-websocket capnp capnpc kj-http kj-async kj-test kj)
    256   endif()
    257 
    258   add_executable(capnp-tests
    259     common-test.c++
    260     blob-test.c++
    261     endian-test.c++
    262     endian-fallback-test.c++
    263     layout-test.c++
    264     any-test.c++
    265     message-test.c++
    266     encoding-test.c++
    267     orphan-test.c++
    268     serialize-test.c++
    269     serialize-packed-test.c++
    270     canonicalize-test.c++
    271     fuzz-test.c++
    272     test-util.c++
    273     ${test_capnp_cpp_files}
    274     ${test_capnp_h_files}
    275   )
    276   target_link_libraries(capnp-tests ${test_libraries})
    277   add_dependencies(capnp-tests test_capnp)
    278   add_dependencies(check capnp-tests)
    279   add_test(NAME capnp-tests-run COMMAND capnp-tests)
    280 
    281   if(NOT CAPNP_LITE)
    282     add_executable(capnp-heavy-tests
    283       endian-reverse-test.c++
    284       capability-test.c++
    285       membrane-test.c++
    286       schema-test.c++
    287       schema-loader-test.c++
    288       schema-parser-test.c++
    289       dynamic-test.c++
    290       stringify-test.c++
    291       serialize-async-test.c++
    292       serialize-text-test.c++
    293       rpc-test.c++
    294       rpc-twoparty-test.c++
    295       ez-rpc-test.c++
    296       compiler/lexer-test.c++
    297       compiler/type-id-test.c++
    298       test-util.c++
    299       compat/json-test.c++
    300       compat/websocket-rpc-test.c++
    301       ${test_capnp_cpp_files}
    302       ${test_capnp_h_files}
    303     )
    304     target_link_libraries(capnp-heavy-tests ${test_libraries})
    305     if(NOT MSVC)
    306       set_target_properties(capnp-heavy-tests
    307         PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations"
    308       )
    309     endif()
    310 
    311     add_dependencies(capnp-heavy-tests test_capnp)
    312     add_dependencies(check capnp-heavy-tests)
    313     add_test(NAME capnp-heavy-tests-run COMMAND capnp-heavy-tests)
    314 
    315     add_executable(capnp-evolution-tests compiler/evolution-test.c++)
    316     target_link_libraries(capnp-evolution-tests capnpc capnp kj)
    317     add_dependencies(check capnp-evolution-tests)
    318     add_test(NAME capnp-evolution-tests-run COMMAND capnp-evolution-tests)
    319   endif()  # NOT CAPNP_LITE
    320 endif()  # BUILD_TESTING
    321 
    322 if(DEFINED ENV{LIB_FUZZING_ENGINE})
    323   add_executable(capnp_llvm_fuzzer_testcase llvm-fuzzer-testcase.c++ test-util.c++ test-util.h ${test_capnp_cpp_files} ${test_capnp_h_files})
    324   target_link_libraries(capnp_llvm_fuzzer_testcase capnp-rpc capnp kj kj-async capnp-json $ENV{LIB_FUZZING_ENGINE})
    325 endif()