From 48f20ffe5faf9fed0038b21cbd0af2d248c03c2d Mon Sep 17 00:00:00 2001 From: Chachay Date: Sun, 18 Feb 2018 22:20:45 +0900 Subject: [PATCH 1/5] Update windows/VS2017 support --- contrib/CMakeLists.txt | 8 ++++++-- contrib/README.md | 15 ++++++++++++++- contrib/WinBuild.cmd | 23 +++++++++++++++++++---- examples/xkcd.cpp | 3 ++- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index ba14b86..9bb8db1 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -1,10 +1,11 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.7) project (MatplotlibCPP_Test) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) include_directories(${PYTHONHOME}/include) +include_directories(${PYTHONHOME}/Lib/site-packages/numpy/core/include) link_directories(${PYTHONHOME}/libs) add_definitions(-DMATPLOTLIBCPP_PYTHON_HEADER=Python.h) @@ -12,10 +13,13 @@ add_definitions(-DMATPLOTLIBCPP_PYTHON_HEADER=Python.h) # message(STATUS "*** dump start cmake variables ***") # get_cmake_property(_variableNames VARIABLES) # foreach(_variableName ${_variableNames}) - # message(STATUS "${_variableName}=${${_variableName}}") +# message(STATUS "${_variableName}=${${_variableName}}") # endforeach() # message(STATUS "*** dump end ***") add_executable(minimal ${CMAKE_CURRENT_SOURCE_DIR}/../examples/minimal.cpp) add_executable(basic ${CMAKE_CURRENT_SOURCE_DIR}/../examples/basic.cpp) add_executable(modern ${CMAKE_CURRENT_SOURCE_DIR}/../examples/modern.cpp) +add_executable(animation ${CMAKE_CURRENT_SOURCE_DIR}/../examples/animation.cpp) +add_executable(nonblock ${CMAKE_CURRENT_SOURCE_DIR}/../examples/nonblock.cpp) +add_executable(xkcd ${CMAKE_CURRENT_SOURCE_DIR}/../examples/xkcd.cpp) diff --git a/contrib/README.md b/contrib/README.md index efc0a50..0af8515 100644 --- a/contrib/README.md +++ b/contrib/README.md @@ -8,12 +8,25 @@ contributors are not required to and may be unable to check whether their changes break any of them. ## Windows support +Tested on the following environment +* Windows 10 - 64bit +* Anaconda 4.3 (64 bit) +* Python 3.6.0 +* CMake 3.9.4 +* Visual Studio 2017, 2015, 2013 ### Configuring and Building Samples +1. Edit WinBuild.cmd for your environment(Line:5-7) + if NOT DEFINED MSVC_VERSION set MSVC_VERSION=[Your Visual Studio Version(12, 14, 15)] + if NOT DEFINED CMAKE_CONFIG set CMAKE_CONFIG=Release + if NOT DEFINED PYTHONHOME set PYTHONHOME=[Your Python Path] +2. Run WinBuild.cmd to build ```cmd > cd contrib > WinBuild.cmd ``` - The `WinBuild.cmd` will set up temporal ENV variables and build binaries in (matplotlib root)/examples with the Release configuration. + +3. Find exe files in examples/build/Release +Note: platforms folder is necessary to make qt works. diff --git a/contrib/WinBuild.cmd b/contrib/WinBuild.cmd index 4e3b450..9dfd627 100644 --- a/contrib/WinBuild.cmd +++ b/contrib/WinBuild.cmd @@ -1,9 +1,14 @@ @echo off @setlocal EnableDelayedExpansion -if NOT DEFINED MSVC_VERSION set MSVC_VERSION=14 +REM ------Set Your Environment------------------------------- +if NOT DEFINED MSVC_VERSION set MSVC_VERSION=15 if NOT DEFINED CMAKE_CONFIG set CMAKE_CONFIG=Release if NOT DEFINED PYTHONHOME set PYTHONHOME=C:/Users/%username%/Anaconda3 +REM --------------------------------------------------------- + +set KEY_NAME="HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\SxS\VS7" +set VALUE_NAME=15.0 if "%MSVC_VERSION%"=="14" ( if "%processor_architecture%" == "AMD64" ( @@ -14,13 +19,23 @@ if "%MSVC_VERSION%"=="14" ( ) else if "%MSVC_VERSION%"=="12" ( if "%processor_architecture%" == "AMD64" ( set CMAKE_GENERATOR=Visual Studio 12 2013 Win64 - ) else ( set CMAKE_GENERATOR=Visual Studio 12 2013 ) +) else if "%MSVC_VERSION%"=="15" ( + if "%processor_architecture%" == "AMD64" ( + set CMAKE_GENERATOR=Visual Studio 15 2017 Win64 + ) else ( + set CMAKE_GENERATOR=Visual Studio 15 2017 + ) +) +if "%MSVC_VERSION%"=="15" ( + for /F "usebackq tokens=1,2,*" %%A in (`REG QUERY %KEY_NAME% /v %VALUE_NAME%`) do ( + set batch_file=%%CVC\Auxiliary\Build\vcvarsall.bat + ) +) else ( + set batch_file=!VS%MSVC_VERSION%0COMNTOOLS!..\..\VC\vcvarsall.bat ) - -set batch_file=!VS%MSVC_VERSION%0COMNTOOLS!..\..\VC\vcvarsall.bat call "%batch_file%" %processor_architecture% pushd .. diff --git a/examples/xkcd.cpp b/examples/xkcd.cpp index 9bf6454..fa41cfc 100644 --- a/examples/xkcd.cpp +++ b/examples/xkcd.cpp @@ -1,6 +1,7 @@ +#define _USE_MATH_DEFINES +#include #include "../matplotlibcpp.h" #include -#include namespace plt = matplotlibcpp; From 36e044c6b5c29466c6f863916817c917f352e682 Mon Sep 17 00:00:00 2001 From: Chachay Date: Tue, 23 Jun 2020 23:42:04 +0200 Subject: [PATCH 2/5] Add vs2019 support and appveyor CI --- README.md | 2 ++ appveyor.yml | 31 +++++++++++++++++++++++++++++++ contrib/WinBuild.cmd | 27 +++++++++++++++++++-------- 3 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 appveyor.yml diff --git a/README.md b/README.md index 61ffef4..6a24799 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ matplotlib-cpp ============== +[![Build status](https://ci.appveyor.com/api/projects/status/qcv0r9y4jf5bvxa8?svg=true)](https://ci.appveyor.com/project/Chachay/matplotlib-cpp) + Welcome to matplotlib-cpp, possibly the simplest C++ plotting library. It is built to resemble the plotting API used by Matlab and matplotlib. diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..8578305 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,31 @@ +version: 1.0.{build} +branches: + only: + - dev3 +image: +- Visual Studio 2015 +- Visual Studio 2017 +- Visual Studio 2019 +configuration: Release +platform: x64 +init: +- cmd: >- + echo %APPVEYOR_BUILD_WORKER_IMAGE% + + if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" set MSVC_VERSION=14 + + if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" set MSVC_VERSION=15 + + if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2019" set MSVC_VERSION=19 + + set PATH=%PYTHONHOME%;%PYTHONHOME%\Scripts;%ProgramFiles(x86)%\Microsoft Visual Studio\Installer;%PATH% +environment: + PYTHONHOME: C:\Miniconda37-x64 +install: +- cmd: >- + conda install --yes numpy matplotlib +build_script: +- cmd: >- + cd contrib + + call WinBuild.cmd \ No newline at end of file diff --git a/contrib/WinBuild.cmd b/contrib/WinBuild.cmd index 9dfd627..0dd9da8 100644 --- a/contrib/WinBuild.cmd +++ b/contrib/WinBuild.cmd @@ -2,9 +2,9 @@ @setlocal EnableDelayedExpansion REM ------Set Your Environment------------------------------- -if NOT DEFINED MSVC_VERSION set MSVC_VERSION=15 +if NOT DEFINED MSVC_VERSION set MSVC_VERSION=19 if NOT DEFINED CMAKE_CONFIG set CMAKE_CONFIG=Release -if NOT DEFINED PYTHONHOME set PYTHONHOME=C:/Users/%username%/Anaconda3 +if NOT DEFINED PYTHONHOME set PYTHONHOME=C:/Users/%username%/miniconda3 REM --------------------------------------------------------- set KEY_NAME="HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\SxS\VS7" @@ -28,9 +28,13 @@ if "%MSVC_VERSION%"=="14" ( ) else ( set CMAKE_GENERATOR=Visual Studio 15 2017 ) +) else if "%MSVC_VERSION%"=="19" ( + set CMAKE_GENERATOR=Visual Studio 16 2019 ) -if "%MSVC_VERSION%"=="15" ( - for /F "usebackq tokens=1,2,*" %%A in (`REG QUERY %KEY_NAME% /v %VALUE_NAME%`) do ( + +if "%MSVC_VERSION%" GEQ "15" ( + REM Find VC ยท microsoft/vswhere Wiki https://github.com/microsoft/vswhere/wiki/Find-VC + for /F "usebackq tokens=1,2,*" %%A in (`vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do ( set batch_file=%%CVC\Auxiliary\Build\vcvarsall.bat ) ) else ( @@ -43,10 +47,17 @@ pushd examples if NOT EXIST build mkdir build pushd build -cmake -G"!CMAKE_GENERATOR!" ^ - -DPYTHONHOME:STRING=%PYTHONHOME%^ - -DCMAKE_BUILD_TYPE:STRING=%CMAKE_CONFIG% ^ - %~dp0 +if "%MSVC_VERSION%" GEQ "19" ( + cmake -G"!CMAKE_GENERATOR!" -A x64^ + -DPYTHONHOME:STRING=%PYTHONHOME%^ + -DCMAKE_BUILD_TYPE:STRING=%CMAKE_CONFIG% ^ + %~dp0 +) else ( + cmake -G"!CMAKE_GENERATOR!" ^ + -DPYTHONHOME:STRING=%PYTHONHOME%^ + -DCMAKE_BUILD_TYPE:STRING=%CMAKE_CONFIG% ^ + %~dp0 +) cmake --build . --config %CMAKE_CONFIG% pushd %CMAKE_CONFIG% From e1b22f1f621faaa116a93be361688b10f4f91811 Mon Sep 17 00:00:00 2001 From: Chachay Date: Wed, 24 Jun 2020 09:49:25 +0200 Subject: [PATCH 3/5] Amend header a bit --- matplotlibcpp.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/matplotlibcpp.h b/matplotlibcpp.h index 6770074..3774e40 100644 --- a/matplotlibcpp.h +++ b/matplotlibcpp.h @@ -13,6 +13,7 @@ #include #include // requires c++11 support #include +#include #ifndef WITHOUT_NUMPY # define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION @@ -312,9 +313,9 @@ template <> struct select_npy_type { const static NPY_TYPES type = NPY // Sanity checks; comment them out or change the numpy type below if you're compiling on // a platform where they don't apply -static_assert(sizeof(long long) == 8); +static_assert(sizeof(long long) == 8, "long long must be 8 byte"); template <> struct select_npy_type { const static NPY_TYPES type = NPY_INT64; }; -static_assert(sizeof(unsigned long long) == 8); +static_assert(sizeof(unsigned long long) == 8, "unsigned long long must be 8 byte"); template <> struct select_npy_type { const static NPY_TYPES type = NPY_UINT64; }; // TODO: add int, long, etc. From 33e15cd0d75788a5546ce5599d565d787d3f8929 Mon Sep 17 00:00:00 2001 From: Chachay Date: Wed, 24 Jun 2020 09:49:39 +0200 Subject: [PATCH 4/5] Adjust workaround of Windows build --- contrib/CMakeLists.txt | 1 + contrib/README.md | 5 +++++ contrib/WinBuild.cmd | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index edb40b1..b402d9b 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -9,6 +9,7 @@ include_directories(${PYTHONHOME}/Lib/site-packages/numpy/core/include) link_directories(${PYTHONHOME}/libs) add_definitions(-DMATPLOTLIBCPP_PYTHON_HEADER=Python.h) +add_compile_definitions(WITHOUT_NUMPY) # message(STATUS "*** dump start cmake variables ***") # get_cmake_property(_variableNames VARIABLES) diff --git a/contrib/README.md b/contrib/README.md index 0af8515..19dffd2 100644 --- a/contrib/README.md +++ b/contrib/README.md @@ -30,3 +30,8 @@ The `WinBuild.cmd` will set up temporal ENV variables and build binaries in (mat 3. Find exe files in examples/build/Release Note: platforms folder is necessary to make qt works. + + +### Check before run examples +If you use Anaconda on Windows, you might need to set PYTHONHOME to Anaconda home directory and QT_QPA_PLATFORM_PLUGIN_PATH to %PYTHONHOME%Library/plugins/platforms. The latter is for especially when you get the error which says 'This application failed to start because it could not find or load the Qt platform plugin "windows" +in "".' diff --git a/contrib/WinBuild.cmd b/contrib/WinBuild.cmd index 0dd9da8..419c454 100644 --- a/contrib/WinBuild.cmd +++ b/contrib/WinBuild.cmd @@ -62,8 +62,8 @@ cmake --build . --config %CMAKE_CONFIG% pushd %CMAKE_CONFIG% if not EXIST platforms mkdir platforms -if EXIST %PYTHONHOME%/Library/plugins/platforms/qwindows.dll ^ -cp %PYTHONHOME%/Library/plugins/platforms/qwindows.dll ./platforms/ +if EXIST %PYTHONHOME%\Library\plugins\platforms\qwindows.dll ^ +copy %PYTHONHOME%\Library\plugins\platforms\qwindows.dll .\platforms\ popd REM move ./%CMAKE_CONFIG% ../ popd From 70dedc3b8625efe38a1f11caa3c330f2fdd6f1de Mon Sep 17 00:00:00 2001 From: Chachay Date: Thu, 25 Jun 2020 23:50:31 +0200 Subject: [PATCH 5/5] Add Error sequence --- contrib/WinBuild.cmd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contrib/WinBuild.cmd b/contrib/WinBuild.cmd index 419c454..f70c736 100644 --- a/contrib/WinBuild.cmd +++ b/contrib/WinBuild.cmd @@ -59,6 +59,10 @@ if "%MSVC_VERSION%" GEQ "19" ( %~dp0 ) cmake --build . --config %CMAKE_CONFIG% +SET BUILD_ERRORLEVEL=!ERRORLEVEL! +IF NOT "!BUILD_ERRORLEVEL!"=="0" ( + EXIT /B !BUILD_ERRORLEVEL! +) pushd %CMAKE_CONFIG% if not EXIST platforms mkdir platforms