From d2ce892e68535d56880d45a06653d2e9a1fceab4 Mon Sep 17 00:00:00 2001 From: KaiN Date: Tue, 22 May 2018 09:43:36 +0200 Subject: [PATCH 01/24] Porting stuff from platform-windows branch --- platforms/common/glfwApp.cpp | 12 +++ platforms/common/platform_gl.h | 11 ++- platforms/windows/README.md | 110 ++++++++++++++++++++++ platforms/windows/src/main.cpp | 38 ++++++++ platforms/windows/src/windowsPlatform.cpp | 66 +++++++++++++ platforms/windows/src/windowsPlatform.h | 26 +++++ toolchains/windows.cmake | 97 +++++++++++++++++++ 7 files changed, 358 insertions(+), 2 deletions(-) create mode 100644 platforms/windows/README.md create mode 100644 platforms/windows/src/main.cpp create mode 100644 platforms/windows/src/windowsPlatform.cpp create mode 100644 platforms/windows/src/windowsPlatform.h create mode 100644 toolchains/windows.cmake diff --git a/platforms/common/glfwApp.cpp b/platforms/common/glfwApp.cpp index 94470c08ec..37004b0e8a 100644 --- a/platforms/common/glfwApp.cpp +++ b/platforms/common/glfwApp.cpp @@ -1,8 +1,16 @@ #include "glfwApp.h" + #include "imgui.h" #include "imgui_impl_glfw.h" #include "imgui_impl_opengl3.h" #include "imgui_stl.h" +#include "debug/textDisplay.h" + +#ifdef TANGRAM_WINDOWS +#define GLFW_INCLUDE_NONE +#include +#endif // TANGRAM_WINDOWS + #define GLFW_INCLUDE_GLEXT #include #include @@ -181,6 +189,10 @@ void create(std::unique_ptr p, int w, int h) { glfwMakeContextCurrent(main_window); glfwSwapInterval(1); // Enable vsync +#ifdef _WIN32 + gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); +#endif + // Set input callbacks glfwSetFramebufferSizeCallback(main_window, framebufferResizeCallback); glfwSetMouseButtonCallback(main_window, mouseButtonCallback); diff --git a/platforms/common/platform_gl.h b/platforms/common/platform_gl.h index 9c62f40da7..70e7f90a92 100644 --- a/platforms/common/platform_gl.h +++ b/platforms/common/platform_gl.h @@ -38,10 +38,17 @@ extern PFNGLGENVERTEXARRAYSOESPROC glGenVertexArraysOESEXT; #define glBindVertexArray glBindVertexArrayAPPLE #endif // TANGRAM_OSX -#ifdef TANGRAM_LINUX +#if defined(TANGRAM_LINUX) || defined(TANGRAM_WINDOWS) #define GL_GLEXT_PROTOTYPES +#ifdef TANGRAM_WINDOWS +#define GLFW_INCLUDE_NONE +#include +// Add missing stuff +#define glDepthRangef(a, b) glDepthRange((double)(a), (double)(b)) +#define glClearDepthf(a) glClearDepth((double)(a)) +#endif // TANGRAM_WINDOWS #include -#endif // TANGRAM_LINUX +#endif // defined(TANGRAM_LINUX) || defined(TANGRAM_WINDOWS) #ifdef TANGRAM_RPI // Broadcom library for direct GPU access diff --git a/platforms/windows/README.md b/platforms/windows/README.md new file mode 100644 index 0000000000..30a61bc18c --- /dev/null +++ b/platforms/windows/README.md @@ -0,0 +1,110 @@ +Ubuntu or Debian Linux +====================== + +## Setup ## + +This project uses CMake (minimum version 3.0), you can download it [here](http://www.cmake.org/download/). + +Make sure to update git submodules before you build: + +```bash +git submodule update --init +``` + +Currently, builds were tested under MinGW-w64 (recommended). You will need to install/build zlib and curl. + +The demo application uses the Nextzen vector tile service, so you will need a Nextzen API key to build and run the demo. + + 1. Visit https://developers.nextzen.org/ to get an API key. + + 2. Setup an environment variable (`NEXTZEN_API_KEY`) to point to your API key. + ```bash + export NEXTZEN_API_KEY=YOUR_API_KEY + ``` + +## Build ## + + 1. Download zlib sources from https://zlib.net/ + + 2. Download curl sources fom https://curl.haxx.se/download.html + +### Zlib and Curl under MinGW-w64 + +- CMake typically installs everything under Program Files, which is unfortunate + because it needs elevated privileges and also bloats dir quickly. I strongly + encourage you to make dedicated directory, e.g. `c:/prg/cmake_install`. + To make it work, set `CMAKE_PREFIX_PATH` env var to this directory. + If `echo %CMAKE_PREFIX_PATH%` doesn't reflect changes, you must restart + command prompt or log out and log in to Windows. +- Using latest curl & zlib source packages is usually the best idea. + +``` bat +cd /d C:\path\to\zlib-1.2.11 +mkdir build && cd build +cmake .. -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=c:/prg/cmake_install +mingw32-make +mingw32-make install +``` + +``` bat +cd /d C:\path\to\curl-7.60.0 +mkdir build && cd build +cmake .. -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=c:/prg/cmake_install -DCMAKE_USE_WINSSL=ON +mingw32-make +mingw32-make install +``` + +### MinGW ### + +- Create directory build/windows under tangram-es root directory. +- Enter command prompt and go to newly created directory. +- Setup CMake, forcing MinGW toolchain: `cmake ../.. -G "MinGW Makefiles"` +- Run build via make: `mingw32-make` + +You can optionally use `mingw32-make -j#` to parallelize the build +and append `DEBUG=1` or `RELEASE=1` to choose the build type. + +### Clang ### + +** Last time I've checked Clang wasn't able to build tangram-es because of some +kind of MSVC quirks compatibility. Proceed at your own risk.** + +You need to have MS Build tools installed. + +`cmake -DCMAKE_C_COMPILER=clang-cl.exe -DCMAKE_CXX_COMPILER=clang-cl.exe -DCMAKE_BUILD_TYPE=Release -G "NMake Makefiles" ../..` + +D:\prg\_git\tangram-es\core\deps\harfbuzz-icu-freetype\icu\common\ucnv2022.cpp(751,9): error: ISO C++17 does not allow + 'register' storage class specifier [-Wregister] + +### MSVC ### + +** Last time I've checked MSVC wasn't able to build tangram-es. +Proceed at your own risk.** + +You need to have MS Build tools installed. + +- Launch Visual C++ 2015 x86 Native Build Tools Command Prompt +- Enter zlib directory and run ```nmake -f win32/Makefile.msc``` +- Enter /winbuild and run nmake /f Makefile.vc mode= +- For static builds, go to + `\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\lib` + and change `libcurl_a.lib` to `libcurl.lib` +- Setup local variable `CMAKE_PREFIX_PATH` so that it includes + `\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl` + and ``. If `echo %CMAKE_PREFIX_PATH%` doesn't reflect changes, + you must restart command prompt or log out and log in to Windows. +- Create directory build/windows under tangram-es root directory. +- Enter command prompt and go to newly created directory. +- Setup CMake: `cmake ../.. -G "NMake Makefiles"` +- Run build via nmake: `nmake` + +## Running app ## + +App should now reside in `build/windows/bin directory`. +If you built curl/zlib as dynamic libraries, you'll have to supply zlib.dll +and curl.dll into same directory as .exe file. + +You can open a different YAML scene file by dragging and dropping it into the +window, or passing it as an argument: + +`tangram -f /path/to/your/scene.yaml` diff --git a/platforms/windows/src/main.cpp b/platforms/windows/src/main.cpp new file mode 100644 index 0000000000..8750207924 --- /dev/null +++ b/platforms/windows/src/main.cpp @@ -0,0 +1,38 @@ +#include "glfwApp.h" +#include "windowsPlatform.h" +#include "log.h" +#include "map.h" +#include +#include +#include +#include // _getcwd + +using namespace Tangram; + +int main(int argc, char* argv[]) { + + auto platform = std::make_shared(); + + // Create the windowed app. + GlfwApp::create(platform, 1024, 768); + GlfwApp::parseArgs(argc, argv); + + // Resolve the input path against the current directory. + Url baseUrl("file:///"); + char pathBuffer[PATH_MAX] = {0}; + if (_getcwd(pathBuffer, PATH_MAX) != nullptr) { + baseUrl = Url("file://" + std::string(pathBuffer)).resolved(baseUrl); + } + + LOG("Base URL: %s", baseUrl.string().c_str()); + + Url sceneUrl = Url(GlfwApp::sceneFile).resolved(baseUrl); + GlfwApp::sceneFile = sceneUrl.string(); + + // Loop until the user closes the window + GlfwApp::run(); + + // Clean up. + GlfwApp::destroy(); + +} diff --git a/platforms/windows/src/windowsPlatform.cpp b/platforms/windows/src/windowsPlatform.cpp new file mode 100644 index 0000000000..85007e4915 --- /dev/null +++ b/platforms/windows/src/windowsPlatform.cpp @@ -0,0 +1,66 @@ +#include "windowsPlatform.h" +#include "gl/hardware.h" +#include "log.h" +#include +#include +#include +#include + +#include + +#define DEFAULT "fonts/NotoSans-Regular.ttf" +#define FONT_AR "fonts/NotoNaskh-Regular.ttf" +#define FONT_HE "fonts/NotoSansHebrew-Regular.ttf" +#define FONT_JA "fonts/DroidSansJapanese.ttf" +#define FALLBACK "fonts/DroidSansFallback.ttf" + +namespace Tangram { + +void logMsg(const char* fmt, ...) { + va_list args; + va_start(args, fmt); + vfprintf(stderr, fmt, args); + va_end(args); +} + +WindowsPlatform::WindowsPlatform() : + m_urlClient(UrlClient::Options{}) {} + +WindowsPlatform::WindowsPlatform(UrlClient::Options urlClientOptions) : + m_urlClient(urlClientOptions) {} + +void WindowsPlatform::requestRender() const { + glfwPostEmptyEvent(); +} + +std::vector WindowsPlatform::systemFontFallbacksHandle() const { + std::vector handles; + + handles.emplace_back(Url(DEFAULT)); + handles.emplace_back(Url(FONT_AR)); + handles.emplace_back(Url(FONT_HE)); + handles.emplace_back(Url(FONT_JA)); + handles.emplace_back(Url(FALLBACK)); + + return handles; +} + +UrlRequestHandle WindowsPlatform::startUrlRequest(Url _url, UrlCallback _callback) { + return m_urlClient.addRequest(_url.string(), _callback); +} + +void WindowsPlatform::cancelUrlRequest(UrlRequestHandle _request) { + m_urlClient.cancelRequest(_request); +} + +WindowsPlatform::~WindowsPlatform() {} + +void setCurrentThreadPriority(int priority) { + // No-op +} + +void initGLExtensions() { + Tangram::Hardware::supportsMapBuffer = true; +} + +} // namespace Tangram diff --git a/platforms/windows/src/windowsPlatform.h b/platforms/windows/src/windowsPlatform.h new file mode 100644 index 0000000000..6796f3d333 --- /dev/null +++ b/platforms/windows/src/windowsPlatform.h @@ -0,0 +1,26 @@ +#pragma once + +#include "platform.h" +#include "urlClient.h" + +namespace Tangram { + +class WindowsPlatform : public Platform { + +public: + + WindowsPlatform(); + WindowsPlatform(UrlClient::Options urlClientOptions); + ~WindowsPlatform() override; + void requestRender() const override; + std::vector systemFontFallbacksHandle() const override; + UrlRequestHandle startUrlRequest(Url _url, UrlCallback _callback) override; + void cancelUrlRequest(UrlRequestHandle _request) override; + +protected: + + UrlClient m_urlClient; + +}; + +} // namespace Tangram diff --git a/toolchains/windows.cmake b/toolchains/windows.cmake new file mode 100644 index 0000000000..1eeb96e40b --- /dev/null +++ b/toolchains/windows.cmake @@ -0,0 +1,97 @@ +# global compile options +if(MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -std=gnu++1y") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DRAPIDJSON_HAS_CXX11_RVALUE_REFS=1") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") # Exceptions handler - required for yaml-cpp + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_USE_MATH_DEFINES") # required for geojson-vt-cpp +else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++1y") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wignored-qualifiers -Wtype-limits -Wmissing-field-initializers") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fstack-protector -static") + + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # Clang may be also used in MSVC-Clang toolchain and that will pass match above, + # But then clang works in clang-cl mode which emulates cl.exe and accepts MSVC args, not GNU-like + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gnu-zero-variadic-macro-arguments") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lc++ -lc++abi") + endif() +endif() + +if (CMAKE_COMPILER_IS_GNUCC) + execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion + OUTPUT_VARIABLE GCC_VERSION) + string(REGEX MATCHALL "[0-9]+" GCC_VERSION_COMPONENTS ${GCC_VERSION}) + list(GET GCC_VERSION_COMPONENTS 0 GCC_MAJOR) + list(GET GCC_VERSION_COMPONENTS 1 GCC_MINOR) + + message(STATUS "Using gcc ${GCC_VERSION}") + if (GCC_VERSION VERSION_GREATER 5.1) + message(STATUS "USE CXX11_ABI") + add_definitions("-D_GLIBCXX_USE_CXX11_ABI=1") + endif() +endif() + +check_unsupported_compiler_version() + +add_definitions(-DTANGRAM_WINDOWS) + +# load core library +add_subdirectory(${PROJECT_SOURCE_DIR}/core) + +if(TANGRAM_APPLICATION) + + set(EXECUTABLE_NAME "tangram") + + get_nextzen_api_key(NEXTZEN_API_KEY) + add_definitions(-DNEXTZEN_API_KEY="${NEXTZEN_API_KEY}") + + if($ENV{CIRCLE_BUILD_NUM}) + add_definitions(-DBUILD_NUM_STRING="\($ENV{CIRCLE_BUILD_NUM}\)") + endif() + + find_package(OpenGL REQUIRED) + find_package(CURL REQUIRED) + + # Build GLFW. + if (TANGRAM_USE_SYSTEM_GLFW_LIBS) + include(FindPkgConfig) + pkg_check_modules(GLFW REQUIRED glfw3) + else() + # configure GLFW to build only the library + set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "Build the GLFW example programs") + set(GLFW_BUILD_TESTS OFF CACHE BOOL "Build the GLFW test programs") + set(GLFW_BUILD_DOCS OFF CACHE BOOL "Build the GLFW documentation") + set(GLFW_INSTALL OFF CACHE BOOL "Generate installation target") + add_subdirectory(${PROJECT_SOURCE_DIR}/platforms/common/glfw) + endif() + + add_executable(${EXECUTABLE_NAME} + ${PROJECT_SOURCE_DIR}/platforms/windows/src/windowsPlatform.cpp + ${PROJECT_SOURCE_DIR}/platforms/windows/src/main.cpp + ${PROJECT_SOURCE_DIR}/platforms/common/platform_gl.cpp + ${PROJECT_SOURCE_DIR}/platforms/common/urlClient.cpp + ${PROJECT_SOURCE_DIR}/platforms/common/glfwApp.cpp + ${PROJECT_SOURCE_DIR}/platforms/common/glad.c + ) + + target_include_directories(${EXECUTABLE_NAME} + PUBLIC + ${GLFW_SOURCE_DIR}/include + ${PROJECT_SOURCE_DIR}/platforms/common + ${CURL_INCLUDE_DIRS} + ) + + target_link_libraries(${EXECUTABLE_NAME} + ${CORE_LIBRARY} + glfw + # only used when not using external lib + -pthread + ${GLFW_LIBRARIES} + ${OPENGL_LIBRARIES} + ${CURL_LIBRARIES} + ) + + add_resources(${EXECUTABLE_NAME} "${PROJECT_SOURCE_DIR}/scenes") + +endif() From a915a8620d6c4815216bcf858edbb2dad148f994 Mon Sep 17 00:00:00 2001 From: KaiN Date: Tue, 22 May 2018 15:41:34 +0200 Subject: [PATCH 02/24] Fixed SSL timeouts --- platforms/common/urlClient.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/platforms/common/urlClient.cpp b/platforms/common/urlClient.cpp index 07132dfd9c..7c542fadda 100644 --- a/platforms/common/urlClient.cpp +++ b/platforms/common/urlClient.cpp @@ -63,6 +63,10 @@ struct UrlClient::Task { curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(handle, CURLOPT_MAXREDIRS, 20); curl_easy_setopt(handle, CURLOPT_TCP_NODELAY, 1); +#ifdef TANGRAM_WINDOWS + curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); +#endif } void setup() { From f30d68edfa9da14310d73e7a5529fd0ea6592e21 Mon Sep 17 00:00:00 2001 From: KaiN Date: Tue, 5 Jun 2018 09:13:24 +0200 Subject: [PATCH 03/24] Windows support for main makefile --- Makefile | 60 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 91463097b4..8d4b852cf0 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,12 @@ +# Multiplatform stuff +ifdef ComSpec + # Windows shell + RMPATH = rmdir /S /Q +else + # Civilized rest of the world + RMPATH = rm -rf +endif + all: android osx ios .PHONY: clean @@ -7,6 +16,7 @@ all: android osx ios .PHONY: clean-ios .PHONY: clean-rpi .PHONY: clean-linux +.PHONY: clean-windows .PHONY: clean-benchmark .PHONY: clean-shaders .PHONY: clean-tizen-arm @@ -21,6 +31,7 @@ all: android osx ios .PHONY: ios-docs .PHONY: rpi .PHONY: linux +.PHONY: windows .PHONY: benchmark .PHONY: tests .PHONY: cmake-osx @@ -36,6 +47,7 @@ IOS_BUILD_DIR = build/ios IOS_DOCS_BUILD_DIR = build/ios-docs RPI_BUILD_DIR = build/rpi LINUX_BUILD_DIR = build/linux +WINDOWS_BUILD_DIR = build\windows TESTS_BUILD_DIR = build/tests BENCH_BUILD_DIR = build/bench TIZEN_ARM_BUILD_DIR = build/tizen-arm @@ -99,6 +111,13 @@ LINUX_CMAKE_PARAMS = \ -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE \ ${CMAKE_OPTIONS} +WINDOWS_CMAKE_PARAMS = \ + -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ + -DPLATFORM_TARGET=windows \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE \ + -G "MinGW Makefiles"\ + ${CMAKE_OPTIONS} + ifndef TIZEN_PROFILE TIZEN_PROFILE=mobile endif @@ -127,44 +146,47 @@ TIZEN_X86_CMAKE_PARAMS = \ -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE \ ${CMAKE_OPTIONS} -clean: clean-android clean-osx clean-ios clean-rpi clean-tests clean-xcode clean-linux clean-shaders \ - clean-tizen-arm clean-tizen-x86 +clean: clean-android clean-osx clean-ios clean-rpi clean-tests clean-xcode \ + clean-linux clean-windows clean-shaders clean-tizen-arm clean-tizen-x86 clean-android: - rm -rf platforms/android/build - rm -rf platforms/android/tangram/build - rm -rf platforms/android/tangram/.externalNativeBuild - rm -rf platforms/android/demo/build + ${RMPATH} platforms/android/build + ${RMPATH} platforms/android/tangram/build + ${RMPATH} platforms/android/tangram/.externalNativeBuild + ${RMPATH} platforms/android/demo/build clean-osx: - rm -rf ${OSX_BUILD_DIR} + ${RMPATH} ${OSX_BUILD_DIR} clean-ios: - rm -rf ${IOS_BUILD_DIR} + ${RMPATH} ${IOS_BUILD_DIR} clean-rpi: - rm -rf ${RPI_BUILD_DIR} + ${RMPATH} ${RPI_BUILD_DIR} clean-linux: - rm -rf ${LINUX_BUILD_DIR} + ${RMPATH} ${LINUX_BUILD_DIR} + +clean-windows: + ${RMPATH} ${WINDOWS_BUILD_DIR} clean-xcode: - rm -rf ${OSX_XCODE_BUILD_DIR} + ${RMPATH} ${OSX_XCODE_BUILD_DIR} clean-tests: - rm -rf ${TESTS_BUILD_DIR} + ${RMPATH} ${TESTS_BUILD_DIR} clean-benchmark: - rm -rf ${BENCH_BUILD_DIR} + ${RMPATH} ${BENCH_BUILD_DIR} clean-shaders: - rm -rf core/generated/*.h + ${RMPATH} core/generated/*.h clean-tizen-arm: - rm -rf ${TIZEN_ARM_BUILD_DIR} + ${RMPATH} ${TIZEN_ARM_BUILD_DIR} clean-tizen-x86: - rm -rf ${TIZEN_X86_BUILD_DIR} + ${RMPATH} ${TIZEN_X86_BUILD_DIR} android: android-demo @echo "run: 'adb install -r platforms/android/demo/build/outputs/apk/debug/demo-debug.apk'" @@ -256,6 +278,12 @@ linux: cmake-linux cmake-linux: cmake -H. -B${LINUX_BUILD_DIR} ${LINUX_CMAKE_PARAMS} +windows: cmake-windows + cmake --build ${WINDOWS_BUILD_DIR} + +cmake-windows: + cmake -H. -B${WINDOWS_BUILD_DIR} ${WINDOWS_CMAKE_PARAMS} + tizen-arm: cmake-tizen-arm cmake --build ${TIZEN_ARM_BUILD_DIR} From 43ab2d07ecbcda364d0b152dbca9513ae98f391a Mon Sep 17 00:00:00 2001 From: KaiN Date: Tue, 5 Jun 2018 09:48:52 +0200 Subject: [PATCH 04/24] Cleaned up windows README, additional hints related to compiler versions --- platforms/windows/README.md | 49 +++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/platforms/windows/README.md b/platforms/windows/README.md index 30a61bc18c..64f7e2028a 100644 --- a/platforms/windows/README.md +++ b/platforms/windows/README.md @@ -1,7 +1,6 @@ -Ubuntu or Debian Linux -====================== +# Windows -## Setup ## +## Setup This project uses CMake (minimum version 3.0), you can download it [here](http://www.cmake.org/download/). @@ -13,16 +12,22 @@ git submodule update --init Currently, builds were tested under MinGW-w64 (recommended). You will need to install/build zlib and curl. -The demo application uses the Nextzen vector tile service, so you will need a Nextzen API key to build and run the demo. +The demo application uses the Nextzen vector tile service, so you will need a Nextzen API key to build and run the demo. 1. Visit https://developers.nextzen.org/ to get an API key. 2. Setup an environment variable (`NEXTZEN_API_KEY`) to point to your API key. ```bash - export NEXTZEN_API_KEY=YOUR_API_KEY + SET NEXTZEN_API_KEY=YOUR_API_KEY ``` + Or via system settings. -## Build ## +## Build + + Tangram has been reported work with 32-bit MinGW-w64 consisting of + GCC 8.1, POSIX threads and SJLJ exceptions. I've experienced crashes because + of exception handling during YAML parsing when using DWARF2 variant - any + recent version with SJLJ should work fine. 1. Download zlib sources from https://zlib.net/ @@ -54,7 +59,9 @@ mingw32-make mingw32-make install ``` -### MinGW ### +### Tangram via MinGW + +In the root directory type `mingw32-make windows` or manually: - Create directory build/windows under tangram-es root directory. - Enter command prompt and go to newly created directory. @@ -63,32 +70,36 @@ mingw32-make install You can optionally use `mingw32-make -j#` to parallelize the build and append `DEBUG=1` or `RELEASE=1` to choose the build type. - -### Clang ### -** Last time I've checked Clang wasn't able to build tangram-es because of some -kind of MSVC quirks compatibility. Proceed at your own risk.** +### Tangram via Clang -You need to have MS Build tools installed. +** Last time I've checked (LLVM5) Clang wasn't able to build tangram-es because +of some kind of MSVC quirks compatibility. Proceed at your own risk.** -`cmake -DCMAKE_C_COMPILER=clang-cl.exe -DCMAKE_CXX_COMPILER=clang-cl.exe -DCMAKE_BUILD_TYPE=Release -G "NMake Makefiles" ../..` +You need to have MS Build tools installed. Proceed as manually with MinGW, but call cmake with following: +`cmake -DCMAKE_C_COMPILER=clang-cl.exe -DCMAKE_CXX_COMPILER=clang-cl.exe -G "NMake Makefiles" ../..` + +My last try ended up with: + +``` txt D:\prg\_git\tangram-es\core\deps\harfbuzz-icu-freetype\icu\common\ucnv2022.cpp(751,9): error: ISO C++17 does not allow 'register' storage class specifier [-Wregister] +``` -### MSVC ### +### Tangram via MSVC -** Last time I've checked MSVC wasn't able to build tangram-es. +** Last time I've checked (vs2015) MSVC wasn't able to build tangram-es. Proceed at your own risk.** You need to have MS Build tools installed. - Launch Visual C++ 2015 x86 Native Build Tools Command Prompt - Enter zlib directory and run ```nmake -f win32/Makefile.msc``` -- Enter /winbuild and run nmake /f Makefile.vc mode= +- Enter `/winbuild` and run `nmake /f Makefile.vc mode=` - For static builds, go to `\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\lib` - and change `libcurl_a.lib` to `libcurl.lib` + and change `libcurl_a.lib` to `libcurl.lib` - Setup local variable `CMAKE_PREFIX_PATH` so that it includes `\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl` and ``. If `echo %CMAKE_PREFIX_PATH%` doesn't reflect changes, @@ -98,9 +109,9 @@ You need to have MS Build tools installed. - Setup CMake: `cmake ../.. -G "NMake Makefiles"` - Run build via nmake: `nmake` -## Running app ## +## Running app -App should now reside in `build/windows/bin directory`. +App should now reside in `build/windows/bin` directory. If you built curl/zlib as dynamic libraries, you'll have to supply zlib.dll and curl.dll into same directory as .exe file. From db5c6a33ac94f30dd956a227a63c57da89a9c2a6 Mon Sep 17 00:00:00 2001 From: KaiN Date: Tue, 5 Jun 2018 11:12:06 +0200 Subject: [PATCH 05/24] Building using static curl/zlib libs --- toolchains/windows.cmake | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/toolchains/windows.cmake b/toolchains/windows.cmake index 1eeb96e40b..417c5d4e57 100644 --- a/toolchains/windows.cmake +++ b/toolchains/windows.cmake @@ -7,7 +7,9 @@ if(MSVC) else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++1y") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wignored-qualifiers -Wtype-limits -Wmissing-field-initializers") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fstack-protector -static") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fstack-protector") + # Static build + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static -DCURL_STATICLIB") if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # Clang may be also used in MSVC-Clang toolchain and that will pass match above, @@ -91,6 +93,10 @@ if(TANGRAM_APPLICATION) ${OPENGL_LIBRARIES} ${CURL_LIBRARIES} ) + # For CURL static + target_link_libraries(${EXECUTABLE_NAME} + wsock32 ws2_32 crypt32 wldap32 + ) add_resources(${EXECUTABLE_NAME} "${PROJECT_SOURCE_DIR}/scenes") From e2ebcbc5b42c85a378aba5cf82148dd72760174e Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Tue, 15 Jan 2019 21:46:47 -0500 Subject: [PATCH 06/24] toolchains/windows.cmake -> platforms/windows/config.cmake --- toolchains/windows.cmake => platforms/windows/config.cmake | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename toolchains/windows.cmake => platforms/windows/config.cmake (100%) diff --git a/toolchains/windows.cmake b/platforms/windows/config.cmake similarity index 100% rename from toolchains/windows.cmake rename to platforms/windows/config.cmake From 081a18acb14ba1d4d155c554da8de36a3b50ed44 Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Tue, 15 Jan 2019 22:18:36 -0500 Subject: [PATCH 07/24] CMake cleanups - Use glad from GLFW - Remove unsupported toolchains --- Makefile | 58 ++++++------- platforms/windows/config.cmake | 150 +++++++++++---------------------- 2 files changed, 76 insertions(+), 132 deletions(-) diff --git a/Makefile b/Makefile index 8d4b852cf0..61d35298ca 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,3 @@ -# Multiplatform stuff -ifdef ComSpec - # Windows shell - RMPATH = rmdir /S /Q -else - # Civilized rest of the world - RMPATH = rm -rf -endif - all: android osx ios .PHONY: clean @@ -39,6 +30,7 @@ all: android osx ios .PHONY: cmake-ios .PHONY: cmake-rpi .PHONY: cmake-linux +.PHONY: cmake-windows ANDROID_BUILD_DIR = platforms/android/tangram/build OSX_BUILD_DIR = build/osx @@ -47,7 +39,7 @@ IOS_BUILD_DIR = build/ios IOS_DOCS_BUILD_DIR = build/ios-docs RPI_BUILD_DIR = build/rpi LINUX_BUILD_DIR = build/linux -WINDOWS_BUILD_DIR = build\windows +WINDOWS_BUILD_DIR = build/windows TESTS_BUILD_DIR = build/tests BENCH_BUILD_DIR = build/bench TIZEN_ARM_BUILD_DIR = build/tizen-arm @@ -112,10 +104,10 @@ LINUX_CMAKE_PARAMS = \ ${CMAKE_OPTIONS} WINDOWS_CMAKE_PARAMS = \ + -G "MinGW Makefiles" \ -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ - -DPLATFORM_TARGET=windows \ + -DTANGRAM_PLATFORM=windows \ -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE \ - -G "MinGW Makefiles"\ ${CMAKE_OPTIONS} ifndef TIZEN_PROFILE @@ -146,47 +138,47 @@ TIZEN_X86_CMAKE_PARAMS = \ -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE \ ${CMAKE_OPTIONS} -clean: clean-android clean-osx clean-ios clean-rpi clean-tests clean-xcode \ - clean-linux clean-windows clean-shaders clean-tizen-arm clean-tizen-x86 +clean: clean-android clean-osx clean-ios clean-rpi clean-tests clean-xcode clean-linux clean-shaders \ + clean-tizen-arm clean-tizen-x86 clean-windows clean-android: - ${RMPATH} platforms/android/build - ${RMPATH} platforms/android/tangram/build - ${RMPATH} platforms/android/tangram/.externalNativeBuild - ${RMPATH} platforms/android/demo/build + rm -rf platforms/android/build + rm -rf platforms/android/tangram/build + rm -rf platforms/android/tangram/.externalNativeBuild + rm -rf platforms/android/demo/build clean-osx: - ${RMPATH} ${OSX_BUILD_DIR} + rm -rf ${OSX_BUILD_DIR} clean-ios: - ${RMPATH} ${IOS_BUILD_DIR} + rm -rf ${IOS_BUILD_DIR} clean-rpi: - ${RMPATH} ${RPI_BUILD_DIR} + rm -rf ${RPI_BUILD_DIR} clean-linux: - ${RMPATH} ${LINUX_BUILD_DIR} + rm -rf ${LINUX_BUILD_DIR} clean-windows: - ${RMPATH} ${WINDOWS_BUILD_DIR} + rm -rf ${WINDOWS_BUILD_DIR} clean-xcode: - ${RMPATH} ${OSX_XCODE_BUILD_DIR} + rm -rf ${OSX_XCODE_BUILD_DIR} clean-tests: - ${RMPATH} ${TESTS_BUILD_DIR} + rm -rf ${TESTS_BUILD_DIR} clean-benchmark: - ${RMPATH} ${BENCH_BUILD_DIR} + rm -rf ${BENCH_BUILD_DIR} clean-shaders: - ${RMPATH} core/generated/*.h + rm -rf core/generated/*.h clean-tizen-arm: - ${RMPATH} ${TIZEN_ARM_BUILD_DIR} + rm -rf ${TIZEN_ARM_BUILD_DIR} clean-tizen-x86: - ${RMPATH} ${TIZEN_X86_BUILD_DIR} + rm -rf ${TIZEN_X86_BUILD_DIR} android: android-demo @echo "run: 'adb install -r platforms/android/demo/build/outputs/apk/debug/demo-debug.apk'" @@ -275,12 +267,12 @@ cmake-rpi: linux: cmake-linux cmake --build ${LINUX_BUILD_DIR} -cmake-linux: - cmake -H. -B${LINUX_BUILD_DIR} ${LINUX_CMAKE_PARAMS} - windows: cmake-windows cmake --build ${WINDOWS_BUILD_DIR} +cmake-linux: + cmake -H. -B${LINUX_BUILD_DIR} ${LINUX_CMAKE_PARAMS} + cmake-windows: cmake -H. -B${WINDOWS_BUILD_DIR} ${WINDOWS_CMAKE_PARAMS} @@ -312,4 +304,4 @@ format: ### Android Helpers android-install: - @adb install -r platforms/android/demo/build/outputs/apk/demo-debug.apk + @adb install -r platforms/android/demo/build/outputs/apk/demo-debug.apk \ No newline at end of file diff --git a/platforms/windows/config.cmake b/platforms/windows/config.cmake index 417c5d4e57..5882fd4f7a 100644 --- a/platforms/windows/config.cmake +++ b/platforms/windows/config.cmake @@ -1,103 +1,55 @@ -# global compile options -if(MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -std=gnu++1y") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DRAPIDJSON_HAS_CXX11_RVALUE_REFS=1") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") # Exceptions handler - required for yaml-cpp - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_USE_MATH_DEFINES") # required for geojson-vt-cpp -else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++1y") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wignored-qualifiers -Wtype-limits -Wmissing-field-initializers") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fstack-protector") - # Static build - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static -DCURL_STATICLIB") - - if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - # Clang may be also used in MSVC-Clang toolchain and that will pass match above, - # But then clang works in clang-cl mode which emulates cl.exe and accepts MSVC args, not GNU-like - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gnu-zero-variadic-macro-arguments") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lc++ -lc++abi") - endif() -endif() - -if (CMAKE_COMPILER_IS_GNUCC) - execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion - OUTPUT_VARIABLE GCC_VERSION) - string(REGEX MATCHALL "[0-9]+" GCC_VERSION_COMPONENTS ${GCC_VERSION}) - list(GET GCC_VERSION_COMPONENTS 0 GCC_MAJOR) - list(GET GCC_VERSION_COMPONENTS 1 GCC_MINOR) - - message(STATUS "Using gcc ${GCC_VERSION}") - if (GCC_VERSION VERSION_GREATER 5.1) - message(STATUS "USE CXX11_ABI") - add_definitions("-D_GLIBCXX_USE_CXX11_ABI=1") - endif() -endif() - check_unsupported_compiler_version() add_definitions(-DTANGRAM_WINDOWS) -# load core library -add_subdirectory(${PROJECT_SOURCE_DIR}/core) - -if(TANGRAM_APPLICATION) - - set(EXECUTABLE_NAME "tangram") - - get_nextzen_api_key(NEXTZEN_API_KEY) - add_definitions(-DNEXTZEN_API_KEY="${NEXTZEN_API_KEY}") - - if($ENV{CIRCLE_BUILD_NUM}) - add_definitions(-DBUILD_NUM_STRING="\($ENV{CIRCLE_BUILD_NUM}\)") - endif() - - find_package(OpenGL REQUIRED) - find_package(CURL REQUIRED) - - # Build GLFW. - if (TANGRAM_USE_SYSTEM_GLFW_LIBS) - include(FindPkgConfig) - pkg_check_modules(GLFW REQUIRED glfw3) - else() - # configure GLFW to build only the library - set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "Build the GLFW example programs") - set(GLFW_BUILD_TESTS OFF CACHE BOOL "Build the GLFW test programs") - set(GLFW_BUILD_DOCS OFF CACHE BOOL "Build the GLFW documentation") - set(GLFW_INSTALL OFF CACHE BOOL "Generate installation target") - add_subdirectory(${PROJECT_SOURCE_DIR}/platforms/common/glfw) - endif() - - add_executable(${EXECUTABLE_NAME} - ${PROJECT_SOURCE_DIR}/platforms/windows/src/windowsPlatform.cpp - ${PROJECT_SOURCE_DIR}/platforms/windows/src/main.cpp - ${PROJECT_SOURCE_DIR}/platforms/common/platform_gl.cpp - ${PROJECT_SOURCE_DIR}/platforms/common/urlClient.cpp - ${PROJECT_SOURCE_DIR}/platforms/common/glfwApp.cpp - ${PROJECT_SOURCE_DIR}/platforms/common/glad.c - ) - - target_include_directories(${EXECUTABLE_NAME} - PUBLIC - ${GLFW_SOURCE_DIR}/include - ${PROJECT_SOURCE_DIR}/platforms/common - ${CURL_INCLUDE_DIRS} - ) - - target_link_libraries(${EXECUTABLE_NAME} - ${CORE_LIBRARY} - glfw - # only used when not using external lib - -pthread - ${GLFW_LIBRARIES} - ${OPENGL_LIBRARIES} - ${CURL_LIBRARIES} - ) - # For CURL static - target_link_libraries(${EXECUTABLE_NAME} - wsock32 ws2_32 crypt32 wldap32 - ) - - add_resources(${EXECUTABLE_NAME} "${PROJECT_SOURCE_DIR}/scenes") - -endif() +find_package(OpenGL REQUIRED) +find_package(CURL REQUIRED) + +include(cmake/glfw.cmake) + +add_executable(tangram + ${PROJECT_SOURCE_DIR}/platforms/windows/src/windowsPlatform.cpp + ${PROJECT_SOURCE_DIR}/platforms/windows/src/main.cpp + ${PROJECT_SOURCE_DIR}/platforms/common/platform_gl.cpp + ${PROJECT_SOURCE_DIR}/platforms/common/urlClient.cpp + ${PROJECT_SOURCE_DIR}/platforms/common/glfwApp.cpp + #${PROJECT_SOURCE_DIR}/platforms/common/glad.c +) + +add_resources(tangram "${PROJECT_SOURCE_DIR}/scenes" "res") + +add_subdirectory(platforms/common/imgui) + +target_include_directories(tangram + PRIVATE + platforms/common + platforms/common/glfw/deps + ${CURL_INCLUDE_DIRS} +) + +target_link_libraries(tangram + PRIVATE + tangram-core + glfw + imgui + ${GLFW_LIBRARIES} + ${OPENGL_LIBRARIES} + ${CURL_LIBRARIES} + -pthread + wsock32 ws2_32 crypt32 wldap32 +) + +target_compile_options(tangram + PRIVATE + -std=c++14 + -fno-omit-frame-pointer + -Wall + -Wreturn-type + -Wsign-compare + -Wignored-qualifiers + -Wtype-limits + -Wmissing-field-initializers +) + +get_nextzen_api_key(NEXTZEN_API_KEY) +target_compile_definitions(tangram PRIVATE NEXTZEN_API_KEY="${NEXTZEN_API_KEY}") \ No newline at end of file From 019c00666565145198f8a0e1bd0c6fe83984d4b2 Mon Sep 17 00:00:00 2001 From: KaiN Date: Fri, 18 Jan 2019 13:29:10 +0100 Subject: [PATCH 08/24] fixed M_PI undefined errors --- core/src/labels/fadeEffect.h | 3 +++ core/src/util/ease.h | 3 +++ core/src/util/rasterize.h | 3 +++ core/src/view/viewConstraint.h | 3 +++ 4 files changed, 12 insertions(+) diff --git a/core/src/labels/fadeEffect.h b/core/src/labels/fadeEffect.h index 7fce72aeff..f5b12042d8 100644 --- a/core/src/labels/fadeEffect.h +++ b/core/src/labels/fadeEffect.h @@ -1,6 +1,9 @@ #pragma once #include +#ifndef M_PI // M_PI is non-standard since c++99 +#define M_PI (3.14159265358979323846264338327950288) +#endif namespace Tangram { diff --git a/core/src/util/ease.h b/core/src/util/ease.h index a1a0bb2b4e..ab5353daff 100644 --- a/core/src/util/ease.h +++ b/core/src/util/ease.h @@ -3,6 +3,9 @@ #include "map.h" #include +#ifndef M_PI // M_PI is non-standard since c++99 +#define M_PI (3.14159265358979323846264338327950288) +#endif #include namespace Tangram { diff --git a/core/src/util/rasterize.h b/core/src/util/rasterize.h index 4a3812a224..cd4f8c90fd 100644 --- a/core/src/util/rasterize.h +++ b/core/src/util/rasterize.h @@ -2,6 +2,9 @@ #include "glm/vec2.hpp" #include +#ifndef M_PI // M_PI is non-standard since c++99 +#define M_PI (3.14159265358979323846264338327950288) +#endif #include namespace Tangram { diff --git a/core/src/view/viewConstraint.h b/core/src/view/viewConstraint.h index 3a527484b0..9e13431e00 100644 --- a/core/src/view/viewConstraint.h +++ b/core/src/view/viewConstraint.h @@ -1,5 +1,8 @@ #pragma once #include +#ifndef M_PI // M_PI is non-standard since c++99 +#define M_PI (3.14159265358979323846264338327950288) +#endif namespace Tangram { From 213a9c8146034d824eeaabaa47ac50377faaceb4 Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Tue, 22 Jan 2019 23:18:55 -0500 Subject: [PATCH 09/24] Fix link issues --- platforms/common/glfwApp.cpp | 1 - platforms/windows/config.cmake | 14 ++++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/platforms/common/glfwApp.cpp b/platforms/common/glfwApp.cpp index 37004b0e8a..4070c2ea1f 100644 --- a/platforms/common/glfwApp.cpp +++ b/platforms/common/glfwApp.cpp @@ -4,7 +4,6 @@ #include "imgui_impl_glfw.h" #include "imgui_impl_opengl3.h" #include "imgui_stl.h" -#include "debug/textDisplay.h" #ifdef TANGRAM_WINDOWS #define GLFW_INCLUDE_NONE diff --git a/platforms/windows/config.cmake b/platforms/windows/config.cmake index 5882fd4f7a..00bff2b7f1 100644 --- a/platforms/windows/config.cmake +++ b/platforms/windows/config.cmake @@ -8,12 +8,14 @@ find_package(CURL REQUIRED) include(cmake/glfw.cmake) add_executable(tangram - ${PROJECT_SOURCE_DIR}/platforms/windows/src/windowsPlatform.cpp - ${PROJECT_SOURCE_DIR}/platforms/windows/src/main.cpp - ${PROJECT_SOURCE_DIR}/platforms/common/platform_gl.cpp - ${PROJECT_SOURCE_DIR}/platforms/common/urlClient.cpp - ${PROJECT_SOURCE_DIR}/platforms/common/glfwApp.cpp - #${PROJECT_SOURCE_DIR}/platforms/common/glad.c + platforms/windows/src/windowsPlatform.cpp + platforms/windows/src/main.cpp + platforms/common/platform_gl.cpp + platforms/common/urlClient.cpp + platforms/common/glfwApp.cpp + platforms/common/imgui_impl_glfw.cpp + platforms/common/imgui_impl_opengl3.cpp + platforms/common/glfw/deps/glad.c ) add_resources(tangram "${PROJECT_SOURCE_DIR}/scenes" "res") From 302996a197cd0df86891797b02ff1b5c93b81f83 Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Tue, 22 Jan 2019 23:27:12 -0500 Subject: [PATCH 10/24] Fix undefined ref to __stack_chk_fail --- platforms/windows/config.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/platforms/windows/config.cmake b/platforms/windows/config.cmake index 00bff2b7f1..840810c085 100644 --- a/platforms/windows/config.cmake +++ b/platforms/windows/config.cmake @@ -1,5 +1,8 @@ check_unsupported_compiler_version() +# TODO: only sqlite? +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector") + add_definitions(-DTANGRAM_WINDOWS) find_package(OpenGL REQUIRED) From 25982fbffea7dd866d26297c8b034d4654269011 Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Wed, 30 Jan 2019 16:58:24 -0500 Subject: [PATCH 11/24] Rebase to origin --- platforms/windows/src/main.cpp | 11 +++-- platforms/windows/src/windowsPlatform.cpp | 50 +++++++++++++++++------ platforms/windows/src/windowsPlatform.h | 13 +++--- 3 files changed, 50 insertions(+), 24 deletions(-) diff --git a/platforms/windows/src/main.cpp b/platforms/windows/src/main.cpp index 8750207924..203b1df4fa 100644 --- a/platforms/windows/src/main.cpp +++ b/platforms/windows/src/main.cpp @@ -11,21 +11,19 @@ using namespace Tangram; int main(int argc, char* argv[]) { - auto platform = std::make_shared(); - // Create the windowed app. - GlfwApp::create(platform, 1024, 768); + GlfwApp::create(std::make_unique(), 1024, 768); GlfwApp::parseArgs(argc, argv); - + // Resolve the input path against the current directory. Url baseUrl("file:///"); char pathBuffer[PATH_MAX] = {0}; if (_getcwd(pathBuffer, PATH_MAX) != nullptr) { baseUrl = Url("file://" + std::string(pathBuffer)).resolved(baseUrl); } - + LOG("Base URL: %s", baseUrl.string().c_str()); - + Url sceneUrl = Url(GlfwApp::sceneFile).resolved(baseUrl); GlfwApp::sceneFile = sceneUrl.string(); @@ -35,4 +33,5 @@ int main(int argc, char* argv[]) { // Clean up. GlfwApp::destroy(); + return 0; } diff --git a/platforms/windows/src/windowsPlatform.cpp b/platforms/windows/src/windowsPlatform.cpp index 85007e4915..2e7168fcdc 100644 --- a/platforms/windows/src/windowsPlatform.cpp +++ b/platforms/windows/src/windowsPlatform.cpp @@ -23,13 +23,24 @@ void logMsg(const char* fmt, ...) { va_end(args); } -WindowsPlatform::WindowsPlatform() : - m_urlClient(UrlClient::Options{}) {} +WindowsPlatform::WindowsPlatform() + : WindowsPlatform(UrlClient::Options{}) {} WindowsPlatform::WindowsPlatform(UrlClient::Options urlClientOptions) : - m_urlClient(urlClientOptions) {} + m_urlClient(std::make_unique(urlClientOptions)) { +} + +WindowsPlatform::~WindowsPlatform() {} + +void WindowsPlatform::shutdown() { + // Stop all UrlWorker threads + m_urlClient.reset(); + + Platform::shutdown(); +} void WindowsPlatform::requestRender() const { + if (m_shutdown) { return; } glfwPostEmptyEvent(); } @@ -45,19 +56,34 @@ std::vector WindowsPlatform::systemFontFallbacksHandle() const return handles; } -UrlRequestHandle WindowsPlatform::startUrlRequest(Url _url, UrlCallback _callback) { - return m_urlClient.addRequest(_url.string(), _callback); +bool WindowsPlatform::startUrlRequestImpl(const Url& _url, const UrlRequestHandle _request, UrlRequestId& _id) { + if (_url.hasHttpScheme()) { + auto onRequestResponse = [this, _request](UrlResponse&& response) { + onUrlResponse(_request, std::move(response)); + }; + _id = m_urlClient->addRequest(_url.string(), onRequestResponse); + return true; + } + auto fileWorkerTask = [this, path = _url.path(), _request](){ + UrlResponse response; + auto allocator = [&](size_t size) { + response.content.resize(size); + return response.content.data(); + }; + Platform::bytesFromFileSystem(path.c_str(), allocator); + onUrlResponse(_request, std::move(response)); + }; + m_fileWorker.enqueue(fileWorkerTask); + return false; } -void WindowsPlatform::cancelUrlRequest(UrlRequestHandle _request) { - m_urlClient.cancelRequest(_request); +void WindowsPlatform::cancelUrlRequestImpl(const UrlRequestId _id) { + if (m_urlClient) { + m_urlClient->cancelRequest(_id); + } } -WindowsPlatform::~WindowsPlatform() {} - -void setCurrentThreadPriority(int priority) { - // No-op -} +void setCurrentThreadPriority(int priority) {} void initGLExtensions() { Tangram::Hardware::supportsMapBuffer = true; diff --git a/platforms/windows/src/windowsPlatform.h b/platforms/windows/src/windowsPlatform.h index 6796f3d333..c997411b1d 100644 --- a/platforms/windows/src/windowsPlatform.h +++ b/platforms/windows/src/windowsPlatform.h @@ -2,6 +2,7 @@ #include "platform.h" #include "urlClient.h" +#include "util/asyncWorker.h" namespace Tangram { @@ -10,17 +11,17 @@ class WindowsPlatform : public Platform { public: WindowsPlatform(); - WindowsPlatform(UrlClient::Options urlClientOptions); + explicit WindowsPlatform(UrlClient::Options urlClientOptions); ~WindowsPlatform() override; + void shutdown() override; void requestRender() const override; std::vector systemFontFallbacksHandle() const override; - UrlRequestHandle startUrlRequest(Url _url, UrlCallback _callback) override; - void cancelUrlRequest(UrlRequestHandle _request) override; + bool startUrlRequestImpl(const Url& _url, const UrlRequestHandle _request, UrlRequestId& _id) override; + void cancelUrlRequestImpl(const UrlRequestId _id) override; protected: - - UrlClient m_urlClient; - + std::unique_ptr m_urlClient; + AsyncWorker m_fileWorker; }; } // namespace Tangram From fef440ad8273a5fcf9ddb5463cbf438bb439ae15 Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Wed, 30 Jan 2019 14:40:15 -0500 Subject: [PATCH 12/24] Fix runtime issues - Fixup path for res folder - Remove stack protector on sqlite dependency --- core/deps/CMakeLists.txt | 2 ++ platforms/windows/config.cmake | 3 --- platforms/windows/src/windowsPlatform.cpp | 10 +++++----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/core/deps/CMakeLists.txt b/core/deps/CMakeLists.txt index a9fffb520d..7033cc7f68 100644 --- a/core/deps/CMakeLists.txt +++ b/core/deps/CMakeLists.txt @@ -82,6 +82,8 @@ if (TANGRAM_MBTILES_DATASOURCE) if (ANDROID) target_compile_definitions(sqlite3 PRIVATE _FILE_OFFSET_BITS=32) endif() + target_compile_options(SQLiteCpp PRIVATE -fno-stack-protector) + target_compile_options(sqlite3 PRIVATE -fno-stack-protector) endif() ## double-conversion ## diff --git a/platforms/windows/config.cmake b/platforms/windows/config.cmake index 840810c085..00bff2b7f1 100644 --- a/platforms/windows/config.cmake +++ b/platforms/windows/config.cmake @@ -1,8 +1,5 @@ check_unsupported_compiler_version() -# TODO: only sqlite? -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector") - add_definitions(-DTANGRAM_WINDOWS) find_package(OpenGL REQUIRED) diff --git a/platforms/windows/src/windowsPlatform.cpp b/platforms/windows/src/windowsPlatform.cpp index 2e7168fcdc..4c9c1c71d2 100644 --- a/platforms/windows/src/windowsPlatform.cpp +++ b/platforms/windows/src/windowsPlatform.cpp @@ -8,11 +8,11 @@ #include -#define DEFAULT "fonts/NotoSans-Regular.ttf" -#define FONT_AR "fonts/NotoNaskh-Regular.ttf" -#define FONT_HE "fonts/NotoSansHebrew-Regular.ttf" -#define FONT_JA "fonts/DroidSansJapanese.ttf" -#define FALLBACK "fonts/DroidSansFallback.ttf" +#define DEFAULT "res/fonts/NotoSans-Regular.ttf" +#define FONT_AR "res/fonts/NotoNaskh-Regular.ttf" +#define FONT_HE "res/fonts/NotoSansHebrew-Regular.ttf" +#define FONT_JA "res/fonts/DroidSansJapanese.ttf" +#define FALLBACK "res/fonts/DroidSansFallback.ttf" namespace Tangram { From 3c3d0ac8c07c1ef9cdaa0224c6fa379c8bdb45d0 Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Wed, 30 Jan 2019 14:47:04 -0500 Subject: [PATCH 13/24] Fix missing return statement --- platforms/linux/src/main.cpp | 5 +++-- platforms/osx/src/main.mm | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/platforms/linux/src/main.cpp b/platforms/linux/src/main.cpp index ccc36ba9c3..e4a91f06ee 100644 --- a/platforms/linux/src/main.cpp +++ b/platforms/linux/src/main.cpp @@ -24,9 +24,9 @@ int main(int argc, char* argv[]) { if (getcwd(pathBuffer, PATH_MAX) != nullptr) { baseUrl = Url(std::string(pathBuffer) + "/").resolved(baseUrl); } - + LOG("Base URL: %s", baseUrl.string().c_str()); - + Url sceneUrl = Url(GlfwApp::sceneFile).resolved(baseUrl); GlfwApp::sceneFile = sceneUrl.string(); @@ -39,4 +39,5 @@ int main(int argc, char* argv[]) { // Clean up. GlfwApp::destroy(); + return 0; } diff --git a/platforms/osx/src/main.mm b/platforms/osx/src/main.mm index ec949b39af..19d1d12394 100644 --- a/platforms/osx/src/main.mm +++ b/platforms/osx/src/main.mm @@ -103,4 +103,6 @@ int main(int argc, char* argv[]) { // Clean up. GlfwApp::destroy(); + + return 0; } From 139e3d7f81958e978ee9e587384d1d962ee88750 Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Wed, 30 Jan 2019 18:44:51 -0500 Subject: [PATCH 14/24] Simplify Windows Readme instructions --- platforms/windows/README.md | 102 +++++++----------------------------- 1 file changed, 19 insertions(+), 83 deletions(-) diff --git a/platforms/windows/README.md b/platforms/windows/README.md index 64f7e2028a..af08a665a1 100644 --- a/platforms/windows/README.md +++ b/platforms/windows/README.md @@ -10,24 +10,18 @@ Make sure to update git submodules before you build: git submodule update --init ``` -Currently, builds were tested under MinGW-w64 (recommended). You will need to install/build zlib and curl. +Builds were tested under MinGW-w64 (required). You will need to install/build zlib and curl manually. The demo application uses the Nextzen vector tile service, so you will need a Nextzen API key to build and run the demo. 1. Visit https://developers.nextzen.org/ to get an API key. - 2. Setup an environment variable (`NEXTZEN_API_KEY`) to point to your API key. - ```bash - SET NEXTZEN_API_KEY=YOUR_API_KEY - ``` - Or via system settings. + 2. Setup an environment variable (`SET NEXTZEN_API_KEY=YOUR_API_KEY` or via system settings) to point to your API key. ## Build - Tangram has been reported work with 32-bit MinGW-w64 consisting of - GCC 8.1, POSIX threads and SJLJ exceptions. I've experienced crashes because - of exception handling during YAML parsing when using DWARF2 variant - any - recent version with SJLJ should work fine. + The **only** supported toolchain to build Tangram ES on Windows is currently MinGW (MinGW-w64 + with GCC, POSIX threads and SJLJ exceptions). 1. Download zlib sources from https://zlib.net/ @@ -35,87 +29,29 @@ The demo application uses the Nextzen vector tile service, so you will need a Ne ### Zlib and Curl under MinGW-w64 -- CMake typically installs everything under Program Files, which is unfortunate - because it needs elevated privileges and also bloats dir quickly. I strongly - encourage you to make dedicated directory, e.g. `c:/prg/cmake_install`. - To make it work, set `CMAKE_PREFIX_PATH` env var to this directory. - If `echo %CMAKE_PREFIX_PATH%` doesn't reflect changes, you must restart - command prompt or log out and log in to Windows. -- Using latest curl & zlib source packages is usually the best idea. +CMake typically installs everything under Program Files, which requires elevated privileges. It is encouraged you to make dedicated directory, e.g. `c:/cmake-install`. To make it work, set `CMAKE_PREFIX_PATH` env var to this directory. The build has been tested with curl 7.63 and zlib 1.2. +From the zlib source directory: ``` bat -cd /d C:\path\to\zlib-1.2.11 -mkdir build && cd build -cmake .. -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=c:/prg/cmake_install -mingw32-make -mingw32-make install +cmake -H. -Bbuild -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=c:/cmake-install +cmake --build build +cmake --build build --target install ``` - +From the curl source directory: ``` bat -cd /d C:\path\to\curl-7.60.0 -mkdir build && cd build -cmake .. -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=c:/prg/cmake_install -DCMAKE_USE_WINSSL=ON -mingw32-make -mingw32-make install +cmake -H. -Bbuild -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=c:/cmake-install -DCMAKE_USE_WINSSL=ON +cmake --build build +cmake --build build --target install ``` -### Tangram via MinGW - -In the root directory type `mingw32-make windows` or manually: - -- Create directory build/windows under tangram-es root directory. -- Enter command prompt and go to newly created directory. -- Setup CMake, forcing MinGW toolchain: `cmake ../.. -G "MinGW Makefiles"` -- Run build via make: `mingw32-make` - -You can optionally use `mingw32-make -j#` to parallelize the build -and append `DEBUG=1` or `RELEASE=1` to choose the build type. - -### Tangram via Clang +### Build Tangram -** Last time I've checked (LLVM5) Clang wasn't able to build tangram-es because -of some kind of MSVC quirks compatibility. Proceed at your own risk.** - -You need to have MS Build tools installed. Proceed as manually with MinGW, but call cmake with following: - -`cmake -DCMAKE_C_COMPILER=clang-cl.exe -DCMAKE_CXX_COMPILER=clang-cl.exe -G "NMake Makefiles" ../..` - -My last try ended up with: - -``` txt -D:\prg\_git\tangram-es\core\deps\harfbuzz-icu-freetype\icu\common\ucnv2022.cpp(751,9): error: ISO C++17 does not allow - 'register' storage class specifier [-Wregister] -``` - -### Tangram via MSVC - -** Last time I've checked (vs2015) MSVC wasn't able to build tangram-es. -Proceed at your own risk.** - -You need to have MS Build tools installed. - -- Launch Visual C++ 2015 x86 Native Build Tools Command Prompt -- Enter zlib directory and run ```nmake -f win32/Makefile.msc``` -- Enter `/winbuild` and run `nmake /f Makefile.vc mode=` -- For static builds, go to - `\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\lib` - and change `libcurl_a.lib` to `libcurl.lib` -- Setup local variable `CMAKE_PREFIX_PATH` so that it includes - `\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl` - and ``. If `echo %CMAKE_PREFIX_PATH%` doesn't reflect changes, - you must restart command prompt or log out and log in to Windows. -- Create directory build/windows under tangram-es root directory. -- Enter command prompt and go to newly created directory. -- Setup CMake: `cmake ../.. -G "NMake Makefiles"` -- Run build via nmake: `nmake` +In the root directory type `mingw32-make windows`. You can append `DEBUG=1` or `RELEASE=1` to choose the build type. ## Running app -App should now reside in `build/windows/bin` directory. -If you built curl/zlib as dynamic libraries, you'll have to supply zlib.dll -and curl.dll into same directory as .exe file. - -You can open a different YAML scene file by dragging and dropping it into the -window, or passing it as an argument: +You can open a different YAML scene file by using the argument `-f`: -`tangram -f /path/to/your/scene.yaml` +``` +tangram.exe -f "C:\Users\user\dev\tangram-es\build\windows\res\scene.yaml" +``` From 5bcb27e0a5c0030cb6037e96dce19965a3374a66 Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Wed, 30 Jan 2019 18:48:34 -0500 Subject: [PATCH 15/24] Cleanup utils.cmake - Remove unused - Convert to 2 spaces tabs --- cmake/utils.cmake | 142 ++++++++++++---------------------------------- 1 file changed, 36 insertions(+), 106 deletions(-) diff --git a/cmake/utils.cmake b/cmake/utils.cmake index 74219ec35f..a65f0428cc 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -1,119 +1,49 @@ function(check_unsupported_compiler_version) + set(MIN_GCC 4.9) + set(MIN_CLANG 3.4) + set(MIN_APPLECLANG 6.0) - set(MIN_GCC 4.9) - set(MIN_CLANG 3.4) - set(MIN_APPLECLANG 6.0) - - if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${MIN_GCC}) - message(FATAL_ERROR "Your GCC version does not support C++14, please install version ${MIN_GCC} or higher") - endif() - elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${MIN_CLANG}) - message(FATAL_ERROR "Your Clang version does not support C++14, please install version ${MIN_CLANG} or higher") - endif() - elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${MIN_APPLECLANG}) - message(FATAL_ERROR "Your Xcode version does not support C++14, please install version ${MIN_APPLECLANG} or higher") - endif() - else() - message(WARNING "Compilation has only been tested with Clang, AppleClang, and GCC") + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${MIN_GCC}) + message(FATAL_ERROR "Your GCC version does not support C++14, please install version ${MIN_GCC} or higher") endif() - + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${MIN_CLANG}) + message(FATAL_ERROR "Your Clang version does not support C++14, please install version ${MIN_CLANG} or higher") + endif() + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${MIN_APPLECLANG}) + message(FATAL_ERROR "Your Xcode version does not support C++14, please install version ${MIN_APPLECLANG} or higher") + endif() + else() + message(WARNING "Compilation has only been tested with Clang, AppleClang, and GCC") + endif() endfunction(check_unsupported_compiler_version) function(get_nextzen_api_key KEY_RESULT) - - set(${KEY_RESULT} $ENV{NEXTZEN_API_KEY} PARENT_SCOPE) - - if(${KEY_RESULT} STREQUAL "") - message(SEND_ERROR - "Make sure to provide an api key to build the demo application, " - "you can create an API key at https://developers.nextzen.org/. " - "Then run 'export NEXTZEN_API_KEY yourKeyHere' or specify `NEXTZEN_API_KEY=yourKeyHere` as an argument to the make command") - return() - endif() - + set(${KEY_RESULT} $ENV{NEXTZEN_API_KEY} PARENT_SCOPE) + if(${KEY_RESULT} STREQUAL "") + message(SEND_ERROR + "Make sure to provide an api key to build the demo application, " + "you can create an API key at https://developers.nextzen.org/. " + "Then run 'export NEXTZEN_API_KEY yourKeyHere' or specify `NEXTZEN_API_KEY=yourKeyHere` as an argument to the make command") + return() + endif() endfunction(get_nextzen_api_key) - -function(find_sources_and_include_directories HEADERS_PATH SOURCES_PATH) - include_recursive_dirs(${HEADERS_PATH}) - file(GLOB_RECURSE FOUND_SOURCES ${SOURCES_PATH}) - - set(SOURCES - ${SOURCES} - ${FOUND_SOURCES} - CACHE INTERNAL "sources" FORCE) - list(REMOVE_DUPLICATES SOURCES) -endfunction(find_sources_and_include_directories) - -function(include_recursive_dirs HEADERS_PATH) - file(GLOB_RECURSE FOUND_HEADERS ${HEADERS_PATH}) - - set(INCLUDE_DIRS "") - foreach(_headerFile ${FOUND_HEADERS}) - get_filename_component(_dir ${_headerFile} PATH) - list(APPEND INCLUDE_DIRS ${_dir}) - endforeach() - list(REMOVE_DUPLICATES INCLUDE_DIRS) - - include_directories(${INCLUDE_DIRS}) - - set(HEADERS - ${HEADERS} - ${FOUND_HEADERS} - CACHE INTERNAL "headers" FORCE) - list(REMOVE_DUPLICATES HEADERS) -endfunction(include_recursive_dirs) - -function(check_and_link_libraries TARGET) - foreach(_lib ${ARGN}) - string(TOUPPER ${_lib} LIB) - find_package (${_lib}) - if(${LIB}_FOUND) - include_directories(${${LIB}_INCLUDE_DIR}) - target_link_libraries(${TARGET} ${${LIB}_LIBRARIES}) - else() - message(SEND_ERROR "You NEED ${_lib} library.") - return() - endif () - endforeach() -endfunction(check_and_link_libraries) - macro(add_bundle_resources RESOURCE_LIST RESOURCE_DIR RESOURCE_BASE) - - file(GLOB_RECURSE FULL_RESOURCE_PATHS "${RESOURCE_DIR}/[^.]**") - foreach(_full_resource_path ${FULL_RESOURCE_PATHS}) - file(RELATIVE_PATH REL_RESOURCE_PATH ${RESOURCE_DIR} ${_full_resource_path}) - get_filename_component(REL_RESOURCE_DIR ${REL_RESOURCE_PATH} PATH) - set_source_files_properties(${_full_resource_path} PROPERTIES MACOSX_PACKAGE_LOCATION "${RESOURCE_BASE}/${REL_RESOURCE_DIR}") - # message(STATUS "resource at: ${_full_resource_path}\n remapped to: ${RESOURCE_BASE}/${REL_RESOURCE_DIR}") - endforeach() - list(APPEND ${RESOURCE_LIST} ${FULL_RESOURCE_PATHS}) - + file(GLOB_RECURSE FULL_RESOURCE_PATHS "${RESOURCE_DIR}/[^.]**") + foreach(_full_resource_path ${FULL_RESOURCE_PATHS}) + file(RELATIVE_PATH REL_RESOURCE_PATH ${RESOURCE_DIR} ${_full_resource_path}) + get_filename_component(REL_RESOURCE_DIR ${REL_RESOURCE_PATH} PATH) + set_source_files_properties(${_full_resource_path} PROPERTIES MACOSX_PACKAGE_LOCATION "${RESOURCE_BASE}/${REL_RESOURCE_DIR}") + # message(STATUS "resource at: ${_full_resource_path}\n remapped to: ${RESOURCE_BASE}/${REL_RESOURCE_DIR}") + endforeach() + list(APPEND ${RESOURCE_LIST} ${FULL_RESOURCE_PATHS}) endmacro(add_bundle_resources) macro(add_resources TARGET RESOURCE_DIR DEST_DIR) - - add_custom_command(TARGET ${TARGET} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory ${RESOURCE_DIR} ${CMAKE_BINARY_DIR}/${DEST_DIR}) - + add_custom_command(TARGET ${TARGET} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory ${RESOURCE_DIR} ${CMAKE_BINARY_DIR}/${DEST_DIR}) endmacro(add_resources) - -macro(target_add_framework APPNAME FWNAME) - find_library(${FWNAME}_FRAMEWORK ${FWNAME}) - if(${${FWNAME}_FRAMEWORK}) - target_link_libraries(${APPNAME} PRIVATE ${FRAMEWORK_${FWNAME}}) - message(STATUS "Framework ${FWNAME} found") - else() - message(SEND_ERROR "Framework ${FWNAME} not found") - endif() -endmacro(target_add_framework) - -# This little macro lets you set any XCode specific property -macro (set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE) - set_property (TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE}) -endmacro (set_xcode_property) - From 551ce7f3e8f032e39f32d1093ba1c2804cfd64fc Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Wed, 30 Jan 2019 19:04:03 -0500 Subject: [PATCH 16/24] Add Appveyor CI --- .appveyor.yml | 21 +++++++++++++++++++++ Makefile | 3 ++- platforms/windows/README.md | 3 +-- platforms/windows/config.cmake | 7 +++++-- 4 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 .appveyor.yml diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000000..7d3d4de519 --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,21 @@ +install: + - set PATH=C:\cmake-install\bin;C:cmake-install\lib;C:\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\bin;%PATH% + - appveyor DownloadFile "https://www.zlib.net/zlib-1.2.11.tar.gz" + - 7z x -o. zlib-1.2.11.tar.gz + - 7z x -oC:\cmake-install zlib-1.2.11.tar + - cd C:\cmake-install\zlib-1.2.11 + - cmake -H. -Bbuild -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=C:\cmake-install -DCMAKE_SH="CMAKE_SH-NOTFOUND" + - cmake --build build + - cmake --build build --target install + - appveyor DownloadFile "https://curl.haxx.se/download/curl-7.63.0.tar.gz" + - 7z x -o. curl-7.63.0.tar.gz + - 7z x -oC:\cmake-install curl-7.63.0.tar + - cd C:\cmake-install\curl-7.63.0 + - cmake -H. -Bbuild -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=C:\cmake-install -DCMAKE_USE_WINSSL=ON -DCMAKE_SH="CMAKE_SH-NOTFOUND" + - cmake --build build + - cmake --build build --target install + - cd C:\projects\tangram-es +before_build: + - git submodule update --init --recursive +build_script: + - mingw32-make windows CMAKE_OPTIONS="-DCURL_LIBRARIES=C:/cmake-install/bin/libcurl.dll -DCURL_INCLUDE_DIRS=C:/cmake-install/include" diff --git a/Makefile b/Makefile index 61d35298ca..030452b079 100644 --- a/Makefile +++ b/Makefile @@ -108,6 +108,7 @@ WINDOWS_CMAKE_PARAMS = \ -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ -DTANGRAM_PLATFORM=windows \ -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE \ + -DCMAKE_SH="CMAKE_SH-NOTFOUND" \ ${CMAKE_OPTIONS} ifndef TIZEN_PROFILE @@ -304,4 +305,4 @@ format: ### Android Helpers android-install: - @adb install -r platforms/android/demo/build/outputs/apk/demo-debug.apk \ No newline at end of file + @adb install -r platforms/android/demo/build/outputs/apk/demo-debug.apk diff --git a/platforms/windows/README.md b/platforms/windows/README.md index af08a665a1..d0e5b0d00f 100644 --- a/platforms/windows/README.md +++ b/platforms/windows/README.md @@ -20,8 +20,7 @@ The demo application uses the Nextzen vector tile service, so you will need a Ne ## Build - The **only** supported toolchain to build Tangram ES on Windows is currently MinGW (MinGW-w64 - with GCC, POSIX threads and SJLJ exceptions). + The **only** supported toolchain to build Tangram ES on Windows is currently MinGW (MinGW GCC, POSIX threads). 1. Download zlib sources from https://zlib.net/ diff --git a/platforms/windows/config.cmake b/platforms/windows/config.cmake index 00bff2b7f1..f4a0332a2d 100644 --- a/platforms/windows/config.cmake +++ b/platforms/windows/config.cmake @@ -3,7 +3,10 @@ check_unsupported_compiler_version() add_definitions(-DTANGRAM_WINDOWS) find_package(OpenGL REQUIRED) -find_package(CURL REQUIRED) + +if(NOT DEFINED CURL_LIBRARIES OR NOT DEFINED CURL_INCLUDE_DIRS) + find_package(CURL REQUIRED) +endif() include(cmake/glfw.cmake) @@ -54,4 +57,4 @@ target_compile_options(tangram ) get_nextzen_api_key(NEXTZEN_API_KEY) -target_compile_definitions(tangram PRIVATE NEXTZEN_API_KEY="${NEXTZEN_API_KEY}") \ No newline at end of file +target_compile_definitions(tangram PRIVATE NEXTZEN_API_KEY="${NEXTZEN_API_KEY}") From 63ccb41d75110f0cf8b1a26dfd838665cc85c746 Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Tue, 12 Feb 2019 20:38:59 -0500 Subject: [PATCH 17/24] Use tangram scoped platform define --- platforms/common/glfwApp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platforms/common/glfwApp.cpp b/platforms/common/glfwApp.cpp index 4070c2ea1f..6ec73e3114 100644 --- a/platforms/common/glfwApp.cpp +++ b/platforms/common/glfwApp.cpp @@ -188,7 +188,7 @@ void create(std::unique_ptr p, int w, int h) { glfwMakeContextCurrent(main_window); glfwSwapInterval(1); // Enable vsync -#ifdef _WIN32 +#ifdef TANGRAM_WINDOWS gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); #endif From 8ba4de73fd9b29d5fbcd6540398584f4d09aff7f Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Wed, 13 Feb 2019 13:27:35 -0500 Subject: [PATCH 18/24] Fix CI --- core/deps/CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/deps/CMakeLists.txt b/core/deps/CMakeLists.txt index 7033cc7f68..703d0f1f71 100644 --- a/core/deps/CMakeLists.txt +++ b/core/deps/CMakeLists.txt @@ -82,8 +82,10 @@ if (TANGRAM_MBTILES_DATASOURCE) if (ANDROID) target_compile_definitions(sqlite3 PRIVATE _FILE_OFFSET_BITS=32) endif() - target_compile_options(SQLiteCpp PRIVATE -fno-stack-protector) - target_compile_options(sqlite3 PRIVATE -fno-stack-protector) + if (WIN32) + target_compile_options(SQLiteCpp PRIVATE -fno-stack-protector) + target_compile_options(sqlite3 PRIVATE -fno-stack-protector) + endif() endif() ## double-conversion ## From 564cde8b2c11a06c5c57fc4d817397e16d417bfc Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Thu, 14 Feb 2019 12:28:54 -0500 Subject: [PATCH 19/24] Speedup CI builds - Make use of build options to disable curl tests and exe - Make use of vm cores --- .appveyor.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 7d3d4de519..b26e4e74ad 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -5,17 +5,17 @@ install: - 7z x -oC:\cmake-install zlib-1.2.11.tar - cd C:\cmake-install\zlib-1.2.11 - cmake -H. -Bbuild -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=C:\cmake-install -DCMAKE_SH="CMAKE_SH-NOTFOUND" - - cmake --build build + - cmake --build build -- -j2 - cmake --build build --target install - appveyor DownloadFile "https://curl.haxx.se/download/curl-7.63.0.tar.gz" - 7z x -o. curl-7.63.0.tar.gz - 7z x -oC:\cmake-install curl-7.63.0.tar - cd C:\cmake-install\curl-7.63.0 - - cmake -H. -Bbuild -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=C:\cmake-install -DCMAKE_USE_WINSSL=ON -DCMAKE_SH="CMAKE_SH-NOTFOUND" - - cmake --build build + - cmake -H. -Bbuild -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=C:\cmake-install -DBUILD_CURL_EXE=OFF -DBUILD_TESTING=OFF -DCMAKE_USE_WINSSL=ON -DCMAKE_SH="CMAKE_SH-NOTFOUND" + - cmake --build build -- -j2 - cmake --build build --target install - cd C:\projects\tangram-es before_build: - git submodule update --init --recursive build_script: - - mingw32-make windows CMAKE_OPTIONS="-DCURL_LIBRARIES=C:/cmake-install/bin/libcurl.dll -DCURL_INCLUDE_DIRS=C:/cmake-install/include" + - mingw32-make windows -j2 CMAKE_OPTIONS="-DCURL_LIBRARIES=C:/cmake-install/bin/libcurl.dll -DCURL_INCLUDE_DIRS=C:/cmake-install/include" From 28d6fb0191ed3a2a6442d598b877b872168ed438 Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Thu, 14 Feb 2019 12:29:46 -0500 Subject: [PATCH 20/24] Update curl build instructions --- platforms/windows/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platforms/windows/README.md b/platforms/windows/README.md index d0e5b0d00f..2c96846b02 100644 --- a/platforms/windows/README.md +++ b/platforms/windows/README.md @@ -38,7 +38,7 @@ cmake --build build --target install ``` From the curl source directory: ``` bat -cmake -H. -Bbuild -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=c:/cmake-install -DCMAKE_USE_WINSSL=ON +cmake -H. -Bbuild -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=c:/cmake-install -DBUILD_CURL_EXE=OFF -DBUILD_TESTING=OFF -DCMAKE_USE_WINSSL=ON cmake --build build cmake --build build --target install ``` From bc9b8651976af795c5a2751dda713c8bba341ba4 Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Fri, 15 Feb 2019 13:12:35 -0500 Subject: [PATCH 21/24] Update appveyor configuration - Consolidate version updates to curl/zlib. - Update `-j2` by `-j %NUMBER_OF_PROCESSORS%`, appveyor VMs might have up to 4 cores. --- .appveyor.yml | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index b26e4e74ad..6cde9e652c 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,21 +1,25 @@ +environment: + MINGW_PATH: C:\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64 + CURL_VERSION: curl-7.63.0 + ZLIB_VERSION: zlib-1.2.11 install: - - set PATH=C:\cmake-install\bin;C:cmake-install\lib;C:\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\bin;%PATH% - - appveyor DownloadFile "https://www.zlib.net/zlib-1.2.11.tar.gz" - - 7z x -o. zlib-1.2.11.tar.gz - - 7z x -oC:\cmake-install zlib-1.2.11.tar - - cd C:\cmake-install\zlib-1.2.11 + - set PATH=C:\cmake-install\bin;C:\cmake-install\lib;%MINGW_PATH%\bin;%PATH% + - appveyor DownloadFile "https://www.zlib.net/%ZLIB_VERSION%.tar.gz" + - 7z x -o. %ZLIB_VERSION%.tar.gz + - 7z x -oC:\cmake-install %ZLIB_VERSION%.tar + - cd C:\cmake-install\%ZLIB_VERSION% - cmake -H. -Bbuild -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=C:\cmake-install -DCMAKE_SH="CMAKE_SH-NOTFOUND" - - cmake --build build -- -j2 + - cmake --build build -- -j %NUMBER_OF_PROCESSORS% - cmake --build build --target install - - appveyor DownloadFile "https://curl.haxx.se/download/curl-7.63.0.tar.gz" - - 7z x -o. curl-7.63.0.tar.gz - - 7z x -oC:\cmake-install curl-7.63.0.tar - - cd C:\cmake-install\curl-7.63.0 + - appveyor DownloadFile "https://curl.haxx.se/download/%CURL_VERSION%.tar.gz" + - 7z x -o. %CURL_VERSION%.tar.gz + - 7z x -oC:\cmake-install %CURL_VERSION%.tar + - cd C:\cmake-install\%CURL_VERSION% - cmake -H. -Bbuild -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=C:\cmake-install -DBUILD_CURL_EXE=OFF -DBUILD_TESTING=OFF -DCMAKE_USE_WINSSL=ON -DCMAKE_SH="CMAKE_SH-NOTFOUND" - - cmake --build build -- -j2 + - cmake --build build -- -j %NUMBER_OF_PROCESSORS% - cmake --build build --target install - cd C:\projects\tangram-es before_build: - git submodule update --init --recursive build_script: - - mingw32-make windows -j2 CMAKE_OPTIONS="-DCURL_LIBRARIES=C:/cmake-install/bin/libcurl.dll -DCURL_INCLUDE_DIRS=C:/cmake-install/include" + - mingw32-make windows -j %NUMBER_OF_PROCESSORS% CMAKE_OPTIONS="-DCURL_LIBRARIES=C:/cmake-install/bin/libcurl.dll -DCURL_INCLUDE_DIRS=C:/cmake-install/include" \ No newline at end of file From 4a197ae4b5de04c9024b83d07575c45e87e10e3a Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Sun, 24 Feb 2019 22:01:15 -0500 Subject: [PATCH 22/24] Update readme for PATH instructions --- platforms/windows/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platforms/windows/README.md b/platforms/windows/README.md index 2c96846b02..2dec372b08 100644 --- a/platforms/windows/README.md +++ b/platforms/windows/README.md @@ -20,7 +20,7 @@ The demo application uses the Nextzen vector tile service, so you will need a Ne ## Build - The **only** supported toolchain to build Tangram ES on Windows is currently MinGW (MinGW GCC, POSIX threads). + The **only** supported toolchain to build Tangram ES on Windows is currently MinGW (MinGW GCC, POSIX threads). Once you have installed MinGW, make sure that the MinGW bin folder is added to your `PATH` environment variable. 1. Download zlib sources from https://zlib.net/ @@ -29,6 +29,7 @@ The demo application uses the Nextzen vector tile service, so you will need a Ne ### Zlib and Curl under MinGW-w64 CMake typically installs everything under Program Files, which requires elevated privileges. It is encouraged you to make dedicated directory, e.g. `c:/cmake-install`. To make it work, set `CMAKE_PREFIX_PATH` env var to this directory. The build has been tested with curl 7.63 and zlib 1.2. +Make sure that this "cmake install" bin folder is added to your `PATH` environment variable. From the zlib source directory: ``` bat From 3b348114a83383e442950cc1f548842761dfd34d Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Wed, 13 Feb 2019 00:29:36 -0500 Subject: [PATCH 23/24] Rebase Perform thorough curl error checks --- platforms/common/urlClient.cpp | 125 ++++++++++------------ platforms/common/urlClient.h | 4 - platforms/windows/src/windowsPlatform.cpp | 17 +-- platforms/windows/src/windowsPlatform.h | 2 - 4 files changed, 58 insertions(+), 90 deletions(-) diff --git a/platforms/common/urlClient.cpp b/platforms/common/urlClient.cpp index 7c542fadda..63692a6bca 100644 --- a/platforms/common/urlClient.cpp +++ b/platforms/common/urlClient.cpp @@ -5,16 +5,30 @@ #include #include #include +#include #include constexpr char const* requestCancelledError = "Request cancelled"; +#ifdef DEBUG +#define CURL_CHECK(STMT) do { CURLcode err = STMT; assert(err == CURLE_OK); } while (0) +#define CURLM_CHECK(STMT) do { \ + CURLMcode err = STMT; \ + if (err != CURLM_OK) \ + LOGE("%s", curl_multi_strerror(err)); \ + assert(err == CURLM_OK); \ + } while (0) +#else +#define CURL_CHECK(STMT) do { STMT; } while (0) +#define CURLM_CHECK(STMT) do { STMT; } while (0) +#endif + namespace Tangram { struct CurlGlobals { CurlGlobals() { LOGD("curl global init"); - curl_global_init(CURL_GLOBAL_ALL); + CURL_CHECK(curl_global_init(CURL_GLOBAL_ALL)); } ~CurlGlobals() { LOGD("curl global shutdown"); @@ -50,22 +64,23 @@ struct UrlClient::Task { Task(const Options& _options) { // Set up an easy handle for reuse. handle = curl_easy_init(); - curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, &curlWriteCallback); - curl_easy_setopt(handle, CURLOPT_WRITEDATA, this); - curl_easy_setopt(handle, CURLOPT_NOPROGRESS, 1L); - curl_easy_setopt(handle, CURLOPT_HEADER, 0L); - curl_easy_setopt(handle, CURLOPT_VERBOSE, 0L); - curl_easy_setopt(handle, CURLOPT_ACCEPT_ENCODING, "gzip"); - curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, curlErrorString); - curl_easy_setopt(handle, CURLOPT_FAILONERROR, 1L); - curl_easy_setopt(handle, CURLOPT_CONNECTTIMEOUT_MS, _options.connectionTimeoutMs); - curl_easy_setopt(handle, CURLOPT_TIMEOUT_MS, _options.requestTimeoutMs); - curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1); - curl_easy_setopt(handle, CURLOPT_MAXREDIRS, 20); - curl_easy_setopt(handle, CURLOPT_TCP_NODELAY, 1); + assert(handle != nullptr); + CURL_CHECK(curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, &curlWriteCallback)); + CURL_CHECK(curl_easy_setopt(handle, CURLOPT_WRITEDATA, this)); + CURL_CHECK(curl_easy_setopt(handle, CURLOPT_NOPROGRESS, 1L)); + CURL_CHECK(curl_easy_setopt(handle, CURLOPT_HEADER, 0L)); + CURL_CHECK(curl_easy_setopt(handle, CURLOPT_VERBOSE, 0L)); + CURL_CHECK(curl_easy_setopt(handle, CURLOPT_ACCEPT_ENCODING, "gzip")); + CURL_CHECK(curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, curlErrorString)); + CURL_CHECK(curl_easy_setopt(handle, CURLOPT_FAILONERROR, 1L)); + CURL_CHECK(curl_easy_setopt(handle, CURLOPT_CONNECTTIMEOUT_MS, _options.connectionTimeoutMs)); + CURL_CHECK(curl_easy_setopt(handle, CURLOPT_TIMEOUT_MS, _options.requestTimeoutMs)); + CURL_CHECK(curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1)); + CURL_CHECK(curl_easy_setopt(handle, CURLOPT_MAXREDIRS, 20)); + CURL_CHECK(curl_easy_setopt(handle, CURLOPT_TCP_NODELAY, 1)); #ifdef TANGRAM_WINDOWS - curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); + CURL_CHECK(curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0L)); + CURL_CHECK(curl_easy_setopt(handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4)); #endif } @@ -102,18 +117,13 @@ UrlClient::UrlClient(Options options) : m_options(options) { // Start the curl thread m_curlHandle = curl_multi_init(); + assert(m_curlHandle != nullptr); m_curlWorker = std::make_unique(&UrlClient::curlLoop, this); m_curlRunning = true; // Init at least one task to avoid checking whether m_tasks is empty in // startPendingRequests() m_tasks.emplace_back(m_options); - - // Using a pipe to notify select() in curl-thread of new requests.. - // https://www.linuxquestions.org/questions/programming-9/exit-from-blocked-pselect-661200/ - if (pipe(m_requestNotify) < 0) { - LOGE("Could not initialize select breaker!"); - } } UrlClient::~UrlClient() { @@ -137,7 +147,6 @@ UrlClient::~UrlClient() { // Stop the curl threads. m_curlRunning = false; - curlWakeUp(); m_curlWorker->join(); @@ -149,24 +158,12 @@ UrlClient::~UrlClient() { // This is probably not needed since all task have been canceled and joined for (auto& task : m_tasks) { if (task.active) { - curl_multi_remove_handle(m_curlHandle, task.handle); + CURLM_CHECK(curl_multi_remove_handle(m_curlHandle, task.handle)); } } curl_multi_cleanup(m_curlHandle); } -void UrlClient::curlWakeUp() { - - if (!m_curlNotified) { - if (write(m_requestNotify[1], "\0", 1) <= 0) { - // err - return; - } - //LOG("wake up!"); - m_curlNotified = true; - } -} - UrlClient::RequestId UrlClient::addRequest(const std::string& _url, UrlCallback _onComplete) { auto id = ++m_requestCount; @@ -179,7 +176,6 @@ UrlClient::RequestId UrlClient::addRequest(const std::string& _url, UrlCallback std::lock_guard lock(m_requestMutex); m_requests.push_back(request); } - curlWakeUp(); return id; } @@ -249,7 +245,7 @@ void UrlClient::startPendingRequests() { LOGD("Tasks %d - starting request for url: %s", int(m_activeTasks), url); - curl_multi_add_handle(m_curlHandle, task.handle); + CURLM_CHECK(curl_multi_add_handle(m_curlHandle, task.handle)); } } @@ -269,7 +265,7 @@ void UrlClient::curlLoop() { int maxfd = -1; long curl_timeo = -1; - curl_multi_timeout(m_curlHandle, &curl_timeo); + CURLM_CHECK(curl_multi_timeout(m_curlHandle, &curl_timeo)); if (curl_timeo >= 0) { timeout.tv_usec = 0; @@ -284,47 +280,38 @@ void UrlClient::curlLoop() { } else { timeout.tv_usec = (curl_timeo % 1000) * 1000; } - //printf ("Timeout %ld.%06ld\n", timeout.tv_sec, timeout.tv_usec); } - // Get file descriptors from the transfers - CURLMcode mc = curl_multi_fdset(m_curlHandle, &fdread, &fdwrite, &fdexcep, - &maxfd); - if (mc != CURLM_OK) { - LOGE("curl_multi_fdset() failed, code %d.", mc); - continue; - } - - // Listen on requestNotify to break select when new requests are added. - FD_SET(m_requestNotify[0], &fdread); + CURLM_CHECK(curl_multi_fdset(m_curlHandle, &fdread, &fdwrite, &fdexcep, &maxfd)); - // Wait for transfers - // On success the value of maxfd is guaranteed to be >= -1. We call - // select(maxfd + 1, ...); specially in case of (maxfd == -1) there are - // no fds ready yet so we call select(0, ...) to sleep 100ms, which is - // the minimum suggested value in the curl_multi_fdset() doc. - int ready = select(maxfd + 2, &fdread, &fdwrite, &fdexcep, &timeout); + int ready; + if (maxfd == -1) { +#ifdef TANGRAM_WINDOWS + Sleep(100); + ready = 0; +#else + ready = select(0, NULL, NULL, NULL, &timeout); +#endif + } else { + // Wait for transfers + // On success the value of maxfd is guaranteed to be >= -1. We call + // select(maxfd + 1, ...); specially in case of (maxfd == -1) there are + // no fds ready yet so we call select(0, ...) to sleep 100ms, which is + // the minimum suggested value in the curl_multi_fdset() doc. + ready = select(maxfd + 2, &fdread, &fdwrite, &fdexcep, &timeout); + } if (ready == -1) { LOGE("select() error!"); + assert(false); continue; - } else { - if (FD_ISSET(m_requestNotify[0], &fdread)) { - // Clear notify fd - char buffer[1]; - int n = read(m_requestNotify[0], buffer, sizeof(buffer)); - if (n <= 0) { LOGE("Read request notify %d", n); } - //LOG("Got request notifies %d %d", n, m_curlNotified); - m_curlNotified = false; - } - // Create tasks from request queue startPendingRequests(); // int activeRequests = 0; - curl_multi_perform(m_curlHandle, &activeRequests); + CURLM_CHECK(curl_multi_perform(m_curlHandle, &activeRequests)); } while (true) { @@ -336,7 +323,7 @@ void UrlClient::curlLoop() { //LOG("Messages left: %d / active %d", msgs_left, m_activeTasks); // Easy handle must be removed for reuse - curl_multi_remove_handle(m_curlHandle, msg->easy_handle); + CURLM_CHECK(curl_multi_remove_handle(m_curlHandle, msg->easy_handle)); // NB: DONE is the only defined message type. if (msg->msg != CURLMSG_DONE) { @@ -376,7 +363,7 @@ void UrlClient::curlLoop() { response.error = requestCancelledError; } else { - LOGW("Failed with error for url: %s", task.curlErrorString, url); + LOGW("Failed with error %s for url: %s", task.curlErrorString, url); response.error = task.curlErrorString; } diff --git a/platforms/common/urlClient.h b/platforms/common/urlClient.h index d22fd87c39..f57b154e52 100644 --- a/platforms/common/urlClient.h +++ b/platforms/common/urlClient.h @@ -55,7 +55,6 @@ class UrlClient { void *m_curlHandle = nullptr; bool m_curlRunning = false; - bool m_curlNotified = false; std::unique_ptr m_curlWorker; AsyncWorker m_dispatcher; @@ -70,9 +69,6 @@ class UrlClient { // RequestIds std::atomic_uint64_t m_requestCount{0}; - - // File descriptors to break waiting select. - int m_requestNotify[2] = { -1, -1 }; }; } // namespace Tangram diff --git a/platforms/windows/src/windowsPlatform.cpp b/platforms/windows/src/windowsPlatform.cpp index 4c9c1c71d2..9f2759171b 100644 --- a/platforms/windows/src/windowsPlatform.cpp +++ b/platforms/windows/src/windowsPlatform.cpp @@ -57,23 +57,10 @@ std::vector WindowsPlatform::systemFontFallbacksHandle() const } bool WindowsPlatform::startUrlRequestImpl(const Url& _url, const UrlRequestHandle _request, UrlRequestId& _id) { - if (_url.hasHttpScheme()) { - auto onRequestResponse = [this, _request](UrlResponse&& response) { - onUrlResponse(_request, std::move(response)); - }; - _id = m_urlClient->addRequest(_url.string(), onRequestResponse); - return true; - } - auto fileWorkerTask = [this, path = _url.path(), _request](){ - UrlResponse response; - auto allocator = [&](size_t size) { - response.content.resize(size); - return response.content.data(); - }; - Platform::bytesFromFileSystem(path.c_str(), allocator); + auto onURLResponse = [this, _request](UrlResponse&& response) { onUrlResponse(_request, std::move(response)); }; - m_fileWorker.enqueue(fileWorkerTask); + _id = m_urlClient->addRequest(_url.string(), onURLResponse); return false; } diff --git a/platforms/windows/src/windowsPlatform.h b/platforms/windows/src/windowsPlatform.h index c997411b1d..ad7cd91066 100644 --- a/platforms/windows/src/windowsPlatform.h +++ b/platforms/windows/src/windowsPlatform.h @@ -2,7 +2,6 @@ #include "platform.h" #include "urlClient.h" -#include "util/asyncWorker.h" namespace Tangram { @@ -21,7 +20,6 @@ class WindowsPlatform : public Platform { protected: std::unique_ptr m_urlClient; - AsyncWorker m_fileWorker; }; } // namespace Tangram From f724b369b3ac13bbbd98837b288d3830826bad36 Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Tue, 26 Feb 2019 00:30:56 -0500 Subject: [PATCH 24/24] Cleanup includes --- platforms/common/urlClient.cpp | 5 +---- platforms/common/urlClient.h | 1 - platforms/windows/src/main.cpp | 2 -- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/platforms/common/urlClient.cpp b/platforms/common/urlClient.cpp index 63692a6bca..251b16daac 100644 --- a/platforms/common/urlClient.cpp +++ b/platforms/common/urlClient.cpp @@ -4,9 +4,6 @@ #include #include #include -#include -#include -#include constexpr char const* requestCancelledError = "Request cancelled"; @@ -17,7 +14,7 @@ constexpr char const* requestCancelledError = "Request cancelled"; if (err != CURLM_OK) \ LOGE("%s", curl_multi_strerror(err)); \ assert(err == CURLM_OK); \ - } while (0) +} while (0) #else #define CURL_CHECK(STMT) do { STMT; } while (0) #define CURLM_CHECK(STMT) do { STMT; } while (0) diff --git a/platforms/common/urlClient.h b/platforms/common/urlClient.h index f57b154e52..b13e501224 100644 --- a/platforms/common/urlClient.h +++ b/platforms/common/urlClient.h @@ -45,7 +45,6 @@ class UrlClient { struct Task; void curlLoop(); - void curlWakeUp(); void startPendingRequests(); diff --git a/platforms/windows/src/main.cpp b/platforms/windows/src/main.cpp index 203b1df4fa..72de074426 100644 --- a/platforms/windows/src/main.cpp +++ b/platforms/windows/src/main.cpp @@ -3,8 +3,6 @@ #include "log.h" #include "map.h" #include -#include -#include #include // _getcwd using namespace Tangram;