2016-04-10 19:49:23 -07:00
|
|
|
include(CMakeParseArguments)
|
|
|
|
|
|
|
|
# BuildLuv(PATCH_COMMAND ... CONFIGURE_COMMAND ... BUILD_COMMAND ... INSTALL_COMMAND ...)
|
|
|
|
# Reusable function to build luv, wraps ExternalProject_Add.
|
|
|
|
# Failing to pass a command argument will result in no command being run
|
|
|
|
function(BuildLuv)
|
|
|
|
cmake_parse_arguments(_luv
|
|
|
|
""
|
|
|
|
""
|
|
|
|
"PATCH_COMMAND;CONFIGURE_COMMAND;BUILD_COMMAND;INSTALL_COMMAND"
|
|
|
|
${ARGN})
|
|
|
|
|
|
|
|
if(NOT _luv_CONFIGURE_COMMAND AND NOT _luv_BUILD_COMMAND
|
|
|
|
AND NOT _luv_INSTALL_COMMAND)
|
|
|
|
message(FATAL_ERROR "Must pass at least one of CONFIGURE_COMMAND, BUILD_COMMAND, INSTALL_COMMAND")
|
|
|
|
endif()
|
|
|
|
|
2019-06-10 05:13:18 -07:00
|
|
|
ExternalProject_Add(lua-compat-5.3
|
|
|
|
PREFIX ${DEPS_BUILD_DIR}
|
|
|
|
URL ${LUA_COMPAT53_URL}
|
|
|
|
DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/lua-compat-5.3
|
|
|
|
DOWNLOAD_COMMAND ${CMAKE_COMMAND}
|
|
|
|
-DPREFIX=${DEPS_BUILD_DIR}
|
|
|
|
-DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/lua-compat-5.3
|
|
|
|
-DURL=${LUA_COMPAT53_URL}
|
|
|
|
-DEXPECTED_SHA256=${LUA_COMPAT53_SHA256}
|
|
|
|
-DTARGET=lua-compat-5.3
|
|
|
|
-DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR}
|
|
|
|
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake
|
|
|
|
PATCH_COMMAND ""
|
|
|
|
CONFIGURE_COMMAND ""
|
|
|
|
BUILD_COMMAND ""
|
|
|
|
INSTALL_COMMAND "")
|
|
|
|
|
2016-04-10 19:49:23 -07:00
|
|
|
ExternalProject_Add(luv-static
|
|
|
|
PREFIX ${DEPS_BUILD_DIR}
|
2019-06-10 05:13:18 -07:00
|
|
|
DEPENDS lua-compat-5.3
|
2016-04-10 19:49:23 -07:00
|
|
|
URL ${LUV_URL}
|
|
|
|
DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/luv
|
|
|
|
DOWNLOAD_COMMAND ${CMAKE_COMMAND}
|
|
|
|
-DPREFIX=${DEPS_BUILD_DIR}
|
|
|
|
-DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/luv
|
|
|
|
-DURL=${LUV_URL}
|
|
|
|
-DEXPECTED_SHA256=${LUV_SHA256}
|
2019-07-03 17:37:29 -07:00
|
|
|
-DTARGET=luv-static
|
|
|
|
# The source is shared with BuildLuarocks (with USE_BUNDLED_LUV).
|
|
|
|
-DSRC_DIR=${DEPS_BUILD_DIR}/src/luv
|
2016-04-10 19:49:23 -07:00
|
|
|
-DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR}
|
|
|
|
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake
|
|
|
|
PATCH_COMMAND "${_luv_PATCH_COMMAND}"
|
|
|
|
CONFIGURE_COMMAND "${_luv_CONFIGURE_COMMAND}"
|
|
|
|
BUILD_COMMAND "${_luv_BUILD_COMMAND}"
|
|
|
|
INSTALL_COMMAND "${_luv_INSTALL_COMMAND}")
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
set(LUV_SRC_DIR ${DEPS_BUILD_DIR}/src/luv)
|
|
|
|
set(LUV_INCLUDE_FLAGS
|
2019-09-30 03:50:22 -07:00
|
|
|
"-I${DEPS_INSTALL_DIR}/include -I${DEPS_INSTALL_DIR}/include/luajit-2.1")
|
2016-04-10 19:49:23 -07:00
|
|
|
|
2018-04-01 18:32:22 -07:00
|
|
|
# Replace luv default rockspec with the alternate one under the "rockspecs"
|
|
|
|
# directory
|
2016-04-10 19:49:23 -07:00
|
|
|
set(LUV_PATCH_COMMAND
|
2018-04-01 18:32:22 -07:00
|
|
|
${CMAKE_COMMAND} -E copy_directory ${LUV_SRC_DIR}/rockspecs ${LUV_SRC_DIR})
|
2016-04-10 19:49:23 -07:00
|
|
|
|
|
|
|
set(LUV_CONFIGURE_COMMAND_COMMON
|
|
|
|
${CMAKE_COMMAND} ${LUV_SRC_DIR}
|
2016-05-26 12:45:33 -07:00
|
|
|
-DCMAKE_GENERATOR=${CMAKE_GENERATOR}
|
2016-04-10 19:49:23 -07:00
|
|
|
-DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR}
|
|
|
|
-DLUA_BUILD_TYPE=System
|
|
|
|
-DWITH_SHARED_LIBUV=ON
|
|
|
|
-DBUILD_SHARED_LIBS=OFF
|
|
|
|
-DBUILD_MODULE=OFF)
|
|
|
|
|
2019-07-09 12:55:01 -07:00
|
|
|
if(USE_BUNDLED_LUAJIT)
|
|
|
|
list(APPEND LUV_CONFIGURE_COMMAND_COMMON -DWITH_LUA_ENGINE=LuaJit)
|
|
|
|
elseif(USE_BUNDLED_LUA)
|
|
|
|
list(APPEND LUV_CONFIGURE_COMMAND_COMMON -DWITH_LUA_ENGINE=Lua)
|
|
|
|
else()
|
|
|
|
find_package(LuaJit)
|
|
|
|
if(LUAJIT_FOUND)
|
|
|
|
list(APPEND LUV_CONFIGURE_COMMAND_COMMON -DWITH_LUA_ENGINE=LuaJit)
|
|
|
|
else()
|
|
|
|
list(APPEND LUV_CONFIGURE_COMMAND_COMMON -DWITH_LUA_ENGINE=Lua)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2018-05-27 02:16:29 -07:00
|
|
|
if(USE_BUNDLED_LIBUV)
|
|
|
|
set(LUV_CONFIGURE_COMMAND_COMMON
|
|
|
|
${LUV_CONFIGURE_COMMAND_COMMON}
|
|
|
|
-DCMAKE_PREFIX_PATH=${DEPS_INSTALL_DIR})
|
|
|
|
endif()
|
|
|
|
|
2016-04-10 19:49:23 -07:00
|
|
|
if(MINGW AND CMAKE_CROSSCOMPILING)
|
|
|
|
get_filename_component(TOOLCHAIN ${CMAKE_TOOLCHAIN_FILE} REALPATH)
|
|
|
|
set(LUV_CONFIGURE_COMMAND
|
|
|
|
${LUV_CONFIGURE_COMMAND_COMMON}
|
|
|
|
# Pass toolchain
|
|
|
|
-DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN}
|
|
|
|
"-DCMAKE_C_FLAGS:STRING=${LUV_INCLUDE_FLAGS} -D_WIN32_WINNT=0x0600"
|
|
|
|
# Hack to avoid -rdynamic in Mingw
|
|
|
|
-DCMAKE_SHARED_LIBRARY_LINK_C_FLAGS="")
|
|
|
|
elseif(MSVC)
|
|
|
|
set(LUV_CONFIGURE_COMMAND
|
|
|
|
${LUV_CONFIGURE_COMMAND_COMMON}
|
|
|
|
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
|
|
|
|
# Same as Unix without fPIC
|
|
|
|
"-DCMAKE_C_FLAGS:STRING=${CMAKE_C_COMPILER_ARG1} ${LUV_INCLUDE_FLAGS}"
|
|
|
|
# Make sure we use the same generator, otherwise we may
|
|
|
|
# accidentaly end up using different MSVC runtimes
|
|
|
|
-DCMAKE_GENERATOR=${CMAKE_GENERATOR}
|
|
|
|
# Use static runtime
|
|
|
|
-DCMAKE_C_FLAGS_DEBUG="-MTd"
|
|
|
|
-DCMAKE_C_FLAGS_RELEASE="-MT")
|
|
|
|
else()
|
|
|
|
set(LUV_CONFIGURE_COMMAND
|
|
|
|
${LUV_CONFIGURE_COMMAND_COMMON}
|
|
|
|
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
|
|
|
|
"-DCMAKE_C_FLAGS:STRING=${CMAKE_C_COMPILER_ARG1} ${LUV_INCLUDE_FLAGS} -fPIC")
|
|
|
|
endif()
|
|
|
|
|
2018-04-12 03:51:38 -07:00
|
|
|
if(CMAKE_GENERATOR MATCHES "Unix Makefiles" AND
|
|
|
|
(CMAKE_SYSTEM_NAME MATCHES ".*BSD" OR CMAKE_SYSTEM_NAME MATCHES "DragonFly"))
|
2019-06-10 05:13:18 -07:00
|
|
|
set(LUV_BUILD_COMMAND ${CMAKE_COMMAND}
|
|
|
|
"-DLUA_COMPAT53_DIR=${DEPS_BUILD_DIR}/src/lua-compat-5.3"
|
|
|
|
"-DCMAKE_MAKE_PROGRAM=gmake" --build .)
|
2018-04-07 07:10:01 -07:00
|
|
|
else()
|
2019-06-10 05:13:18 -07:00
|
|
|
set(LUV_BUILD_COMMAND ${CMAKE_COMMAND}
|
|
|
|
"-DLUA_COMPAT53_DIR=${DEPS_BUILD_DIR}/src/lua-compat-5.3" --build .)
|
2018-04-07 07:10:01 -07:00
|
|
|
endif()
|
2016-04-10 19:49:23 -07:00
|
|
|
set(LUV_INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install)
|
|
|
|
|
|
|
|
BuildLuv(PATCH_COMMAND ${LUV_PATCH_COMMAND}
|
|
|
|
CONFIGURE_COMMAND ${LUV_CONFIGURE_COMMAND}
|
|
|
|
BUILD_COMMAND ${LUV_BUILD_COMMAND}
|
|
|
|
INSTALL_COMMAND ${LUV_INSTALL_COMMAND})
|
|
|
|
|
|
|
|
list(APPEND THIRD_PARTY_DEPS luv-static)
|
2017-03-25 16:22:15 -07:00
|
|
|
if(USE_BUNDLED_LUAJIT)
|
|
|
|
add_dependencies(luv-static luajit)
|
|
|
|
endif()
|
|
|
|
if(USE_BUNDLED_LIBUV)
|
|
|
|
add_dependencies(luv-static libuv)
|
|
|
|
endif()
|