CMakeLists.txt 6.35 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

# capnp ========================================================================

set(capnp_sources_lite
  c++.capnp.c++
  blob.c++
  arena.c++
  layout.c++
  list.c++
  any.c++
  message.c++
  schema.capnp.c++
  serialize.c++
  serialize-packed.c++
)
set(capnp_sources_heavy
  schema.c++
  schema-loader.c++
  dynamic.c++
  stringify.c++
)
if(NOT CAPNP_LITE)
  set(capnp_sources ${capnp_sources_lite} ${capnp_sources_heavy})
else()
  set(capnp_sources ${capnp_sources_lite})
endif()

set(capnp_headers
  c++.capnp.h
  common.h
  blob.h
  endian.h
  layout.h
  orphan.h
  list.h
  any.h
  message.h
  capability.h
39
  membrane.h
40 41 42 43 44 45 46 47 48 49 50 51 52
  dynamic.h
  schema.h
  schema.capnp.h
  schema-lite.h
  schema-loader.h
  schema-parser.h
  pretty-print.h
  serialize.h
  serialize-async.h
  serialize-packed.h
  pointer-helpers.h
  generated-header-support.h
)
53 54 55 56
set(capnp_schemas
  c++.capnp
  schema.capnp
)
57 58 59 60
add_library(capnp ${capnp_sources})
target_link_libraries(capnp kj)

install(TARGETS capnp ARCHIVE DESTINATION "${LIB_INSTALL_DIR}")
61
install(FILES ${capnp_headers} ${capnp_schemas} DESTINATION "${INCLUDE_INSTALL_DIR}/capnp")
62 63 64 65

set(capnp-rpc_sources
  serialize-async.c++
  capability.c++
66
  membrane.c++
67 68 69 70 71
  dynamic-capability.c++
  rpc.c++
  rpc.capnp.c++
  rpc-twoparty.c++
  rpc-twoparty.capnp.c++
72
  persistent.capnp.c++
73 74 75 76 77 78 79 80
  ez-rpc.c++
)
set(capnp-rpc_headers
  rpc-prelude.h
  rpc.h
  rpc-twoparty.h
  rpc.capnp.h
  rpc-twoparty.capnp.h
81
  persistent.capnp.h
82 83
  ez-rpc.h
)
84 85 86 87 88
set(capnp-rpc_schemas
  rpc.capnp
  rpc-twoparty.capnp
  persistent.capnp
)
89 90 91
if(NOT CAPNP_LITE)
  add_library(capnp-rpc ${capnp-rpc_sources})
  target_link_libraries(capnp-rpc kj-async kj)
92
  install(TARGETS capnp-rpc ARCHIVE DESTINATION "${LIB_INSTALL_DIR}")
93
  install(FILES ${capnp-rpc_headers} ${capnp-rpc_schemas} DESTINATION "${INCLUDE_INSTALL_DIR}/capnp")
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
endif()

# Tools/Compilers ==============================================================

set(capnpc_sources
  compiler/md5.c++
  compiler/error-reporter.c++
  compiler/lexer.capnp.c++
  compiler/lexer.c++
  compiler/grammar.capnp.c++
  compiler/parser.c++
  compiler/node-translator.c++
  compiler/compiler.c++
  schema-parser.c++
)
if(NOT CAPNP_LITE)
  add_library(capnpc ${capnpc_sources})
  target_link_libraries(capnpc capnp kj)
112
  install(TARGETS capnpc ARCHIVE DESTINATION "${LIB_INSTALL_DIR}")
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
endif()

if(BUILD_TOOLS AND NOT CAPNP_LITE)
  add_executable(capnp_tool
    compiler/module-loader.c++
    compiler/capnp.c++
  )
  target_link_libraries(capnp_tool capnpc capnp kj)
  set_target_properties(capnp_tool PROPERTIES OUTPUT_NAME capnp)

  add_executable(capnpc_cpp
    compiler/capnpc-c++.c++
  )
  target_link_libraries(capnpc_cpp capnp kj)
  set_target_properties(capnpc_cpp PROPERTIES OUTPUT_NAME capnpc-c++)

  add_executable(capnpc_capnp
    compiler/capnpc-capnp.c++
  )
  target_link_libraries(capnpc_capnp capnp kj)
  set_target_properties(capnpc_capnp PROPERTIES OUTPUT_NAME capnpc-capnp)

  install(TARGETS capnp_tool capnpc_cpp capnpc_capnp RUNTIME DESTINATION "${BIN_INSTALL_DIR}")

  # Symlink capnpc -> capnp
