diff --git a/.github/workflows/windows-ci.yml b/.github/workflows/windows-ci.yml index bb9282b6e..421a130d5 100644 --- a/.github/workflows/windows-ci.yml +++ b/.github/workflows/windows-ci.yml @@ -105,7 +105,7 @@ jobs: key: vcpkg-${{ env.VCPKG_COMMIT_ID }} - windows-build-and-test: + windows-build-and-test-msvc: needs: windows-get-or-build-dependencies strategy: matrix: @@ -238,14 +238,155 @@ jobs: - name: Run expression test run: build-windows-${{ matrix.renderer }}/expression-test/mbgl-expression-test.exe + windows-build-and-test-msys2: + if: needs.pre-job.outputs.should_skip != 'true' + needs: pre-job + strategy: + matrix: + msystem: [clang64, mingw64, ucrt64] + renderer: [opengl, egl, vulkan] + runs-on: windows-2022 + steps: + - run: | + git config --system core.longpaths true + git config --system core.autocrlf input + + - uses: actions/checkout@v4 + with: + submodules: recursive + + - uses: msys2/setup-msys2@v2 + with: + msystem: ${{ matrix.msystem }} + update: true + pacboy: >- + toolchain:p + clang:p + cmake:p + angleproject:p + curl-winssl:p + dlfcn:p + glfw:p + icu:p + libjpeg-turbo:p + libpng:p + libwebp:p + libuv:p + + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: cpp + + - uses: mozilla-actions/sccache-action@v0.0.9 + + - name: Initialize sccache + run: | + & $env:SCCACHE_PATH --start-server + & $env:SCCACHE_PATH --zero-stats + + - name: Configure MapLibre Native Core + env: + CI: 1 + CMAKE_C_COMPILER_LAUNCHER: "${{ env.SCCACHE_PATH }}" + CMAKE_CXX_COMPILER_LAUNCHER: "${{ env.SCCACHE_PATH }}" + shell: msys2 {0} + run: | + cmake --version + cmake --preset windows-${{ matrix.renderer }} -DCMAKE_POLICY_DEFAULT_CMP0141=NEW -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ + + - name: Build MapLibre Native Core + shell: msys2 {0} + run: | + cmake --build build-windows-${{ matrix.renderer }} --target mbgl-core mbgl-test-runner mbgl-render-test-runner mbgl-expression-test mbgl-render mbgl-benchmark-runner + + # CodeQL + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:cpp" + + - name: Download Mesa3D + run: | + (Invoke-WebRequest https://api.github.com/repos/pal1000/mesa-dist-win/releases -Headers @{ Authorization = ('Bearer {0}' -f '${{ secrets.GITHUB_TOKEN }}') } | ConvertFrom-Json)[0].assets | Where-Object name -match 'mesa3d-.+-release-msvc\.7z' | foreach { Invoke-WebRequest $_.browser_download_url -OutFile mesa3d.7z } + + - name: Extract Mesa3D files for OpenGL + if: matrix.renderer != 'vulkan' + run: | + & 'C:\Program Files\7-Zip\7z.exe' e -obuild-windows-${{ matrix.renderer }} .\mesa3d.7z x64\libgallium_wgl.dll x64\libGLESv2.dll + + - name: Extract Mesa3D files for Vulkan + if: matrix.renderer == 'vulkan' + run: | + & 'C:\Program Files\7-Zip\7z.exe' e -obuild-windows-${{ matrix.renderer }} .\mesa3d.7z x64\lvp_icd.x86_64.json x64\vulkan_lvp.dll + + # unit tests + + - name: Configure Mesa3D drivers (OpenGL) + if: matrix.renderer != 'vulkan' + run: | + reg add 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\OpenGLDrivers\MSOGL' /v DLL /t REG_SZ /d ('{0}\build-windows-${{ matrix.renderer }}\libgallium_wgl.dll' -f $PWD.Path) /f + reg add 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\OpenGLDrivers\MSOGL' /v DriverVersion /t REG_DWORD /d 1 /f + reg add 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\OpenGLDrivers\MSOGL' /v Flags /t REG_DWORD /d 1 /f + reg add 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\OpenGLDrivers\MSOGL' /v Version /t REG_DWORD /d 2 /f + Add-Content -Path $env:GITHUB_ENV -Value 'GALLIUM_DRIVER=llvmpipe' + + - name: Configure Mesa3D drivers (Vulkan) + if: matrix.renderer == 'vulkan' + run: | + reg add 'HKLM\Software\Khronos\Vulkan\Drivers' /f /v '${{ github.workspace }}\build-windows-${{ matrix.renderer }}\lvp_icd.x86_64.json' /t REG_DWORD /d 0 + + - name: Download and configure Vulkan + if: matrix.renderer == 'vulkan' + run: | + # 1.4.313.1 doesn't have runtime components? + # $version = (Invoke-WebRequest -Uri "https://vulkan.lunarg.com/sdk/latest.json" | ConvertFrom-Json).windows + $version = '1.4.313.0' + Invoke-WebRequest https://sdk.lunarg.com/sdk/download/$version/windows/VulkanRT-X64-$version-Components.zip -OutFile VulkanRT.zip + & 'C:\Program Files\7-Zip\7z.exe' e -obuild-windows-${{ matrix.renderer }} -r .\VulkanRT.zip *x64\vulkan-1.* + + - name: Run C++ tests + continue-on-error: ${{ matrix.renderer == 'vulkan' }} + env: + ANGLE_DEFAULT_PLATFORM: 'gl' + GALLIUM_DRIVER: llvmpipe + LIBGL_ALWAYS_SOFTWARE: true + run: build-windows-${{ matrix.renderer }}/mbgl-test-runner.exe + + # render tests + + - name: Run render test + id: render_test + env: + manifest_file: ${{ matrix.renderer }} + ANGLE_DEFAULT_PLATFORM: 'gl' + GALLIUM_DRIVER: llvmpipe + LIBGL_ALWAYS_SOFTWARE: true + run: build-windows-${{ matrix.renderer }}/mbgl-render-test-runner.exe "--manifestPath=metrics/windows-${env:manifest_file}.json" + + - name: Upload render test result + if: always() && steps.render_test.outcome == 'failure' + uses: actions/upload-artifact@v4 + with: + name: render-test-result-${{ matrix.renderer }} + path: | + metrics/windows-${{ matrix.renderer }}.html + + # expression tests + + - name: Run expression test + run: build-windows-${{ matrix.renderer }}/expression-test/mbgl-expression-test.exe + windows-ci-result: name: Windows CI Result if: needs.pre-job.outputs.should_skip != 'true' && always() runs-on: windows-2022 needs: - pre-job - - windows-build-and-test + - windows-build-and-test-msvc + - windows-build-and-test-msys2 steps: - name: Mark result as failed - if: needs.windows-build-and-test.result != 'success' + if: needs.windows-build-and-test-msvc.result != 'success' || needs.windows-build-and-test-msys2.result != 'success' run: exit 1 diff --git a/CMakeLists.txt b/CMakeLists.txt index eafae983a..6f24a62dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,7 +44,7 @@ if (MLN_WITH_QT AND NOT CMAKE_OSX_DEPLOYMENT_TARGET) set(CMAKE_OSX_DEPLOYMENT_TARGET 13.0) endif() -if(WIN32 AND NOT MLN_WITH_QT AND NOT CMAKE_SYSTEM_NAME STREQUAL Android) +if(WIN32 AND NOT DEFINED ENV{MSYSTEM} AND NOT MLN_WITH_QT AND NOT CMAKE_SYSTEM_NAME STREQUAL Android) set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/platform/windows/custom-toolchain.cmake) endif() diff --git a/docs/mdbook/src/SUMMARY.md b/docs/mdbook/src/SUMMARY.md index 2cd413ae8..4aeb0e96a 100644 --- a/docs/mdbook/src/SUMMARY.md +++ b/docs/mdbook/src/SUMMARY.md @@ -16,6 +16,9 @@ - [macOS](./platforms/macos/README.md) - [Linux](./platforms/linux/README.md) - [Using Docker](./platforms/linux/using-docker.md) + - [Windows](./platforms/windows/README.md) + - [Building with Microsoft Visual Studio](./platforms/windows/build-msvc.md) + - [Building with MSYS2](./platforms/windows/build-msys2.md) - [Release Policy](./release-policy.md) diff --git a/docs/mdbook/src/platforms/windows/README.md b/docs/mdbook/src/platforms/windows/README.md new file mode 100644 index 000000000..f9df15033 --- /dev/null +++ b/docs/mdbook/src/platforms/windows/README.md @@ -0,0 +1,7 @@ +# Windows + +This is a port to add Windows support on other targets (Node, GLFW, etc). + +The files produced by building mbgl-core target can be reused as libraries in other projects. + +Building with [Microsoft Visual Studio](./build-msvc.md) and [MSYS2](./build-msys2.md) are supported. diff --git a/docs/mdbook/src/platforms/windows/build-msvc.md b/docs/mdbook/src/platforms/windows/build-msvc.md new file mode 100644 index 000000000..de4cfa580 --- /dev/null +++ b/docs/mdbook/src/platforms/windows/build-msvc.md @@ -0,0 +1,156 @@ +# Building with Microsoft Visual Studio + +## Prerequisites + +The build was tested with `Microsoft Visual Studio 2022`. Earlier versions are not guaranteed to work, but `Microsoft Visual Studio 2019` might work as well. + +To install the required Visual Studio components, open Visual Studio Installer and check `Desktop Development with C++` option. Make sure `C++ CMake tools for Windows` is selected in the right pane. If `git` is not already installed, select `Git for Windows` option in `Individual Components`. When Visual Studio finishes the install process, everything is ready to start. + +## Downloading sources + +Open `x64 Native Tools Command Prompt for VS 2022` and then clone the repository: + +```cmd +git clone --config core.longpaths=true --depth 1 --recurse-submodules -j8 https://github.com/maplibre/maplibre-native.git +cd maplibre-native +``` + +> [!NOTE] +> The `core.longpaths=true` config is necessary, because without it a lot of `Filename too long` messages will come. If you have this configuration set globally (`git config --system core.longpaths=true`), you can omit the `--config core.longpaths=true` portion of the clone command. + +## Configuring + +Configure the build with the following command, replacing `` with `opengl`, `egl` or `vulkan`, which are the rendering engines you can use. If you don't know which one to choose, just use `opengl`: + +```cmd +cmake --preset windows- +``` + +It will take some time to build and install all components on which Maplibre depends. + +## Building + +Finally, build the project with the following command, again replacing `` with the value you choose in the configure step: + +```cmd +cmake --build build-windows- +``` + +## Building with Microsoft Visual Studio + +Just add the `-G "Microsoft Visual Studio 17 2022"` (or the corresponding Visual Studio version you have) option from the configure command: + +```cmd +cmake --preset windows- -G "Microsoft Windows 2022" +``` + +Once configure is done, open the file `build-windows-\Mapbox GL Native.sln`. Build the target `ALL_BUILD` to build all targets, or pick a specific target. Don't forget to pick a build configuration (`Release`, `RelWithDebInfo`, `MinSizeRel` or `Debug`), otherwise the project will be built with default configuration (`Debug`). + +## Testing + +If all went well and target `mbgl-render` or `ALL_BUILD` was chosen, there should now be a `build-windows-\bin\mbgl-render.exe` binary that you can run to generate map tile images. To test that it is working properly, run the following command. + +```cmd +.\build-windows-\bin\mbgl-render.exe --style https://raw.githubusercontent.com/maplibre/demotiles/gh-pages/style.json --output out.png +``` + +This should produce an `out.png` map tile image with the default MapLibre styling from [the MapLibre demo](https://maplibre.org/maplibre-gl-js/docs/examples/display-a-map/). + +![Sample image of world from mbgl-render command](images/sample-maplibre-style-mbgl-render-out.png) + +### Using your own style/tiles + +You can also use the `mbgl-render` command to render images from your own style or tile set. To do so, you will need a data source and a style JSON file. + +For the purposes of this exercise, you can use the `zurich_switzerland.mbtiles` from [here](https://github.com/acalcutt/tileserver-gl/releases/download/test_data/zurich_switzerland.mbtiles), and the following `style.json` file. + +```json +{ + "version": 8, + "name": "Test style", + "center": [ + 8.54806714892635, + 47.37180823552663 + ], + "sources": { + "test": { + "type": "vector", + "url": "mbtiles:///path/to/zurich_switzerland.mbtiles" + } + }, + "layers": [ + { + "id": "background", + "type": "background", + "paint": { + "background-color": "hsl(47, 26%, 88%)" + } + }, + { + "id": "water", + "type": "fill", + "source": "test", + "source-layer": "water", + "filter": [ + "==", + "$type", + "Polygon" + ], + "paint": { + "fill-color": "hsl(205, 56%, 73%)" + } + }, + { + "id": "admin_country", + "type": "line", + "source": "test", + "source-layer": "boundary", + "filter": [ + "all", + [ + "<=", + "admin_level", + 2 + ], + [ + "==", + "$type", + "LineString" + ] + ], + "layout": { + "line-cap": "round", + "line-join": "round" + }, + "paint": { + "line-color": "hsla(0, 8%, 22%, 0.51)", + "line-width": { + "base": 1.3, + "stops": [ + [ + 3, + 0.5 + ], + [ + 22, + 15 + ] + ] + } + } + } + ] +} +``` + +Note that this style is totally inadequate for any real use beyond testing your custom setup. Don't forget to replace the source URL `"mbtiles:///path/to/zurich_switzerland.mbtiles"` with the actual path to your mbtiles file. + +From your `maplibre-native` dir, run the following command. + +```cmd +.\build-windows-\bin\mbgl-render.exe --style path\to\style.json --output out.png +``` + +This should produce an `out.png` image in your current directory with a barebones image of the world. + +![Sample image of world from mbgl-render command](images/sample-barebones-mbgl-render-out.png) diff --git a/docs/mdbook/src/platforms/windows/build-msys2.md b/docs/mdbook/src/platforms/windows/build-msys2.md new file mode 100644 index 000000000..3a559bd69 --- /dev/null +++ b/docs/mdbook/src/platforms/windows/build-msys2.md @@ -0,0 +1,160 @@ +# Building with MSYS2 + +## Prerequisites + +You must have [`MSYS2`](https://www.msys2.org/) installed. Then launch an window, which can be `UCRT64`, `CLANG64`, `CLANGARM64` or `MINGW64`. + +You need to install the required packages: + +```sh +pacman -S --needed \ + git \ + ${MINGW_PACKAGE_PREFIX}-toolchain \ + ${MINGW_PACKAGE_PREFIX}-clang \ + ${MINGW_PACKAGE_PREFIX}-cmake \ + ${MINGW_PACKAGE_PREFIX}-angleproject \ + ${MINGW_PACKAGE_PREFIX}-curl-winssl \ + ${MINGW_PACKAGE_PREFIX}-dlfcn \ + ${MINGW_PACKAGE_PREFIX}-glfw \ + ${MINGW_PACKAGE_PREFIX}-icu \ + ${MINGW_PACKAGE_PREFIX}-libjpeg-turbo \ + ${MINGW_PACKAGE_PREFIX}-libpng \ + ${MINGW_PACKAGE_PREFIX}-libwebp \ + ${MINGW_PACKAGE_PREFIX}-libuv +``` + +Then everything is ready to start. + +## Downloading sources + +Just clone the repository: + +```sh +git clone --depth 1 --recurse-submodules -j8 https://github.com/maplibre/maplibre-native.git +cd maplibre-native +``` + +## Configuring + +Configure the build with the following command, replacing `` with `opengl`, `egl` or `vulkan`, which are the rendering engines you can use. If you don't know which one to choose, just use `opengl`: + +```sh +cmake --preset windows- -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ +``` + +## Building + +Finally, build the project with the following command, again replacing `` with the value you choose in the configure step: + +```sh +cmake --build build-windows- +``` + +## Testing + +If all went well and target `mbgl-render` or `ALL_BUILD` was chosen, there should now be a `build-windows-/bin/mbgl-render.exe` binary that you can run to generate map tile images. To test that it is working properly, run the following command. + +```sh +./build-windows-/bin/mbgl-render.exe --style https://raw.githubusercontent.com/maplibre/demotiles/gh-pages/style.json --output out.png +``` + +This should produce an `out.png` map tile image with the default MapLibre styling from [the MapLibre demo](https://maplibre.org/maplibre-gl-js/docs/examples/display-a-map/). + +![Sample image of world from mbgl-render command](images/sample-maplibre-style-mbgl-render-out.png) + +### Using your own style/tiles + +You can also use the `mbgl-render` command to render images from your own style or tile set. To do so, you will need a data source and a style JSON file. + +For the purposes of this exercise, you can use the `zurich_switzerland.mbtiles` from [here](https://github.com/acalcutt/tileserver-gl/releases/download/test_data/zurich_switzerland.mbtiles), and the following `style.json` file. + +```json +{ + "version": 8, + "name": "Test style", + "center": [ + 8.54806714892635, + 47.37180823552663 + ], + "sources": { + "test": { + "type": "vector", + "url": "mbtiles:///path/to/zurich_switzerland.mbtiles" + } + }, + "layers": [ + { + "id": "background", + "type": "background", + "paint": { + "background-color": "hsl(47, 26%, 88%)" + } + }, + { + "id": "water", + "type": "fill", + "source": "test", + "source-layer": "water", + "filter": [ + "==", + "$type", + "Polygon" + ], + "paint": { + "fill-color": "hsl(205, 56%, 73%)" + } + }, + { + "id": "admin_country", + "type": "line", + "source": "test", + "source-layer": "boundary", + "filter": [ + "all", + [ + "<=", + "admin_level", + 2 + ], + [ + "==", + "$type", + "LineString" + ] + ], + "layout": { + "line-cap": "round", + "line-join": "round" + }, + "paint": { + "line-color": "hsla(0, 8%, 22%, 0.51)", + "line-width": { + "base": 1.3, + "stops": [ + [ + 3, + 0.5 + ], + [ + 22, + 15 + ] + ] + } + } + } + ] +} +``` + +Note that this style is totally inadequate for any real use beyond testing your custom setup. Don't forget to replace the source URL `"mbtiles:///path/to/zurich_switzerland.mbtiles"` with the actual path to your mbtiles file. + +From your `maplibre-native/` dir, run the following command. + +```sh +./build-windows-/bin/mbgl-render.exe --style path/to/style.json --output out.png +``` + +This should produce an `out.png` image in your current directory with a barebones image of the world. + +![Sample image of world from mbgl-render command](images/sample-barebones-mbgl-render-out.png) diff --git a/docs/mdbook/src/platforms/windows/images/sample-barebones-mbgl-render-out.png b/docs/mdbook/src/platforms/windows/images/sample-barebones-mbgl-render-out.png new file mode 100644 index 000000000..49d9df592 Binary files /dev/null and b/docs/mdbook/src/platforms/windows/images/sample-barebones-mbgl-render-out.png differ diff --git a/docs/mdbook/src/platforms/windows/images/sample-maplibre-style-mbgl-render-out.png b/docs/mdbook/src/platforms/windows/images/sample-maplibre-style-mbgl-render-out.png new file mode 100644 index 000000000..896ec6a11 Binary files /dev/null and b/docs/mdbook/src/platforms/windows/images/sample-maplibre-style-mbgl-render-out.png differ diff --git a/platform/node/CMakeLists.txt b/platform/node/CMakeLists.txt index 3774b3678..311bfc96a 100644 --- a/platform/node/CMakeLists.txt +++ b/platform/node/CMakeLists.txt @@ -1,6 +1,10 @@ set(NODE_MODULE_MINIMUM_ABI 83) # Minimum supported Node.js version: 14 set(NODE_MODULE_CACHE_DIR ${CMAKE_BINARY_DIR}/headers) +if(DEFINED ENV{MSYSTEM}) + message(FATAL "MSYS2 is not supported, Node.js in Windows only has binary compatibility with Microsoft Visual C++.") +endif() + include(${CMAKE_CURRENT_LIST_DIR}/cmake/module.cmake) add_node_module( diff --git a/platform/windows/src/gl_functions.cpp b/platform/windows/src/gl_functions.cpp index 230e53530..f98e6ab89 100644 --- a/platform/windows/src/gl_functions.cpp +++ b/platform/windows/src/gl_functions.cpp @@ -1,5 +1,3 @@ -#pragma once - #include #ifndef GL_GLEXT_PROTOTYPES diff --git a/platform/windows/src/headless_backend_wgl.cpp b/platform/windows/src/headless_backend_wgl.cpp index e2562c19f..49db16116 100644 --- a/platform/windows/src/headless_backend_wgl.cpp +++ b/platform/windows/src/headless_backend_wgl.cpp @@ -1,5 +1,3 @@ -#pragma once - #include #include diff --git a/platform/windows/src/thread.cpp b/platform/windows/src/thread.cpp index 9c1b597c7..19e7f28a0 100644 --- a/platform/windows/src/thread.cpp +++ b/platform/windows/src/thread.cpp @@ -1,5 +1,3 @@ -#pragma once - #include #include #include @@ -11,6 +9,7 @@ DWORD selfThreadKey; DummyClassThread dummyClassThread; +#ifdef _MSC_VER // https://learn.microsoft.com/en-us/visualstudio/debugger/how-to-set-a-thread-name-in-native-code?view=vs-2022 void SetThreadName(DWORD dwThreadID, const char* threadName) { THREADNAME_INFO info; @@ -27,6 +26,7 @@ void SetThreadName(DWORD dwThreadID, const char* threadName) { } #pragma warning(pop) } +#endif THREAD_INFO* GetCurrentThreadInfo() { THREAD_INFO* info = (THREAD_INFO*)TlsGetValue(selfThreadKey); @@ -57,6 +57,7 @@ std::string getCurrentThreadName() { } void setCurrentThreadName(const std::string& name) { +#ifdef _MSC_VER THREAD_INFO* info = GetCurrentThreadInfo(); if (info && info->name) { @@ -66,6 +67,7 @@ void setCurrentThreadName(const std::string& name) { } SetThreadName(-1, name.c_str()); +#endif } void makeThreadLowPriority() { diff --git a/platform/windows/src/thread_local.cpp b/platform/windows/src/thread_local.cpp index 66c9f1efb..ae5fa65cc 100644 --- a/platform/windows/src/thread_local.cpp +++ b/platform/windows/src/thread_local.cpp @@ -1,5 +1,3 @@ -#pragma once - #include #include #include diff --git a/platform/windows/windows.cmake b/platform/windows/windows.cmake index d44ebb73b..24ebae32a 100644 --- a/platform/windows/windows.cmake +++ b/platform/windows/windows.cmake @@ -1,36 +1,56 @@ -if(MLN_WITH_EGL) - set(_RENDERER EGL) -elseif(MLN_WITH_VULKAN) - set(_RENDERER Vulkan) +if(MSVC) + if(MLN_WITH_EGL) + set(_RENDERER EGL) + elseif(MLN_WITH_VULKAN) + set(_RENDERER Vulkan) + else() + set(_RENDERER OpenGL) + endif() + + if(NOT MLN_USE_BUILTIN_ICU) + set(WITH_ICU -With-ICU) + endif() + + execute_process(COMMAND powershell -ExecutionPolicy Bypass -File ${CMAKE_CURRENT_LIST_DIR}/Get-VendorPackages.ps1 -Triplet ${VCPKG_TARGET_TRIPLET} -Renderer ${_RENDERER} ${WITH_ICU}) + unset(_RENDERER) + + add_compile_definitions(NOMINMAX GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE) + + target_compile_options( + mbgl-compiler-options + INTERFACE + /MP + ) + + find_package(CURL REQUIRED) + find_package(dlfcn-win32 REQUIRED) + find_package(ICU OPTIONAL_COMPONENTS i18n uc) + find_package(JPEG REQUIRED) + find_package(libuv REQUIRED) + find_package(PNG REQUIRED) + find_package(WebP REQUIRED) + find_path(DLFCN_INCLUDE_DIRS dlfcn.h) + find_path(LIBUV_INCLUDE_DIRS uv.h) +elseif(DEFINED ENV{MSYSTEM}) + set(MSYS 1) + set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") + set(BUILD_SHARED_LIBS OFF) + set(CMAKE_EXE_LINKER_FLAGS "-static") + + add_compile_definitions(WIN32 GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE) + + find_package(ICU OPTIONAL_COMPONENTS i18n uc data) + find_package(JPEG REQUIRED) + find_package(PNG REQUIRED) + find_package(PkgConfig REQUIRED) + + pkg_search_module(WEBP libwebp REQUIRED) + pkg_search_module(LIBUV libuv REQUIRED) + pkg_search_module(CURL libcurl REQUIRED) else() - set(_RENDERER OpenGL) + message(FATAL_ERROR "Unsupported build system: " ${CMAKE_SYSTEM_NAME}) endif() -if(NOT MLN_USE_BUILTIN_ICU) - set(WITH_ICU -With-ICU) -endif() - -execute_process(COMMAND powershell -ExecutionPolicy Bypass -File ${CMAKE_CURRENT_LIST_DIR}/Get-VendorPackages.ps1 -Triplet ${VCPKG_TARGET_TRIPLET} -Renderer ${_RENDERER} ${WITH_ICU}) -unset(_RENDERER) - -add_compile_definitions(NOMINMAX GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE) - -target_compile_options( - mbgl-compiler-options - INTERFACE - $<$:/MP> -) - -find_package(CURL REQUIRED) -find_package(dlfcn-win32 REQUIRED) -find_package(ICU OPTIONAL_COMPONENTS i18n uc) -find_package(JPEG REQUIRED) -find_package(libuv REQUIRED) -find_package(PNG REQUIRED) -find_package(WebP REQUIRED) -find_path(DLFCN_INCLUDE_DIRS dlfcn.h) -find_path(LIBUV_INCLUDE_DIRS uv.h) - target_sources( mbgl-core PRIVATE @@ -91,7 +111,25 @@ if(MLN_WITH_OPENGL) endif() if(MLN_WITH_EGL) - find_package(unofficial-angle CONFIG REQUIRED) + if(MSVC) + find_package(unofficial-angle CONFIG REQUIRED) + + target_link_libraries( + mbgl-core + PRIVATE + unofficial::angle::libEGL + unofficial::angle::libGLESv2 + ) + elseif(MSYS) + pkg_search_module(EGL angleproject REQUIRED) + + target_link_libraries( + mbgl-core + PRIVATE + ${EGL_LIBRARIES} + ) + endif() + target_sources( mbgl-core PRIVATE @@ -103,13 +141,12 @@ if(MLN_WITH_EGL) PRIVATE KHRONOS_STATIC ) - target_link_libraries( - mbgl-core - PRIVATE - unofficial::angle::libEGL - unofficial::angle::libGLESv2 - ) elseif(MLN_WITH_VULKAN) + target_include_directories( + mbgl-core + PRIVATE + ${PROJECT_SOURCE_DIR}/vendor/Vulkan-Headers/include + ) target_sources( mbgl-core PRIVATE @@ -184,16 +221,34 @@ if(NOT ${ICU_FOUND} OR "${ICU_VERSION}" VERSION_LESS 62.0 OR MLN_USE_BUILTIN_ICU PRIVATE ${PROJECT_SOURCE_DIR}/vendor/icu/include ) +elseif(MSYS) + target_compile_definitions( + mbgl-core + PRIVATE + U_STATIC_IMPLEMENTATION + ) +endif() + +if(MSVC) + target_link_libraries( + mbgl-core + PRIVATE + ${CURL_LIBRARIES} + dlfcn-win32::dl + ) +elseif(MSYS) + target_link_libraries( + mbgl-core + PRIVATE + ${CURL_STATIC_LIBRARIES} + ) endif() target_link_libraries( mbgl-core PRIVATE - ${CURL_LIBRARIES} ${JPEG_LIBRARIES} - ${LIBUV_LIBRARIES} ${WEBP_LIBRARIES} - dlfcn-win32::dl $<$>:ICU::i18n> $<$>:ICU::uc> $<$>:ICU::data> @@ -210,6 +265,18 @@ if(MLN_WITH_GLFW) endif() if(MLN_WITH_NODE) add_subdirectory(${PROJECT_SOURCE_DIR}/platform/node) +elseif(MSVC) + target_link_libraries( + mbgl-core + PRIVATE + $,libuv::uv_a,libuv::uv> + ) +elseif(MSYS) + target_link_libraries( + mbgl-core + PRIVATE + ${LIBUV_LIBRARIES} + ) endif() add_executable( @@ -243,9 +310,16 @@ target_link_libraries( PRIVATE mbgl-compiler-options $ - $,libuv::uv_a,libuv::uv> ) +if(MSVC) + target_link_libraries( + mbgl-test-runner + PRIVATE + $,libuv::uv_a,libuv::uv> + ) +endif() + add_executable( mbgl-benchmark-runner ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/benchmark/main.cpp @@ -256,9 +330,16 @@ target_link_libraries( PRIVATE mbgl-compiler-options $ - $,libuv::uv_a,libuv::uv> ) +if(MSVC) + target_link_libraries( + mbgl-benchmark-runner + PRIVATE + $,libuv::uv_a,libuv::uv> + ) +endif() + add_executable( mbgl-render-test-runner ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/render-test/main.cpp @@ -269,14 +350,23 @@ target_link_libraries( PRIVATE mbgl-compiler-options mbgl-render-test - $,libuv::uv_a,libuv::uv> ) -target_link_libraries( - mbgl-expression-test - PRIVATE - $,libuv::uv_a,libuv::uv> -) +if(MSVC) + target_link_libraries( + mbgl-render-test-runner + PRIVATE + $,libuv::uv_a,libuv::uv> + ) +endif() + +if(MSVC) + target_link_libraries( + mbgl-expression-test + PRIVATE + $,libuv::uv_a,libuv::uv> + ) +endif() # Disable benchmarks in CI as they run in VM environment if(NOT DEFINED ENV{CI}) diff --git a/render-test/runner.cpp b/render-test/runner.cpp index ddf00b023..9b1bb36b3 100644 --- a/render-test/runner.cpp +++ b/render-test/runner.cpp @@ -828,8 +828,15 @@ void TestRunner::run(TestMetadata& metadata) { #if defined(__clang__) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" +#endif +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif static std::wstring_convert, char16_t> cv; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif #if defined(__clang__) #pragma clang diagnostic pop #endif diff --git a/src/mbgl/util/chrono.cpp b/src/mbgl/util/chrono.cpp index ad42852af..a4b8e60df 100644 --- a/src/mbgl/util/chrono.cpp +++ b/src/mbgl/util/chrono.cpp @@ -45,7 +45,8 @@ std::string iso8601(Timestamp timestamp) { std::tm info; _gmtime(&time, &info); char buffer[30]; - std::strftime(buffer, sizeof(buffer), "%F %T", &info); + // %F and %T are not supported in MinGW (https://sourceforge.net/p/mingw-w64/bugs/793/) + std::strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", &info); return buffer; } @@ -59,7 +60,8 @@ std::string iso8601(std::chrono::time_point #include -#ifdef __GNUC__ +#if defined(__GNUC__) && !defined(WIN32) #define MBGL_FOPEN_MODE_WBE "wbe" #else #define MBGL_FOPEN_MODE_WBE "wb" diff --git a/test/storage/local_file_source.test.cpp b/test/storage/local_file_source.test.cpp index e0e6c211b..bd26efaa0 100644 --- a/test/storage/local_file_source.test.cpp +++ b/test/storage/local_file_source.test.cpp @@ -179,8 +179,8 @@ TEST(LocalFileSource, URLLimit) { std::unique_ptr req = fs.request({Resource::Unknown, toAbsoluteURL(url)}, [&](Response res) { req.reset(); ASSERT_NE(nullptr, res.error); -#if defined(_MSC_VER) && !defined(__clang__) - // Microsoft Visual Studio defines PATH_MAX as 260, less than the +#if defined(WIN32) + // MSYS2 and Microsoft Visual Studio defines PATH_MAX as 260, less than the // limit to trigger an error with reason "Other" EXPECT_EQ(Response::Error::Reason::NotFound, res.error->reason); #else diff --git a/test/style/style_parser.test.cpp b/test/style/style_parser.test.cpp index 4acfce448..c7d7b91bd 100644 --- a/test/style/style_parser.test.cpp +++ b/test/style/style_parser.test.cpp @@ -14,8 +14,8 @@ #include #include -#if defined(WIN32) && !defined(__clang__) -#include +#if defined(WIN32) +#include #ifdef GetObject #undef GetObject #endif @@ -100,7 +100,7 @@ static void populateNames(std::vector& names) { } }; -#if defined(WIN32) && !defined(__clang__) +#if defined(WIN32) style_directory += "/*"; WIN32_FIND_DATAA ffd; HANDLE hFind = FindFirstFileA(style_directory.c_str(), &ffd); diff --git a/vendor/benchmark.cmake b/vendor/benchmark.cmake index 427254d65..b54ceda5b 100644 --- a/vendor/benchmark.cmake +++ b/vendor/benchmark.cmake @@ -38,7 +38,8 @@ if(WIN32) target_link_libraries( mbgl-vendor-benchmark - PRIVATE shlwapi + PRIVATE + $,shlwapi,-lShlwapi> ) endif()