CMakeLists.txt 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. cmake_minimum_required(VERSION 2.6)
  2. project(enet)
  3. # The "configure" step.
  4. include(CheckFunctionExists)
  5. include(CheckStructHasMember)
  6. include(CheckTypeSize)
  7. check_function_exists("fcntl" HAS_FCNTL)
  8. check_function_exists("poll" HAS_POLL)
  9. check_function_exists("getaddrinfo" HAS_GETADDRINFO)
  10. check_function_exists("getnameinfo" HAS_GETNAMEINFO)
  11. check_function_exists("gethostbyname_r" HAS_GETHOSTBYNAME_R)
  12. check_function_exists("gethostbyaddr_r" HAS_GETHOSTBYADDR_R)
  13. check_function_exists("inet_pton" HAS_INET_PTON)
  14. check_function_exists("inet_ntop" HAS_INET_NTOP)
  15. check_struct_has_member("struct msghdr" "msg_flags" "sys/types.h;sys/socket.h" HAS_MSGHDR_FLAGS)
  16. set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h" "sys/socket.h")
  17. check_type_size("socklen_t" HAS_SOCKLEN_T BUILTIN_TYPES_ONLY)
  18. unset(CMAKE_EXTRA_INCLUDE_FILES)
  19. if(MSVC)
  20. add_definitions(-W3)
  21. else()
  22. add_definitions(-Wno-error)
  23. endif()
  24. if(HAS_FCNTL)
  25. add_definitions(-DHAS_FCNTL=1)
  26. endif()
  27. if(HAS_POLL)
  28. add_definitions(-DHAS_POLL=1)
  29. endif()
  30. if(HAS_GETNAMEINFO)
  31. add_definitions(-DHAS_GETNAMEINFO=1)
  32. endif()
  33. if(HAS_GETADDRINFO)
  34. add_definitions(-DHAS_GETADDRINFO=1)
  35. endif()
  36. if(HAS_GETHOSTBYNAME_R)
  37. add_definitions(-DHAS_GETHOSTBYNAME_R=1)
  38. endif()
  39. if(HAS_GETHOSTBYADDR_R)
  40. add_definitions(-DHAS_GETHOSTBYADDR_R=1)
  41. endif()
  42. if(HAS_INET_PTON)
  43. add_definitions(-DHAS_INET_PTON=1)
  44. endif()
  45. if(HAS_INET_NTOP)
  46. add_definitions(-DHAS_INET_NTOP=1)
  47. endif()
  48. if(HAS_MSGHDR_FLAGS)
  49. add_definitions(-DHAS_MSGHDR_FLAGS=1)
  50. endif()
  51. if(HAS_SOCKLEN_T)
  52. add_definitions(-DHAS_SOCKLEN_T=1)
  53. endif()
  54. include_directories(${PROJECT_SOURCE_DIR}/include)
  55. set(INCLUDE_FILES_PREFIX include/enet)
  56. set(INCLUDE_FILES
  57. ${INCLUDE_FILES_PREFIX}/callbacks.h
  58. ${INCLUDE_FILES_PREFIX}/enet.h
  59. ${INCLUDE_FILES_PREFIX}/list.h
  60. ${INCLUDE_FILES_PREFIX}/protocol.h
  61. ${INCLUDE_FILES_PREFIX}/time.h
  62. ${INCLUDE_FILES_PREFIX}/types.h
  63. ${INCLUDE_FILES_PREFIX}/unix.h
  64. ${INCLUDE_FILES_PREFIX}/utility.h
  65. ${INCLUDE_FILES_PREFIX}/win32.h
  66. )
  67. set(SOURCE_FILES
  68. src/callbacks.c
  69. src/compress.c
  70. src/host.c
  71. src/list.c
  72. src/packet.c
  73. src/peer.c
  74. src/protocol.c
  75. src/unix.c
  76. src/win32.c)
  77. source_group(include FILES ${INCLUDE_FILES})
  78. source_group(source FILES ${SOURCE_FILES})
  79. add_library(enet STATIC
  80. ${INCLUDE_FILES}
  81. ${SOURCE_FILES}
  82. )
  83. if (MINGW)
  84. target_link_libraries(enet winmm ws2_32)
  85. endif()