CMakeLists.txt 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #
  2. # Copyright (c) 2019 Chris Burns <[email protected]>
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"), to deal
  6. # in the Software without restriction, including without limitation the rights
  7. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. # copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in all
  12. # copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. # SOFTWARE.
  21. #
  22. set(ENET_LIB_NAME enet)
  23. cmake_minimum_required(VERSION 3.1)
  24. project(${ENET_LIB_NAME} LANGUAGES C)
  25. set(ENET_DEBUG OFF CACHE BOOL "Enables debug and trace logging")
  26. set(ENET_PLUGIN_DIR_BASE "${CMAKE_CURRENT_SOURCE_DIR}/Unity/Plugins")
  27. set(ENET_PLUGIN_DIR_ARCH "x86_64")
  28. set(ENET_DEFINES -DENET_NO_PRAGMA_LINK -DENET_DLL)
  29. set(ENET_DEPS "")
  30. set(ENET_SRCDIR "Source/Native")
  31. set(ENET_SRCS
  32. ${ENET_SRCDIR}/enet.c
  33. ${ENET_SRCDIR}/enet.h
  34. ${ENET_SRCDIR}/custom/enet_logging.h
  35. )
  36. if(ENET_DEBUG)
  37. list(APPEND ENET_DEFINES -DENET_DEBUG)
  38. endif()
  39. if(MSVC)
  40. set(CompilerFlags
  41. CMAKE_C_FLAGS
  42. CMAKE_C_FLAGS_RELEASE
  43. CMAKE_C_FLAGS_DEBUG
  44. )
  45. foreach(CompilerFlag ${CompilerFlags})
  46. string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
  47. endforeach()
  48. list(APPEND ENET_DEFINES -D_CRT_SECURE_NO_WARNINGS)
  49. list(APPEND ENET_DEPS Ws2_32 Winmm)
  50. endif()
  51. include_directories(${ENET_SRCDIR})
  52. add_library(${ENET_LIB_NAME} SHARED ${ENET_SRCS})
  53. target_link_libraries(${ENET_LIB_NAME} ${ENET_DEPS})
  54. target_compile_definitions(${ENET_LIB_NAME} PRIVATE ${ENET_DEFINES})
  55. set(ENET_PLUGIN_DIR ${ENET_PLUGIN_DIR_BASE}/${ENET_PLUGIN_DIR_ARCH})
  56. set(ENET_LIB_PREFIX ${CMAKE_SHARED_LIBRARY_PREFIX})
  57. string(REPLACE ".dylib" ".bundle" ENET_LIB_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
  58. set(ENET_PLUGIN_NAME ${ENET_LIB_PREFIX}${ENET_LIB_NAME}${ENET_LIB_SUFFIX})
  59. file(MAKE_DIRECTORY ${ENET_PLUGIN_DIR})
  60. add_custom_command(
  61. TARGET ${ENET_LIB_NAME}
  62. POST_BUILD
  63. COMMAND ${CMAKE_COMMAND} -E copy
  64. $<TARGET_FILE:${ENET_LIB_NAME}>
  65. ${ENET_PLUGIN_DIR}/${ENET_PLUGIN_NAME}
  66. )