CMakeLists.txt 6.29 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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

# 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
  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
)
add_library(capnp ${capnp_sources})
target_link_libraries(capnp kj)

install(TARGETS capnp ARCHIVE DESTINATION "${LIB_INSTALL_DIR}")
install(FILES ${capnp_headers} DESTINATION "${INCLUDE_INSTALL_DIR}/capnp")

set(capnp-rpc_sources
  serialize-async.c++
  capability.c++
  dynamic-capability.c++
  rpc.c++
  rpc.capnp.c++
  rpc-twoparty.c++
  rpc-twoparty.capnp.c++
66
  persistent.capnp.c++
67 68 69 70 71 72 73 74
  ez-rpc.c++
)
set(capnp-rpc_headers
  rpc-prelude.h
  rpc.h
  rpc-twoparty.h
  rpc.capnp.h
  rpc-twoparty.capnp.h
75
  persistent.capnp.h
76 77 78 79 80
  ez-rpc.h
)
if(NOT CAPNP_LITE)
  add_library(capnp-rpc ${capnp-rpc_sources})
  target_link_libraries(capnp-rpc kj-async kj)
81 82
  install(TARGETS capnp-rpc ARCHIVE DESTINATION "${LIB_INSTALL_DIR}")
  install(FILES ${capnp-rpc_headers} DESTINATION "${INCLUDE_INSTALL_DIR}/capnp")
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
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++
)
set(capnpc_headers
  c++.capnp
  schema.capnp
  rpc.capnp
  rpc-twoparty.capnp
103
  persistent.capnp
104 105 106 107
)
if(NOT CAPNP_LITE)
  add_library(capnpc ${capnpc_sources})
  target_link_libraries(capnpc capnp kj)
108 109
  install(TARGETS capnpc ARCHIVE DESTINATION "${LIB_INSTALL_DIR}")
  install(FILES ${capnpc_headers} DESTINATION "${INCLUDE_INSTALL_DIR}/capnp")
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
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
135
  install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink capnp \"${BIN_INSTALL_DIR}/capnpc\")")
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
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})
156
        set(CAPNP_EXECUTABLE "$ENV{CAPNP}")
157 158 159 160 161 162 163
      else()
        find_program(CAPNP_EXECUTABLE capnp)
      endif()
    endif()

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

  # Add "/capnp" to match the path used to import the files in the test sources
174 175 176
  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}")
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207

  capnp_generate_cpp(test_capnp_cpp_files test_capnp_h_files ${test_capnp_files})

  if(CAPNP_LITE)
    set(test_libraries capnp kj gtest gtest_main)
  else()
    set(test_libraries capnp capnp-rpc capnpc kj kj-async gtest gtest_main)
  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++
    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
208
      endian-reverse-test.c++
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
      capability-test.c++
      schema-test.c++
      schema-loader-test.c++
      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})
225 226 227 228
    set_target_properties(capnp-heavy-tests
      PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations"
    )

229 230 231 232 233 234 235 236 237
    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