CMakeLists.txt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. cmake_minimum_required(VERSION 2.8.12...3.20)
  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_c_source_compiles("
  16. #include <stddef.h>
  17. struct S { int a; double b; };
  18. int main() {
  19. return (int)offsetof(struct S, b);
  20. }
  21. " HAS_OFFSETOF)
  22. check_struct_has_member("struct msghdr" "msg_flags" "sys/types.h;sys/socket.h" HAS_MSGHDR_FLAGS)
  23. set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h" "sys/socket.h")
  24. check_type_size("socklen_t" HAS_SOCKLEN_T BUILTIN_TYPES_ONLY)
  25. unset(CMAKE_EXTRA_INCLUDE_FILES)
  26. if(MSVC)
  27. add_definitions(-W3)
  28. else()
  29. add_definitions(-Wno-error)
  30. endif()
  31. if(HAS_FCNTL)
  32. add_definitions(-DHAS_FCNTL=1)
  33. endif()
  34. if(HAS_POLL)
  35. add_definitions(-DHAS_POLL=1)
  36. endif()
  37. if(HAS_GETNAMEINFO)
  38. add_definitions(-DHAS_GETNAMEINFO=1)
  39. endif()
  40. if(HAS_GETADDRINFO)
  41. add_definitions(-DHAS_GETADDRINFO=1)
  42. endif()
  43. if(HAS_GETHOSTBYNAME_R)
  44. add_definitions(-DHAS_GETHOSTBYNAME_R=1)
  45. endif()
  46. if(HAS_GETHOSTBYADDR_R)
  47. add_definitions(-DHAS_GETHOSTBYADDR_R=1)
  48. endif()
  49. if(HAS_INET_PTON)
  50. add_definitions(-DHAS_INET_PTON=1)
  51. endif()
  52. if(HAS_INET_NTOP)
  53. add_definitions(-DHAS_INET_NTOP=1)
  54. endif()
  55. if(HAS_OFFSETOF)
  56. add_definitions(-DHAS_OFFSETOF=1)
  57. endif()
  58. if(HAS_MSGHDR_FLAGS)
  59. add_definitions(-DHAS_MSGHDR_FLAGS=1)
  60. endif()
  61. if(HAS_SOCKLEN_T)
  62. add_definitions(-DHAS_SOCKLEN_T=1)
  63. endif()
  64. include_directories(${PROJECT_SOURCE_DIR}/include)
  65. set(INCLUDE_FILES_PREFIX include/enet)
  66. set(INCLUDE_FILES
  67. ${INCLUDE_FILES_PREFIX}/callbacks.h
  68. ${INCLUDE_FILES_PREFIX}/enet.h
  69. ${INCLUDE_FILES_PREFIX}/list.h
  70. ${INCLUDE_FILES_PREFIX}/protocol.h
  71. ${INCLUDE_FILES_PREFIX}/time.h
  72. ${INCLUDE_FILES_PREFIX}/types.h
  73. ${INCLUDE_FILES_PREFIX}/unix.h
  74. ${INCLUDE_FILES_PREFIX}/utility.h
  75. ${INCLUDE_FILES_PREFIX}/win32.h
  76. )
  77. set(SOURCE_FILES
  78. callbacks.c
  79. compress.c
  80. host.c
  81. list.c
  82. packet.c
  83. peer.c
  84. protocol.c
  85. unix.c
  86. win32.c)
  87. source_group(include FILES ${INCLUDE_FILES})
  88. source_group(source FILES ${SOURCE_FILES})
  89. if(WIN32 AND BUILD_SHARED_LIBS AND (MSVC OR CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
  90. add_definitions(-DENET_DLL=1)
  91. add_definitions(-DENET_BUILDING_LIB)
  92. endif()
  93. add_library(enet
  94. ${INCLUDE_FILES}
  95. ${SOURCE_FILES}
  96. )
  97. if (WIN32)
  98. target_link_libraries(enet winmm ws2_32)
  99. endif()
  100. include(GNUInstallDirs)
  101. install(TARGETS enet
  102. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  103. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  104. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  105. )
  106. install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/enet
  107. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  108. )