138
  install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink capnp \"${BIN_INSTALL_DIR}/capnpc\")")
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
endif()  # BUILD_TOOLS AND NOT CAPNP_LITE

# Tests ========================================================================

if(BUILD_TESTING)
  set(test_capnp_files
    test.capnp
    test-import.capnp
    test-import2.capnp
  )

  # Setup paths to the schema compiler for generating ${test_capnp_files}
  if(NOT EXTERNAL_CAPNP)
    set(CAPNP_EXECUTABLE $<TARGET_FILE:capnp_tool>)
    set(CAPNPC_CXX_EXECUTABLE $<TARGET_FILE:capnpc_cpp>)
  else()
    # Allow paths to tools to be set with one of: (1) the CMake variables from the
    # the FindCapnProto module; (2) environment variables; or (3) find_program()
    if (NOT CAPNP_EXECUTABLE)
      if (DEFINED ENV{CAPNP})
159
        set(CAPNP_EXECUTABLE "$ENV{CAPNP}")
160 161 162 163 164 165 166
      else()
        find_program(CAPNP_EXECUTABLE capnp)
      endif()
    endif()

    if(NOT CAPNPC_CXX_EXECUTABLE)
      if (DEFINED ENV{CAPNPC_CXX})
167
        set(CAPNPC_CXX_EXECUTABLE "$ENV{CAPNPC_CXX}")
168 169
      else()
        # Also search in the same directory that `capnp` was found in
170 171
        get_filename_component(capnp_dir "${CAPNP_EXECUTABLE}" DIRECTORY)
        find_program(CAPNPC_CXX_EXECUTABLE capnpc-c++ HINTS "${capnp_dir}")
172 173 174 175 176
      endif()
    endif()
  endif()

  # Add "/capnp" to match the path used to import the files in the test sources
177 178 179
  set(CAPNPC_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/test_capnp/capnp")
  include_directories("${CMAKE_CURRENT_BINARY_DIR}/test_capnp")  # Note: no "/capnp"
  file(MAKE_DIRECTORY "${CAPNPC_OUTPUT_DIR}")
180 181 182 183

  capnp_generate_cpp(test_capnp_cpp_files test_capnp_h_files ${test_capnp_files})

  if(CAPNP_LITE)
184
    set(test_libraries capnp kj-test kj)
185
  else()
186
    set(test_libraries capnp-rpc capnp capnpc kj-async kj-test kj)
187 188 189 190 191 192 193 194 195 196 197 198 199 200
  endif()

  add_executable(capnp-tests
    common-test.c++
    blob-test.c++
    endian-test.c++
    endian-fallback-test.c++
    layout-test.c++
    any-test.c++
    message-test.c++
    encoding-test.c++
    orphan-test.c++
    serialize-test.c++
    serialize-packed-test.c++
201
    fuzz-test.c++
202 203 204 205 206 207 208 209 210 211
    test-util.c++
    ${test_capnp_cpp_files}
    ${test_capnp_h_files}
  )
  target_link_libraries(capnp-tests ${test_libraries})
  add_dependencies(check capnp-tests)
  add_test(NAME capnp-tests-run COMMAND capnp-tests)

  if(NOT CAPNP_LITE)
    add_executable(capnp-heavy-tests
212
      endian-reverse-test.c++
213
      capability-test.c++
214
      membrane-test.c++
215 216
      schema-test.c++
      schema-loader-test.c++
217
      schema-parser-test.c++
218 219 220 221 222 223 224 225 226 227 228 229 230
      dynamic-test.c++
      stringify-test.c++
      serialize-async-test.c++
      rpc-test.c++
      rpc-twoparty-test.c++
      ez-rpc-test.c++
      compiler/lexer-test.c++
      compiler/md5-test.c++
      test-util.c++
      ${test_capnp_cpp_files}
      ${test_capnp_h_files}
    )
    target_link_libraries(capnp-heavy-tests ${test_libraries})
231 232 233 234
    set_target_properties(capnp-heavy-tests
      PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations"
    )

235 236 237 238 239 240 241 242 243
    add_dependencies(check capnp-heavy-tests)
    add_test(NAME capnp-heavy-tests-run COMMAND capnp-heavy-tests)

    add_executable(capnp-evolution-tests compiler/evolution-test.c++)
    target_link_libraries(capnp-evolution-tests capnpc capnp kj)
    add_dependencies(check capnp-evolution-tests)
    add_test(NAME capnp-evolution-tests-run COMMAND capnp-evolution-tests)
  endif()  # NOT CAPNP_LITE
endif()  # BUILD_TESTING