CMakeLists.txt 8.33 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
  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
50
  serialize-text.h
51 52
  pointer-helpers.h
  generated-header-support.h
53
  raw-schema.h
54
)
55 56 57 58
set(capnp_schemas
  c++.capnp
  schema.capnp
)
59
add_library(capnp ${capnp_sources})
60
add_library(CapnProto::capnp ALIAS capnp)
61
target_link_libraries(capnp PUBLIC kj)
62
#make sure external consumers don't need to manually set the include dirs
63 64 65 66
target_include_directories(capnp INTERFACE
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
  $<INSTALL_INTERFACE:include>
)
67 68
# Ensure the library has a version set to match autotools build
set_target_properties(capnp PROPERTIES VERSION ${VERSION})
69
install(TARGETS capnp ${INSTALL_TARGETS_DEFAULT_ARGS})
70
install(FILES ${capnp_headers} ${capnp_schemas} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/capnp")
71 72 73 74

set(capnp-rpc_sources
  serialize-async.c++
  capability.c++
75
  membrane.c++
76 77 78 79 80
  dynamic-capability.c++
  rpc.c++
  rpc.capnp.c++
  rpc-twoparty.c++
  rpc-twoparty.capnp.c++
81
  persistent.capnp.c++
82 83 84 85 86 87 88 89
  ez-rpc.c++
)
set(capnp-rpc_headers
  rpc-prelude.h
  rpc.h
  rpc-twoparty.h
  rpc.capnp.h
  rpc-twoparty.capnp.h
90
  persistent.capnp.h
91 92
  ez-rpc.h
)
93 94 95 96 97
set(capnp-rpc_schemas
  rpc.capnp
  rpc-twoparty.capnp
  persistent.capnp
)
98 99
if(NOT CAPNP_LITE)
  add_library(capnp-rpc ${capnp-rpc_sources})
100
  add_library(CapnProto::capnp-rpc ALIAS capnp-rpc)
101
  target_link_libraries(capnp-rpc PUBLIC capnp kj-async kj)
102 103
  # Ensure the library has a version set to match autotools build
  set_target_properties(capnp-rpc PROPERTIES VERSION ${VERSION})
104
  install(TARGETS capnp-rpc ${INSTALL_TARGETS_DEFAULT_ARGS})
105
  install(FILES ${capnp-rpc_headers} ${capnp-rpc_schemas} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/capnp")
106 107
endif()

108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
# capnp-json ========================================================================

set(capnp-json_sources
  compat/json.c++
  compat/json.capnp.c++
)
set(capnp-json_headers
  compat/json.h
  compat/json.capnp.h
)
set(capnp-json_schemas
  compat/json.capnp
)
if(NOT CAPNP_LITE)
  add_library(capnp-json ${capnp-json_sources})
123
  add_library(CapnProto::capnp-json ALIAS capnp-json)
124
  target_link_libraries(capnp-json PUBLIC capnp kj-async kj)
125 126
  # Ensure the library has a version set to match autotools build
  set_target_properties(capnp-json PROPERTIES VERSION ${VERSION})
127
  install(TARGETS capnp-json ${INSTALL_TARGETS_DEFAULT_ARGS})
128
  install(FILES ${capnp-json_headers} ${capnp-json_schemas} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/capnp/compat")
129 130
endif()

131 132
# Tools/Compilers ==============================================================

133
set(capnpc_sources
134
  compiler/type-id.c++
135 136 137 138 139 140 141 142 143 144 145 146
  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++
  serialize-text.c++
)
if(NOT CAPNP_LITE)
  add_library(capnpc ${capnpc_sources})
147
  target_link_libraries(capnpc PUBLIC capnp kj)
148 149
  # Ensure the library has a version set to match autotools build
  set_target_properties(capnpc PROPERTIES VERSION ${VERSION})
150 151 152
  install(TARGETS capnpc ${INSTALL_TARGETS_DEFAULT_ARGS})
  install(FILES ${capnpc_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/capnp")
endif()
153

154 155 156 157 158
if(NOT CAPNP_LITE)
  add_executable(capnp_tool
    compiler/module-loader.c++
    compiler/capnp.c++
  )
159
  target_link_libraries(capnp_tool capnpc capnp-json capnp kj)
160 161 162 163
  set_target_properties(capnp_tool PROPERTIES OUTPUT_NAME capnp)
  set_target_properties(capnp_tool PROPERTIES CAPNP_INCLUDE_DIRECTORY
    $<JOIN:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>,$<INSTALL_INTERFACE:${CMAKE_INSTALL_BINDIR}/..>>
  )
164

165 166 167 168 169 170 171 172 173 174
  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++)
  #Capnp tool needs capnpc_cpp location. But cmake deprecated LOCATION property.
  #So we use custom property to pass location
  set_target_properties(capnpc_cpp PROPERTIES CAPNPC_CXX_EXECUTABLE
    $<TARGET_FILE:capnpc_cpp>
  )
175

176 177 178 179 180
  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)
181

182
  install(TARGETS capnp_tool capnpc_cpp capnpc_capnp ${INSTALL_TARGETS_DEFAULT_ARGS})
183

184 185 186
  # Symlink capnpc -> capnp
  install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink capnp \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_BINDIR}/capnpc\")")
endif()  # NOT CAPNP_LITE
187 188 189 190 191 192 193 194 195 196

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

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

197 198
  set(CAPNPC_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/test_capnp")
  include_directories("${CAPNPC_OUTPUT_DIR}")
199
  file(MAKE_DIRECTORY "${CAPNPC_OUTPUT_DIR}")
200 201 202 203
  # Tell capnp_generate_cpp to set --src-prefix to our parent directory. This allows us to pass our
  # .capnp files relative to this directory, but have their canonical name end up as
  # capnp/test.capnp, capnp/test-import.capnp, etc.
  get_filename_component(CAPNPC_SRC_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}" DIRECTORY)
204 205 206

  capnp_generate_cpp(test_capnp_cpp_files test_capnp_h_files ${test_capnp_files})

207 208 209 210 211 212 213
  # TODO(cleanup): capnp-tests and capnp-heavy-tests both depend on the test.capnp output files. In
  #   a parallel Makefile-based build (maybe others?), they can race and cause the custom capnp
  #   command in capnp_generate_cpp() to run twice. To get around this I'm using a custom target to
  #   force CMake to generate race-free Makefiles. Remove this garbage when we move to a
  #   target-based capnp_generate() command, as that will make CMake do the right thing by default.
  add_custom_target(test_capnp DEPENDS ${test_capnp_cpp_files} ${test_capnp_h_files})

214 215 216 217
  if(CAPNP_LITE)
    set(test_libraries capnp kj-test kj)
  else()
    set(test_libraries capnp-json capnp-rpc capnp capnpc kj-async kj-test kj)
218 219 220 221 222 223 224 225 226 227 228 229 230 231
  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++
Matthew Maurer's avatar
Matthew Maurer committed
232
    canonicalize-test.c++
233
    fuzz-test.c++
234 235 236 237 238
    test-util.c++
    ${test_capnp_cpp_files}
    ${test_capnp_h_files}
  )
  target_link_libraries(capnp-tests ${test_libraries})
239
  add_dependencies(capnp-tests test_capnp)
240 241 242 243 244
  add_dependencies(check capnp-tests)
  add_test(NAME capnp-tests-run COMMAND capnp-tests)

  if(NOT CAPNP_LITE)
    add_executable(capnp-heavy-tests
245
      endian-reverse-test.c++
246
      capability-test.c++
247
      membrane-test.c++
248 249
      schema-test.c++
      schema-loader-test.c++
250
      schema-parser-test.c++
251 252 253
      dynamic-test.c++
      stringify-test.c++
      serialize-async-test.c++
254
      serialize-text-test.c++
255 256 257
      rpc-test.c++
      rpc-twoparty-test.c++
      ez-rpc-test.c++
258
      compiler/lexer-test.c++
259
      compiler/type-id-test.c++
260
      test-util.c++
261
      compat/json-test.c++
262 263 264 265
      ${test_capnp_cpp_files}
      ${test_capnp_h_files}
    )
    target_link_libraries(capnp-heavy-tests ${test_libraries})
266 267 268 269 270
    if(NOT MSVC)
      set_target_properties(capnp-heavy-tests
        PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations"
      )
    endif()
271

272
    add_dependencies(capnp-heavy-tests test_capnp)
273 274 275
    add_dependencies(check capnp-heavy-tests)
    add_test(NAME capnp-heavy-tests-run COMMAND capnp-heavy-tests)

276 277 278 279
    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)
280 281
  endif()  # NOT CAPNP_LITE
endif()  # BUILD_TESTING