CMakeLists.txt 5.31 KB
Newer Older
1 2 3

# kj ===========================================================================

4
set(kj_sources_lite
5
  array.c++
6
  common.c++
7
  debug.c++
8
  exception.c++
9
  io.c++
10
  memory.c++
11
  mutex.c++
12
  string.c++
13
  thread.c++
14 15
  main.c++
  arena.c++
16
  test-helpers.c++
17 18 19 20 21
)
set(kj_sources_heavy
  units.c++
  refcount.c++
  string-tree.c++
22
  encoding.c++
23
  time.c++
24
  filesystem.c++
25
  filesystem-disk-unix.c++
26
  filesystem-disk-win32.c++
27 28
  parse/char.c++
)
29
if(NOT CAPNP_LITE)
30 31 32
  set(kj_sources ${kj_sources_lite} ${kj_sources_heavy})
else()
  set(kj_sources ${kj_sources_lite})
33 34
endif()

35 36 37 38 39 40 41 42 43
set(kj_headers
  common.h
  units.h
  memory.h
  refcount.h
  array.h
  vector.h
  string.h
  string-tree.h
44
  encoding.h
45 46 47 48 49 50 51 52 53 54
  exception.h
  debug.h
  arena.h
  io.h
  tuple.h
  one-of.h
  function.h
  mutex.h
  thread.h
  threadlocal.h
55
  filesystem.h
56
  time.h
57 58 59 60 61 62 63
  main.h
  windows-sanity.h
)
set(kj-parse_headers
  parse/common.h
  parse/char.h
)
64 65 66
set(kj-std_headers
  std/iostream.h
)
67
add_library(kj ${kj_sources})
68
add_library(CapnProto::kj ALIAS kj)
69 70 71
target_compile_features(kj PUBLIC cxx_constexpr)
# Requiring the cxx_std_11 metafeature would be preferable, but that doesn't exist until CMake 3.8.

72
if(UNIX AND NOT ANDROID)
73 74 75 76 77
  target_link_libraries(kj PUBLIC pthread)
endif()
#make sure the lite flag propagates to all users (internal + external) of this library
target_compile_definitions(kj PUBLIC ${CAPNP_LITE_FLAG})
#make sure external consumers don't need to manually set the include dirs
78 79 80 81
target_include_directories(kj INTERFACE
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
  $<INSTALL_INTERFACE:include>
)
82 83
# Ensure the library has a version set to match autotools build
set_target_properties(kj PROPERTIES VERSION ${VERSION})
84
install(TARGETS kj ${INSTALL_TARGETS_DEFAULT_ARGS})
85 86 87
install(FILES ${kj_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kj")
install(FILES ${kj-parse_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kj/parse")
install(FILES ${kj-std_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kj/std")
88

89 90 91 92 93 94 95 96 97 98
set(kj-test_sources
  test.c++
)
set(kj-test_headers
  test.h
)
set(kj-test-compat_headers
  compat/gtest.h
)
add_library(kj-test ${kj-test_sources})
99
add_library(CapnProto::kj-test ALIAS kj-test)
100
target_link_libraries(kj-test PUBLIC kj)
101 102
# Ensure the library has a version set to match autotools build
set_target_properties(kj-test PROPERTIES VERSION ${VERSION})
103
install(TARGETS kj-test ${INSTALL_TARGETS_DEFAULT_ARGS})
104 105
install(FILES ${kj-test_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kj")
install(FILES ${kj-test-compat_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kj/compat")
106

107 108 109
set(kj-async_sources
  async.c++
  async-unix.c++
110 111
  async-win32.c++
  async-io-win32.c++
Kenton Varda's avatar
Kenton Varda committed
112
  async-io.c++
113
  async-io-unix.c++
114
  timer.c++
115 116 117 118 119 120
)
set(kj-async_headers
  async-prelude.h
  async.h
  async-inl.h
  async-unix.h
121
  async-win32.h
122
  async-io.h
123
  timer.h
124 125 126
)
if(NOT CAPNP_LITE)
  add_library(kj-async ${kj-async_sources})
127
  add_library(CapnProto::kj-async ALIAS kj-async)
128
  target_link_libraries(kj-async PUBLIC kj)
129 130 131
  if(UNIX)
    # external clients of this library need to link to pthreads
    target_compile_options(kj-async INTERFACE "-pthread")
132 133
  elseif(WIN32)
    target_link_libraries(kj-async PUBLIC ws2_32)
134
  endif()
135 136
  # Ensure the library has a version set to match autotools build
  set_target_properties(kj-async PROPERTIES VERSION ${VERSION})
137
  install(TARGETS kj-async ${INSTALL_TARGETS_DEFAULT_ARGS})
138
  install(FILES ${kj-async_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kj")
139 140
endif()

141 142 143
# kj-http ======================================================================

set(kj-http_sources
144
  compat/url.c++
145 146 147
  compat/http.c++
)
set(kj-http_headers
148
  compat/url.h
149 150 151 152 153
  compat/http.h
)
if(NOT CAPNP_LITE)
  add_library(kj-http ${kj-http_sources})
  add_library(CapnProto::kj-http ALIAS kj-http)
154
  target_link_libraries(kj-http PUBLIC kj-async kj)
155 156
  # Ensure the library has a version set to match autotools build
  set_target_properties(kj-http PROPERTIES VERSION ${VERSION})
157 158 159 160
  install(TARGETS kj-http ${INSTALL_TARGETS_DEFAULT_ARGS})
  install(FILES ${kj-http_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kj/compat")
endif()

161 162 163 164 165 166 167 168 169 170 171 172 173
# Tests ========================================================================

if(BUILD_TESTING)
  add_executable(kj-tests
    common-test.c++
    memory-test.c++
    array-test.c++
    string-test.c++
    exception-test.c++
    debug-test.c++
    io-test.c++
    mutex-test.c++
    threadlocal-test.c++
Kenton Varda's avatar
Kenton Varda committed
174
    test-test.c++
175
    std/iostream-test.c++
176 177
  )
  # TODO: Link with librt on Solaris for sched_yield
178
  target_link_libraries(kj-tests kj-test kj)
179 180 181 182 183 184 185
  add_dependencies(check kj-tests)
  add_test(NAME kj-tests-run COMMAND kj-tests)

  if(NOT CAPNP_LITE)
    add_executable(kj-heavy-tests
      async-test.c++
      async-unix-test.c++
186
      async-win32-test.c++
187
      async-io-test.c++
188 189
      refcount-test.c++
      string-tree-test.c++
190
      encoding-test.c++
191 192 193 194 195 196
      arena-test.c++
      units-test.c++
      tuple-test.c++
      one-of-test.c++
      function-test.c++
      threadlocal-pthread-test.c++
197 198
      filesystem-test.c++
      filesystem-disk-test.c++
199 200
      parse/common-test.c++
      parse/char-test.c++
201
      compat/url-test.c++
202
      compat/http-test.c++
203
    )
204
    target_link_libraries(kj-heavy-tests kj-http kj-async kj-test kj)
205 206 207 208
    add_dependencies(check kj-heavy-tests)
    add_test(NAME kj-heavy-tests-run COMMAND kj-heavy-tests)
  endif()  # NOT CAPNP_LITE
endif()  # BUILD_TESTING