BuildLuv.cmake 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # BuildLuv(PATCH_COMMAND ... CONFIGURE_COMMAND ... BUILD_COMMAND ... INSTALL_COMMAND ...)
  2. # Reusable function to build luv, wraps ExternalProject_Add.
  3. # Failing to pass a command argument will result in no command being run
  4. function(BuildLuv)
  5. cmake_parse_arguments(_luv
  6. ""
  7. ""
  8. "PATCH_COMMAND;CONFIGURE_COMMAND;BUILD_COMMAND;INSTALL_COMMAND"
  9. ${ARGN})
  10. if(NOT _luv_CONFIGURE_COMMAND AND NOT _luv_BUILD_COMMAND
  11. AND NOT _luv_INSTALL_COMMAND)
  12. message(FATAL_ERROR "Must pass at least one of CONFIGURE_COMMAND, BUILD_COMMAND, INSTALL_COMMAND")
  13. endif()
  14. ExternalProject_Add(lua-compat-5.3
  15. PREFIX ${DEPS_BUILD_DIR}
  16. URL ${LUA_COMPAT53_URL}
  17. DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/lua-compat-5.3
  18. DOWNLOAD_COMMAND ${CMAKE_COMMAND}
  19. -DPREFIX=${DEPS_BUILD_DIR}
  20. -DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/lua-compat-5.3
  21. -DURL=${LUA_COMPAT53_URL}
  22. -DEXPECTED_SHA256=${LUA_COMPAT53_SHA256}
  23. -DTARGET=lua-compat-5.3
  24. -DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR}
  25. -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake
  26. PATCH_COMMAND ""
  27. CONFIGURE_COMMAND ""
  28. BUILD_COMMAND ""
  29. INSTALL_COMMAND "")
  30. ExternalProject_Add(luv-static
  31. PREFIX ${DEPS_BUILD_DIR}
  32. DEPENDS lua-compat-5.3
  33. URL ${LUV_URL}
  34. DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/luv
  35. DOWNLOAD_COMMAND ${CMAKE_COMMAND}
  36. -DPREFIX=${DEPS_BUILD_DIR}
  37. -DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/luv
  38. -DURL=${LUV_URL}
  39. -DEXPECTED_SHA256=${LUV_SHA256}
  40. -DTARGET=luv-static
  41. # The source is shared with BuildLuarocks (with USE_BUNDLED_LUV).
  42. -DSRC_DIR=${DEPS_BUILD_DIR}/src/luv
  43. -DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR}
  44. -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake
  45. PATCH_COMMAND "${_luv_PATCH_COMMAND}"
  46. CONFIGURE_COMMAND "${_luv_CONFIGURE_COMMAND}"
  47. BUILD_COMMAND "${_luv_BUILD_COMMAND}"
  48. INSTALL_COMMAND "${_luv_INSTALL_COMMAND}"
  49. LIST_SEPARATOR |)
  50. endfunction()
  51. set(LUV_SRC_DIR ${DEPS_BUILD_DIR}/src/luv)
  52. set(LUV_INCLUDE_FLAGS
  53. "-I${DEPS_INSTALL_DIR}/include -I${DEPS_INSTALL_DIR}/include/luajit-2.1")
  54. # Replace luv default rockspec with the alternate one under the "rockspecs"
  55. # directory
  56. set(LUV_PATCH_COMMAND
  57. ${CMAKE_COMMAND} -E copy_directory ${LUV_SRC_DIR}/rockspecs ${LUV_SRC_DIR})
  58. set(LUV_CONFIGURE_COMMAND_COMMON
  59. ${CMAKE_COMMAND} ${LUV_SRC_DIR}
  60. -DCMAKE_GENERATOR=${CMAKE_GENERATOR}
  61. -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
  62. -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR}
  63. -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES_ALT_SEP}
  64. -DLUA_BUILD_TYPE=System
  65. -DLUA_COMPAT53_DIR=${DEPS_BUILD_DIR}/src/lua-compat-5.3
  66. -DWITH_SHARED_LIBUV=ON
  67. -DBUILD_SHARED_LIBS=OFF
  68. -DBUILD_STATIC_LIBS=ON
  69. -DBUILD_MODULE=OFF)
  70. if(USE_BUNDLED_LUAJIT)
  71. list(APPEND LUV_CONFIGURE_COMMAND_COMMON -DWITH_LUA_ENGINE=LuaJit)
  72. elseif(USE_BUNDLED_LUA)
  73. list(APPEND LUV_CONFIGURE_COMMAND_COMMON -DWITH_LUA_ENGINE=Lua)
  74. else()
  75. find_package(LuaJit)
  76. if(LUAJIT_FOUND)
  77. list(APPEND LUV_CONFIGURE_COMMAND_COMMON -DWITH_LUA_ENGINE=LuaJit)
  78. else()
  79. list(APPEND LUV_CONFIGURE_COMMAND_COMMON -DWITH_LUA_ENGINE=Lua)
  80. endif()
  81. endif()
  82. if(USE_BUNDLED_LIBUV)
  83. set(LUV_CONFIGURE_COMMAND_COMMON
  84. ${LUV_CONFIGURE_COMMAND_COMMON}
  85. -DCMAKE_PREFIX_PATH=${DEPS_INSTALL_DIR})
  86. endif()
  87. if(MSVC)
  88. set(LUV_CONFIGURE_COMMAND
  89. ${LUV_CONFIGURE_COMMAND_COMMON}
  90. -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
  91. -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
  92. # Same as Unix without fPIC
  93. "-DCMAKE_C_FLAGS:STRING=${CMAKE_C_COMPILER_ARG1} ${LUV_INCLUDE_FLAGS}"
  94. # Make sure we use the same generator, otherwise we may
  95. # accidentally end up using different MSVC runtimes
  96. -DCMAKE_GENERATOR=${CMAKE_GENERATOR})
  97. else()
  98. set(LUV_CONFIGURE_COMMAND
  99. ${LUV_CONFIGURE_COMMAND_COMMON}
  100. -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
  101. "-DCMAKE_C_FLAGS:STRING=${CMAKE_C_COMPILER_ARG1} ${LUV_INCLUDE_FLAGS} -fPIC")
  102. if(CMAKE_GENERATOR MATCHES "Unix Makefiles" AND
  103. (CMAKE_SYSTEM_NAME MATCHES ".*BSD" OR CMAKE_SYSTEM_NAME MATCHES "DragonFly"))
  104. set(LUV_CONFIGURE_COMMAND ${LUV_CONFIGURE_COMMAND} -DCMAKE_MAKE_PROGRAM=gmake)
  105. endif()
  106. endif()
  107. set(LUV_BUILD_COMMAND
  108. ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE})
  109. set(LUV_INSTALL_COMMAND
  110. ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE})
  111. BuildLuv(PATCH_COMMAND ${LUV_PATCH_COMMAND}
  112. CONFIGURE_COMMAND ${LUV_CONFIGURE_COMMAND}
  113. BUILD_COMMAND ${LUV_BUILD_COMMAND}
  114. INSTALL_COMMAND ${LUV_INSTALL_COMMAND})
  115. list(APPEND THIRD_PARTY_DEPS luv-static)
  116. if(USE_BUNDLED_LUAJIT)
  117. add_dependencies(luv-static luajit)
  118. endif()
  119. if(USE_BUNDLED_LIBUV)
  120. add_dependencies(luv-static libuv)
  121. endif()