summaryrefslogtreecommitdiffstats
path: root/tpool/CMakeLists.txt
blob: 115e3d58634317b13866ff6e9c2b8704ae20f5a1 (plain)
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
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/include)
IF(WIN32)
  SET(EXTRA_SOURCES tpool_win.cc aio_win.cc)
ELSEIF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  OPTION(WITH_URING "Require that io_uring be used" OFF)
  OPTION(WITH_LIBAIO "Require that libaio is used, unless uring is there" OFF)
  IF(WITH_URING)
    SET(URING_REQUIRED REQUIRED)
  ELSEIF(WITH_LIBAIO)
    SET(LIBAIO_REQIRED REQUIRED)
  ENDIF()
  FIND_PACKAGE(URING QUIET ${URING_REQUIRED})
  IF(URING_FOUND)
    SET(URING_FOUND ${URING_FOUND} PARENT_SCOPE)
    SET(TPOOL_DEFINES "-DHAVE_URING" PARENT_SCOPE)
    ADD_DEFINITIONS(-DHAVE_URING)
    LINK_LIBRARIES(${URING_LIBRARIES})
    INCLUDE_DIRECTORIES(${URING_INCLUDE_DIRS})
    SET(EXTRA_SOURCES aio_liburing.cc)
    SET(CMAKE_REQUIRED_INCLUDES_SAVE ${CMAKE_REQUIRED_INCLUDES})
    SET(CMAKE_REQUIRED_LIBRARIES_SAVE ${CMAKE_REQUIRED_LIBRARIES})
    SET(CMAKE_REQUIRED_INCLUDES ${URING_INCLUDE_DIRS})
    SET(CMAKE_REQUIRED_LIBRARIES ${URING_LIBRARIES})
    CHECK_SYMBOL_EXISTS(io_uring_mlock_size "liburing.h" HAVE_IO_URING_MLOCK_SIZE)
    SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_SAVE})
    SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_SAVE})
    IF(HAVE_IO_URING_MLOCK_SIZE)
      SET_SOURCE_FILES_PROPERTIES(aio_liburing.cc PROPERTIES COMPILE_FLAGS "-DHAVE_IO_URING_MLOCK_SIZE")
    ENDIF()
  ELSE()
    FIND_PACKAGE(LIBAIO QUIET ${LIBAIO_REQUIRED})
    IF(LIBAIO_FOUND)
      SET(TPOOL_DEFINES "-DLINUX_NATIVE_AIO" PARENT_SCOPE)
      ADD_DEFINITIONS(-DLINUX_NATIVE_AIO)
      INCLUDE_DIRECTORIES(${LIBAIO_INCLUDE_DIRS})
      LINK_LIBRARIES(${LIBAIO_LIBRARIES})
      SET(EXTRA_SOURCES aio_linux.cc)
    ENDIF()
  ENDIF()
ENDIF()

ADD_LIBRARY(tpool STATIC
  aio_simulated.cc
  tpool_structs.h
  CMakeLists.txt
  tpool.h
  tpool_generic.cc
  task_group.cc
  task.cc
  wait_notification.cc
  ${EXTRA_SOURCES}
)

IF(URING_FOUND)
  ADD_DEPENDENCIES(tpool GenError)
ENDIF()