Add automatic dependency download to CMake for Windows

This commit is contained in:
heinrich5991 2019-02-03 11:00:11 +01:00
parent 99843b7a70
commit 63d17483d2
3 changed files with 26 additions and 12 deletions

View file

@ -65,6 +65,7 @@ if(TARGET_OS STREQUAL "windows")
endif() endif()
option(CLIENT "Compile client" ON) option(CLIENT "Compile client" ON)
option(DOWNLOAD_DEPENDENCIES "Download dependencies (only available on Windows)" ${AUTO_DEPENDENCIES_DEFAULT})
option(PREFER_BUNDLED_LIBS "Prefer bundled libraries over system libraries" ${AUTO_DEPENDENCIES_DEFAULT}) option(PREFER_BUNDLED_LIBS "Prefer bundled libraries over system libraries" ${AUTO_DEPENDENCIES_DEFAULT})
option(DEV "Don't generate stuff necessary for packaging" OFF) option(DEV "Don't generate stuff necessary for packaging" OFF)
@ -86,6 +87,28 @@ set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
set(SERVER_EXECUTABLE teeworlds_srv CACHE STRING "Name of the built server executable") set(SERVER_EXECUTABLE teeworlds_srv CACHE STRING "Name of the built server executable")
set(CLIENT_EXECUTABLE teeworlds CACHE STRING "Name of the build client executable") set(CLIENT_EXECUTABLE teeworlds CACHE STRING "Name of the build client executable")
########################################################################
# Download dependencies
########################################################################
find_package(PythonInterp)
if(DOWNLOAD_DEPENDENCIES)
if(PYTHON_EXECUTABLE AND TARGET_OS STREQUAL "windows" AND TARGET_BITS)
set(DOWNLOADS)
foreach(d freetype sdl)
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/other/${d}/${TARGET_OS}/lib${TARGET_BITS}")
list(APPEND DOWNLOADS ${d})
endif()
endforeach()
if(DOWNLOADS)
message(STATUS "Downloading Freetype and SDL 2")
execute_process(COMMAND ${PYTHON_EXECUTABLE} scripts/download.py ${DOWNLOADS}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
endif()
endif()
endif()
######################################################################## ########################################################################
# Compiler flags # Compiler flags
######################################################################## ########################################################################
@ -257,7 +280,6 @@ find_package(ZLIB)
find_package(Freetype) find_package(Freetype)
find_package(Git) find_package(Git)
find_package(Pnglite) find_package(Pnglite)
find_package(PythonInterp)
find_package(SDL2) find_package(SDL2)
find_package(Threads) find_package(Threads)
find_package(Wavpack) find_package(Wavpack)

View file

@ -378,7 +378,6 @@ function BuildContent(settings, arch, conf)
end end
-- dependencies -- dependencies
dl = Python("scripts/download.py") dl = Python("scripts/download.py")
dl = dl .. " --arch " .. arch .. " --conf " .. conf
AddJob("other/sdl/include/SDL.h", "Downloading SDL2", dl .. " sdl") AddJob("other/sdl/include/SDL.h", "Downloading SDL2", dl .. " sdl")
AddJob("other/freetype/include/ft2build.h", "Downloading freetype", dl .. " freetype") AddJob("other/freetype/include/ft2build.h", "Downloading freetype", dl .. " freetype")
table.insert(content, CopyFile(settings.link.Output(settings, "") .. "/SDL2.dll", "other/sdl/windows/lib" .. _arch .. "/SDL2.dll")) table.insert(content, CopyFile(settings.link.Output(settings, "") .. "/SDL2.dll", "other/sdl/windows/lib" .. _arch .. "/SDL2.dll"))

View file

@ -19,14 +19,9 @@ def unzip(filename, where):
z.close() z.close()
return z.namelist()[0] return z.namelist()[0]
def downloadAll(arch, conf, targets): def downloadAll(targets):
url = "https://github.com/teeworlds/teeworlds-libs/archive/master.zip" url = "https://github.com/teeworlds/teeworlds-libs/archive/master.zip"
if arch == "x86_64":
_arch = "64"
else:
_arch = "32"
builddir = "build/" + arch + "/" + conf + "/"
# download and unzip # download and unzip
src_package_libs = twlib.fetch_file(url) src_package_libs = twlib.fetch_file(url)
if not src_package_libs: if not src_package_libs:
@ -52,12 +47,10 @@ def downloadAll(arch, conf, targets):
def main(): def main():
import argparse import argparse
p = argparse.ArgumentParser(description="Download freetype and SDL library and header files for Windows.") p = argparse.ArgumentParser(description="Download freetype and SDL library and header files for Windows.")
p.add_argument("--arch", default="x86", choices=["x86", "x86_64"], help="Architecture for the downloaded libraries (Default: x86)")
p.add_argument("--conf", default="debug", choices=["debug", "release"], help="Build type (Default: debug)")
p.add_argument("targets", metavar="TARGET", nargs='+', choices=["sdl", "freetype"], help='Target to download. Valid choices are "sdl" and "freetype"') p.add_argument("targets", metavar="TARGET", nargs='+', choices=["sdl", "freetype"], help='Target to download. Valid choices are "sdl" and "freetype"')
args = p.parse_args() args = p.parse_args()
downloadAll(args.arch, args.conf, args.targets) downloadAll(args.targets)
if __name__ == '__main__': if __name__ == '__main__':
main() main()