capnproto

FORK: Cap'n Proto serialization/RPC system - core tools and C++ library
git clone https://git.neptards.moe/neptards/capnproto.git
Log | Files | Refs | README | LICENSE

CMakeLists.txt (7583B)


      1 
      2 # kj ===========================================================================
      3 
      4 set(kj_sources_lite
      5   array.c++
      6   list.c++
      7   common.c++
      8   debug.c++
      9   exception.c++
     10   io.c++
     11   memory.c++
     12   mutex.c++
     13   string.c++
     14   source-location.c++
     15   hash.c++
     16   table.c++
     17   thread.c++
     18   main.c++
     19   arena.c++
     20   test-helpers.c++
     21   units.c++
     22   encoding.c++
     23 )
     24 set(kj_sources_heavy
     25   refcount.c++
     26   string-tree.c++
     27   time.c++
     28   filesystem.c++
     29   filesystem-disk-unix.c++
     30   filesystem-disk-win32.c++
     31   parse/char.c++
     32 )
     33 if(NOT CAPNP_LITE)
     34   set(kj_sources ${kj_sources_lite} ${kj_sources_heavy})
     35 else()
     36   set(kj_sources ${kj_sources_lite})
     37 endif()
     38 
     39 set(kj_headers
     40   common.h
     41   units.h
     42   memory.h
     43   refcount.h
     44   array.h
     45   list.h
     46   vector.h
     47   string.h
     48   string-tree.h
     49   source-location.h
     50   hash.h
     51   table.h
     52   map.h
     53   encoding.h
     54   exception.h
     55   debug.h
     56   arena.h
     57   io.h
     58   tuple.h
     59   one-of.h
     60   function.h
     61   mutex.h
     62   thread.h
     63   threadlocal.h
     64   filesystem.h
     65   time.h
     66   main.h
     67   windows-sanity.h
     68 )
     69 set(kj-parse_headers
     70   parse/common.h
     71   parse/char.h
     72 )
     73 set(kj-std_headers
     74   std/iostream.h
     75 )
     76 add_library(kj ${kj_sources})
     77 add_library(CapnProto::kj ALIAS kj)
     78 # TODO(cleanup): Use cxx_std_14 once it's safe to require cmake 3.8.
     79 target_compile_features(kj PUBLIC cxx_generic_lambdas)
     80 
     81 if(UNIX AND NOT ANDROID)
     82   target_link_libraries(kj PUBLIC pthread)
     83 endif()
     84 #make sure the lite flag propagates to all users (internal + external) of this library
     85 target_compile_definitions(kj PUBLIC ${CAPNP_LITE_FLAG})
     86 #make sure external consumers don't need to manually set the include dirs
     87 get_filename_component(PARENT_DIR ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY)
     88 target_include_directories(kj INTERFACE
     89   $<BUILD_INTERFACE:${PARENT_DIR}>
     90   $<INSTALL_INTERFACE:include>
     91 )
     92 # Ensure the library has a version set to match autotools build
     93 set_target_properties(kj PROPERTIES VERSION ${VERSION})
     94 install(TARGETS kj ${INSTALL_TARGETS_DEFAULT_ARGS})
     95 install(FILES ${kj_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kj")
     96 install(FILES ${kj-parse_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kj/parse")
     97 install(FILES ${kj-std_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kj/std")
     98 
     99 set(kj-test_sources
    100   test.c++
    101 )
    102 set(kj-test_headers
    103   test.h
    104 )
    105 set(kj-test-compat_headers
    106   compat/gtest.h
    107 )
    108 add_library(kj-test ${kj-test_sources})
    109 add_library(CapnProto::kj-test ALIAS kj-test)
    110 target_link_libraries(kj-test PUBLIC kj)
    111 # Ensure the library has a version set to match autotools build
    112 set_target_properties(kj-test PROPERTIES VERSION ${VERSION})
    113 install(TARGETS kj-test ${INSTALL_TARGETS_DEFAULT_ARGS})
    114 install(FILES ${kj-test_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kj")
    115 install(FILES ${kj-test-compat_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kj/compat")
    116 
    117 set(kj-async_sources
    118   async.c++
    119   async-unix.c++
    120   async-win32.c++
    121   async-io-win32.c++
    122   async-io.c++
    123   async-io-unix.c++
    124   timer.c++
    125 )
    126 set(kj-async_headers
    127   async-prelude.h
    128   async.h
    129   async-inl.h
    130   async-unix.h
    131   async-win32.h
    132   async-io.h
    133   async-queue.h
    134   timer.h
    135 )
    136 if(NOT CAPNP_LITE)
    137   add_library(kj-async ${kj-async_sources})
    138   add_library(CapnProto::kj-async ALIAS kj-async)
    139   target_link_libraries(kj-async PUBLIC kj)
    140   if(UNIX)
    141     # external clients of this library need to link to pthreads
    142     target_compile_options(kj-async INTERFACE "-pthread")
    143   elseif(WIN32)
    144     target_link_libraries(kj-async PUBLIC ws2_32)
    145   endif()
    146   # Ensure the library has a version set to match autotools build
    147   set_target_properties(kj-async PROPERTIES VERSION ${VERSION})
    148   install(TARGETS kj-async ${INSTALL_TARGETS_DEFAULT_ARGS})
    149   install(FILES ${kj-async_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kj")
    150 endif()
    151 
    152 # kj-http ======================================================================
    153 
    154 set(kj-http_sources
    155   compat/url.c++
    156   compat/http.c++
    157 )
    158 set(kj-http_headers
    159   compat/url.h
    160   compat/http.h
    161 )
    162 if(NOT CAPNP_LITE)
    163   add_library(kj-http ${kj-http_sources})
    164   add_library(CapnProto::kj-http ALIAS kj-http)
    165   target_link_libraries(kj-http PUBLIC kj-async kj)
    166   # Ensure the library has a version set to match autotools build
    167   set_target_properties(kj-http PROPERTIES VERSION ${VERSION})
    168   install(TARGETS kj-http ${INSTALL_TARGETS_DEFAULT_ARGS})
    169   install(FILES ${kj-http_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kj/compat")
    170 endif()
    171 
    172 # kj-tls ======================================================================
    173 set(kj-tls_sources
    174   compat/readiness-io.c++
    175   compat/tls.c++
    176 )
    177 set(kj-tls_headers
    178   compat/readiness-io.h
    179   compat/tls.h
    180 )
    181 if(NOT CAPNP_LITE)
    182   add_library(kj-tls ${kj-tls_sources})
    183   add_library(CapnProto::kj-tls ALIAS kj-tls)
    184   target_link_libraries(kj-tls PUBLIC kj-async)
    185   if (WITH_OPENSSL)
    186     target_compile_definitions(kj-tls PRIVATE KJ_HAS_OPENSSL)
    187     target_link_libraries(kj-tls PRIVATE OpenSSL::SSL OpenSSL::Crypto)
    188   endif()
    189   # Ensure the library has a version set to match autotools build
    190   set_target_properties(kj-tls PROPERTIES VERSION ${VERSION})
    191   install(TARGETS kj-tls ${INSTALL_TARGETS_DEFAULT_ARGS})
    192   install(FILES ${kj-tls_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kj/compat")
    193 endif()
    194 
    195 # kj-gzip ======================================================================
    196 
    197 set(kj-gzip_sources
    198   compat/gzip.c++
    199 )
    200 set(kj-gzip_headers
    201   compat/gzip.h
    202 )
    203 if(NOT CAPNP_LITE)
    204   add_library(kj-gzip ${kj-gzip_sources})
    205   add_library(CapnProto::kj-gzip ALIAS kj-gzip)
    206 
    207   find_package(ZLIB)
    208   if(ZLIB_FOUND)
    209     add_definitions(-D KJ_HAS_ZLIB=1)
    210     include_directories(${ZLIB_INCLUDE_DIRS})
    211     target_link_libraries(kj-gzip PUBLIC kj-async kj ${ZLIB_LIBRARIES})
    212   endif()
    213 
    214   # Ensure the library has a version set to match autotools build
    215   set_target_properties(kj-gzip PROPERTIES VERSION ${VERSION})
    216   install(TARGETS kj-gzip ${INSTALL_TARGETS_DEFAULT_ARGS})
    217   install(FILES ${kj-gzip_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kj/compat")
    218 endif()
    219 
    220 # Tests ========================================================================
    221 
    222 if(BUILD_TESTING)
    223   add_executable(kj-tests
    224     common-test.c++
    225     memory-test.c++
    226     array-test.c++
    227     list-test.c++
    228     string-test.c++
    229     table-test.c++
    230     map-test.c++
    231     exception-test.c++
    232     debug-test.c++
    233     io-test.c++
    234     mutex-test.c++
    235     time-test.c++
    236     threadlocal-test.c++
    237     test-test.c++
    238     std/iostream-test.c++
    239   )
    240   # TODO: Link with librt on Solaris for sched_yield
    241   target_link_libraries(kj-tests kj-test kj)
    242   add_dependencies(check kj-tests)
    243   add_test(NAME kj-tests-run COMMAND kj-tests)
    244 
    245   if(NOT CAPNP_LITE)
    246     add_executable(kj-heavy-tests
    247       async-test.c++
    248       async-xthread-test.c++
    249       async-coroutine-test.c++
    250       async-unix-test.c++
    251       async-unix-xthread-test.c++
    252       async-win32-test.c++
    253       async-win32-xthread-test.c++
    254       async-io-test.c++
    255       async-queue-test.c++
    256       refcount-test.c++
    257       string-tree-test.c++
    258       encoding-test.c++
    259       arena-test.c++
    260       units-test.c++
    261       tuple-test.c++
    262       one-of-test.c++
    263       function-test.c++
    264       filesystem-test.c++
    265       filesystem-disk-test.c++
    266       parse/common-test.c++
    267       parse/char-test.c++
    268       compat/url-test.c++
    269       compat/http-test.c++
    270       compat/gzip-test.c++
    271       compat/tls-test.c++
    272     )
    273     target_link_libraries(kj-heavy-tests kj-http kj-gzip kj-tls kj-async kj-test kj)
    274     if (WITH_OPENSSL)
    275       set_source_files_properties(compat/tls-test.c++
    276         PROPERTIES
    277           COMPILE_DEFINITIONS KJ_HAS_OPENSSL
    278       )
    279     endif()
    280     add_dependencies(check kj-heavy-tests)
    281     add_test(NAME kj-heavy-tests-run COMMAND kj-heavy-tests)
    282   endif()  # NOT CAPNP_LITE
    283 endif()  # BUILD_TESTING