Skip to content

Commit b815a43

Browse files
ChachayBenno Evers
authored and
Benno Evers
committed
Windows Compile Command
1 parent d3c9763 commit b815a43

File tree

8 files changed

+87
-6
lines changed

8 files changed

+87
-6
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@
3030
# Logfiles
3131
*.tlog
3232
*.log
33+
34+
# Build
35+
/examples/build/*

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,6 @@ Todo/Issues/Wishlist
138138
be easy to add.
139139

140140
* A lot of copying could be avoided if we generate numpy arrays directly instead of python lists
141+
142+
* 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"
143+
in "".'

Win/CMakeLists.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project (MatplotlibCPP_Test)
3+
4+
set(CMAKE_CXX_STANDARD 11)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
7+
include_directories(${PYTHONHOME}/include)
8+
link_directories(${PYTHONHOME}/libs)
9+
10+
add_definitions(-DPY_INCLUDE)
11+
12+
# message(STATUS "*** dump start cmake variables ***")
13+
# get_cmake_property(_variableNames VARIABLES)
14+
# foreach(_variableName ${_variableNames})
15+
# message(STATUS "${_variableName}=${${_variableName}}")
16+
# endforeach()
17+
# message(STATUS "*** dump end ***")
18+
19+
add_executable(minimal ${CMAKE_CURRENT_SOURCE_DIR}/../examples/minimal.cpp)
20+
add_executable(basic ${CMAKE_CURRENT_SOURCE_DIR}/../examples/basic.cpp)
21+
add_executable(modern ${CMAKE_CURRENT_SOURCE_DIR}/../examples/modern.cpp)

Win/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
### Configuring and Building Samples
2+
3+
```cmd
4+
> cd Win
5+
> Win\build_win.cmd
6+
```
7+
8+
The `build_win.cmd` will set up temporal ENV variables and build binaries in (matplotlib root)/examples with the Release configuration.

Win/WinBuild.cmd

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
@echo off
2+
@setlocal EnableDelayedExpansion
3+
4+
if NOT DEFINED MSVC_VERSION set MSVC_VERSION=14
5+
if NOT DEFINED CMAKE_CONFIG set CMAKE_CONFIG=Release
6+
if NOT DEFINED PYTHONHOME set PYTHONHOME=C:/Users/%username%/Anaconda3
7+
8+
if "%MSVC_VERSION%"=="14" (
9+
if "%processor_architecture%" == "AMD64" (
10+
set CMAKE_GENERATOR=Visual Studio 14 2015 Win64
11+
) else (
12+
set CMAKE_GENERATOR=Visual Studio 14 2015
13+
)
14+
) else if "%MSVC_VERSION%"=="12" (
15+
if "%processor_architecture%" == "AMD64" (
16+
set CMAKE_GENERATOR=Visual Studio 12 2013 Win64
17+
18+
) else (
19+
set CMAKE_GENERATOR=Visual Studio 12 2013
20+
)
21+
)
22+
23+
set batch_file=!VS%MSVC_VERSION%0COMNTOOLS!..\..\VC\vcvarsall.bat
24+
call "%batch_file%" %processor_architecture%
25+
26+
pushd ..
27+
pushd examples
28+
if NOT EXIST build mkdir build
29+
pushd build
30+
31+
cmake -G"!CMAKE_GENERATOR!" ^
32+
-DPYTHONHOME:STRING=%PYTHONHOME%^
33+
-DCMAKE_BUILD_TYPE:STRING=%CMAKE_CONFIG% ^
34+
../../Win/
35+
cmake --build . --config %CMAKE_CONFIG%
36+
37+
pushd %CMAKE_CONFIG%
38+
if not EXIST platforms mkdir platforms
39+
if EXIST %PYTHONHOME%/Library/plugins/platforms/qwindows.dll ^
40+
cp %PYTHONHOME%/Library/plugins/platforms/qwindows.dll ./platforms/
41+
popd
42+
move ./%CMAKE_CONFIG% ../
43+
popd
44+
popd
45+
popd
46+
@endlocal

examples/basic.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include "../matplotlibcpp.h"
2-
1+
#define _USE_MATH_DEFINES
32
#include <cmath>
3+
#include "../matplotlibcpp.h"
44

55
namespace plt = matplotlibcpp;
66

examples/modern.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include "../matplotlibcpp.h"
2-
1+
#define _USE_MATH_DEFINES
32
#include <cmath>
3+
#include "../matplotlibcpp.h"
44

55
using namespace std;
66
namespace plt = matplotlibcpp;

matplotlibcpp.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <stdexcept>
77
#include <iostream>
88

9-
#if __cplusplus > 199711L
9+
#if __cplusplus > 199711L || _MSC_VER > 1800
1010
#include <functional>
1111
#endif
1212

@@ -583,7 +583,7 @@ namespace matplotlibcpp {
583583
Py_DECREF(res);
584584
}
585585

586-
#if __cplusplus > 199711L
586+
#if __cplusplus > 199711L || _MSC_VER > 1800
587587
// C++11-exclusive content starts here (variadic plot() and initializer list support)
588588

589589
namespace detail {

0 commit comments

Comments
 (0)