浏览代码

Windows Compile Command

Chachay 8 年之前
父节点
当前提交
b815a4320f
共有 8 个文件被更改,包括 87 次插入6 次删除
  1. 3 0
      .gitignore
  2. 3 0
      README.md
  3. 21 0
      Win/CMakeLists.txt
  4. 8 0
      Win/README.md
  5. 46 0
      Win/WinBuild.cmd
  6. 2 2
      examples/basic.cpp
  7. 2 2
      examples/modern.cpp
  8. 2 2
      matplotlibcpp.h

+ 3 - 0
.gitignore

@@ -30,3 +30,6 @@
 # Logfiles
 *.tlog
 *.log
+
+# Build
+/examples/build/*

+ 3 - 0
README.md

@@ -138,3 +138,6 @@ Todo/Issues/Wishlist
   be easy to add.
 
 * A lot of copying could be avoided if we generate numpy arrays directly instead of python lists
+
+* 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 "".'

+ 21 - 0
Win/CMakeLists.txt

@@ -0,0 +1,21 @@
+cmake_minimum_required(VERSION 3.1)
+project (MatplotlibCPP_Test)
+
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+include_directories(${PYTHONHOME}/include)
+link_directories(${PYTHONHOME}/libs)
+
+add_definitions(-DPY_INCLUDE)
+
+# message(STATUS "*** dump start cmake variables ***")
+# get_cmake_property(_variableNames VARIABLES)
+# foreach(_variableName ${_variableNames})
+        # 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)

+ 8 - 0
Win/README.md

@@ -0,0 +1,8 @@
+### Configuring and Building Samples
+
+```cmd
+> cd Win
+> Win\build_win.cmd
+```
+
+The `build_win.cmd` will set up temporal ENV variables and build binaries in (matplotlib root)/examples with the Release configuration.

+ 46 - 0
Win/WinBuild.cmd

@@ -0,0 +1,46 @@
+@echo off
+@setlocal EnableDelayedExpansion
+
+if NOT DEFINED MSVC_VERSION set MSVC_VERSION=14
+if NOT DEFINED CMAKE_CONFIG set CMAKE_CONFIG=Release
+if NOT DEFINED PYTHONHOME   set PYTHONHOME=C:/Users/%username%/Anaconda3
+
+if "%MSVC_VERSION%"=="14" (
+    if "%processor_architecture%" == "AMD64" (
+        set CMAKE_GENERATOR=Visual Studio 14 2015 Win64
+    ) else (
+        set CMAKE_GENERATOR=Visual Studio 14 2015
+    )
+) 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
+    )
+)
+
+set batch_file=!VS%MSVC_VERSION%0COMNTOOLS!..\..\VC\vcvarsall.bat
+call "%batch_file%" %processor_architecture%
+
+pushd ..
+pushd examples
+if NOT EXIST build mkdir build
+pushd build
+
+cmake -G"!CMAKE_GENERATOR!" ^
+      -DPYTHONHOME:STRING=%PYTHONHOME%^
+      -DCMAKE_BUILD_TYPE:STRING=%CMAKE_CONFIG% ^
+      ../../Win/
+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/
+popd
+move ./%CMAKE_CONFIG% ../
+popd
+popd
+popd
+@endlocal

+ 2 - 2
examples/basic.cpp

@@ -1,6 +1,6 @@
-#include "../matplotlibcpp.h"
-
+#define _USE_MATH_DEFINES
 #include <cmath>
+#include "../matplotlibcpp.h"
 
 namespace plt = matplotlibcpp;
 

+ 2 - 2
examples/modern.cpp

@@ -1,6 +1,6 @@
-#include "../matplotlibcpp.h"
-
+#define _USE_MATH_DEFINES
 #include <cmath>
+#include "../matplotlibcpp.h"
 
 using namespace std;
 namespace plt = matplotlibcpp;

+ 2 - 2
matplotlibcpp.h

@@ -6,7 +6,7 @@
 #include <stdexcept>
 #include <iostream>
 
-#if __cplusplus > 199711L
+#if __cplusplus > 199711L || _MSC_VER > 1800
 #include <functional>
 #endif
 
@@ -583,7 +583,7 @@ namespace matplotlibcpp {
 		Py_DECREF(res);
 	}
 
-#if __cplusplus > 199711L
+#if __cplusplus > 199711L || _MSC_VER > 1800
 	// C++11-exclusive content starts here (variadic plot() and initializer list support)
 
 	namespace detail {