CMakeLists.txt 5.15 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 24
  parse/char.c++
)
25
if(NOT CAPNP_LITE)
26 27 28
  set(kj_sources ${kj_sources_lite} ${kj_sources_heavy})
else()
  set(kj_sources ${kj_sources_lite})
29 30
endif()

31 32 33 34 35 36 37 38 39
set(kj_headers
  common.h
  units.h
  memory.h
  refcount.h
  array.h
  vector.h
  string.h
  string-tree.h
40
  encoding.h
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
  exception.h
  debug.h
  arena.h
  io.h
  tuple.h
  one-of.h
  function.h
  mutex.h
  thread.h
  threadlocal.h
  main.h
  windows-sanity.h
)
set(kj-parse_headers
  parse/common.h
  parse/char.h
)
58 59 60
set(kj-std_headers
  std/iostream.h
)
61
add_library(kj ${kj_sources})
62
add_library(CapnProto::kj ALIAS kj)
63 64 65
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.

66
if(UNIX AND NOT ANDROID)
67 68 69 70 71
  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
72 73 74 75
target_include_directories(kj INTERFACE
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
  $<INSTALL_INTERFACE:include>
)
76 77
# Ensure the library has a version set to match autotools build
set_target_properties(kj PROPERTIES VERSION ${VERSION})
78
install(TARGETS kj ${INSTALL_TARGETS_DEFAULT_ARGS})
79 80 81
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")
82

83 84 85 86 87 88 89 90 91 92
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})
93
add_library(CapnProto::kj-test ALIAS kj-test)
94
target_link_libraries(kj-test PUBLIC kj)
95 96
# Ensure the library has a version set to match autotools build
set_target_properties(kj-test PROPERTIES VERSION ${VERSION})
97
install(TARGETS kj-test ${INSTALL_TARGETS_DEFAULT_ARGS})
98 99
install(FILES ${kj-test_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kj")
install(FILES ${kj-test-compat_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kj/compat")
100

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

135 136 137
# kj-http ======================================================================

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

155 156 157 158 159 160 161 162 163 164 165 166 167
# 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
168
    test-test.c++
169
    std/iostream-test.c++
170 171
  )
  # TODO: Link with librt on Solaris for sched_yield
172
  target_link_libraries(kj-tests kj-test kj)
173 174 175 176 177 178 179
  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++
180
      async-win32-test.c++
181
      async-io-test.c++
182 183
      refcount-test.c++
      string-tree-test.c++
184
      encoding-test.c++
185 186 187 188 189 190
      arena-test.c++
      units-test.c++
      tuple-test.c++
      one-of-test.c++
      function-test.c++
      threadlocal-pthread-test.c++
191 192
      parse/common-test.c++
      parse/char-test.c++
193
      compat/url-test.c++
194
      compat/http-test.c++
195
    )
196
    target_link_libraries(kj-heavy-tests kj-http kj-async kj-test kj)
197 198 199 200
    add_dependencies(check kj-heavy-tests)
    add_test(NAME kj-heavy-tests-run COMMAND kj-heavy-tests)
  endif()  # NOT CAPNP_LITE
endif()  # BUILD_TESTING