From 63d17483d26a2b25a2aac141c814ffc100d3aafa Mon Sep 17 00:00:00 2001 From: heinrich5991 Date: Sun, 3 Feb 2019 11:00:11 +0100 Subject: [PATCH] Add automatic dependency download to CMake for Windows --- CMakeLists.txt | 24 +++++++++++++++++++++++- bam.lua | 1 - scripts/download.py | 13 +++---------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e3675c618..2a9923318 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,7 @@ if(TARGET_OS STREQUAL "windows") endif() 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(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(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 ######################################################################## @@ -257,7 +280,6 @@ find_package(ZLIB) find_package(Freetype) find_package(Git) find_package(Pnglite) -find_package(PythonInterp) find_package(SDL2) find_package(Threads) find_package(Wavpack) diff --git a/bam.lua b/bam.lua index b35766d4a..42b1846f6 100644 --- a/bam.lua +++ b/bam.lua @@ -378,7 +378,6 @@ function BuildContent(settings, arch, conf) end -- dependencies dl = Python("scripts/download.py") - dl = dl .. " --arch " .. arch .. " --conf " .. conf AddJob("other/sdl/include/SDL.h", "Downloading SDL2", dl .. " sdl") 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")) diff --git a/scripts/download.py b/scripts/download.py index 1943000d2..a7278a135 100644 --- a/scripts/download.py +++ b/scripts/download.py @@ -19,14 +19,9 @@ def unzip(filename, where): z.close() return z.namelist()[0] -def downloadAll(arch, conf, targets): +def downloadAll(targets): 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 src_package_libs = twlib.fetch_file(url) if not src_package_libs: @@ -52,12 +47,10 @@ def downloadAll(arch, conf, targets): def main(): import argparse 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"') args = p.parse_args() - downloadAll(args.arch, args.conf, args.targets) + downloadAll(args.targets) if __name__ == '__main__': main()