summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDon Bright <hugh.m.bright@gmail.com>2013-05-27 01:24:53 (GMT)
committerDon Bright <hugh.m.bright@gmail.com>2013-05-27 01:24:53 (GMT)
commit08952ee2164efd8257adbd8684317ec1c945b7ac (patch)
tree5b50d417d950ad27e90f2765977e42caac1a881d
parent31c88a434b3201d88819b485f74da843c2728cb2 (diff)
windows - library path find, also windows build fixes
-rw-r--r--boost.pri4
-rw-r--r--cgal.pri4
-rw-r--r--common.pri2
-rw-r--r--src/CGALEvaluator.cc3
-rw-r--r--src/CSGTermEvaluator.cc2
-rw-r--r--src/PlatformUtils-win.cc57
-rw-r--r--src/PlatformUtils-win32.cc15
-rw-r--r--src/PlatformUtils.cc33
-rw-r--r--src/PlatformUtils.h1
-rw-r--r--win.pri (renamed from win32.pri)0
10 files changed, 86 insertions, 35 deletions
diff --git a/boost.pri b/boost.pri
index f3619a0..2084c89 100644
--- a/boost.pri
+++ b/boost.pri
@@ -6,7 +6,7 @@ boost {
!isEmpty(BOOST_DIR) {
QMAKE_INCDIR += $$BOOST_DIR
message("boost location: $$BOOST_DIR")
- win32: QMAKE_LIBDIR += -L$$BOOST_DIR/lib
+ win*: QMAKE_LIBDIR += -L$$BOOST_DIR/lib
}
CONFIG(mingw-cross-env) {
@@ -16,7 +16,7 @@ boost {
BOOST_LINK_FLAGS = -lboost_thread_win32-mt -lboost_program_options-mt -lboost_filesystem-mt -lboost_system-mt -lboost_regex-mt -lboost_chrono-mt
}
- isEmpty(BOOST_LINK_FLAGS):win32 {
+ isEmpty(BOOST_LINK_FLAGS):win* {
BOOST_LINK_FLAGS = -llibboost_thread-vc90-mt-s-1_46_1 -llibboost_program_options-vc90-mt-s-1_46_1 -llibboost_filesystem-vc90-mt-s-1_46_1 -llibboost_system-vc90-mt-s-1_46_1 -llibboost_regex-vc90-mt-s-1_46_1
}
diff --git a/cgal.pri b/cgal.pri
index ae532f0..241332a 100644
--- a/cgal.pri
+++ b/cgal.pri
@@ -6,7 +6,7 @@ cgal {
CGAL_DIR = $$(CGALDIR)
!isEmpty(CGAL_DIR) {
QMAKE_INCDIR += $$CGAL_DIR/include
- win32: QMAKE_INCDIR += $$CGAL_DIR/auxiliary/gmp/include
+ win*: QMAKE_INCDIR += $$CGAL_DIR/auxiliary/gmp/include
QMAKE_LIBDIR += $$CGAL_DIR/lib
message("CGAL location: $$CGAL_DIR")
}
@@ -15,7 +15,7 @@ cgal {
LIBS += -lgmp -lmpfr -lCGAL
QMAKE_CXXFLAGS += -frounding-math
} else {
- win32 {
+ win* {
*-g++* {
QMAKE_CXXFLAGS += -frounding-math
}
diff --git a/common.pri b/common.pri
index 71aa510..7153ded 100644
--- a/common.pri
+++ b/common.pri
@@ -3,7 +3,7 @@ MOC_DIR = objects
UI_DIR = objects
RCC_DIR = objects
-include(win32.pri)
+include(win.pri)
include(flex.pri)
include(bison.pri)
include(cgal.pri)
diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc
index 2ea7a8d..686bde1 100644
--- a/src/CGALEvaluator.cc
+++ b/src/CGALEvaluator.cc
@@ -279,7 +279,7 @@ Response CGALEvaluator::visit(State &state, const CsgNode &node)
if (state.isPostfix()) {
CGAL_Nef_polyhedron N;
if (!isCached(node)) {
- CGALEvaluator::CsgOp op;
+ CGALEvaluator::CsgOp op = CGE_UNION;
switch (node.type) {
case CSG_TYPE_UNION:
op = CGE_UNION;
@@ -291,7 +291,6 @@ Response CGALEvaluator::visit(State &state, const CsgNode &node)
op = CGE_INTERSECTION;
break;
default:
- op = -1;
assert(false);
}
N = applyToChildren(node, op);
diff --git a/src/CSGTermEvaluator.cc b/src/CSGTermEvaluator.cc
index 4624d4c..6b39c66 100644
--- a/src/CSGTermEvaluator.cc
+++ b/src/CSGTermEvaluator.cc
@@ -124,7 +124,7 @@ Response CSGTermEvaluator::visit(State &state, const AbstractPolyNode &node)
Response CSGTermEvaluator::visit(State &state, const CsgNode &node)
{
if (state.isPostfix()) {
- CsgOp op;
+ CsgOp op = CSGT_UNION;
switch (node.type) {
case CSG_TYPE_UNION:
op = CSGT_UNION;
diff --git a/src/PlatformUtils-win.cc b/src/PlatformUtils-win.cc
new file mode 100644
index 0000000..d06df51
--- /dev/null
+++ b/src/PlatformUtils-win.cc
@@ -0,0 +1,57 @@
+#include "PlatformUtils.h"
+#include "printutils.h"
+#include <windows.h>
+#define _WIN32_IE 0x0501 // SHGFP_TYPE_CURRENT
+#include <shlobj.h>
+
+// convert from windows api w_char strings (usually utf16) to utf8 std::string
+std::string winapi_wstr_to_utf8( std::wstring wstr )
+{
+ std::string utf8_str("");
+
+ UINT CodePage = CP_UTF8;
+ DWORD dwFlags = 0;
+ LPCSTR lpMultiByteStr = NULL;
+ int cbMultiByte = 0;
+ LPWSTR lpWideCharStr = &wstr[0];
+ int cchWideChar = (int)wstr.size();
+
+ int numbytes = MultiByteToWideChar( CodePage, dwFlags, lpMultiByteStr,
+ cbMultiByte, lpWideCharStr, cchWideChar );
+
+ cbMultiByte = numbytes;
+ lpMultiByteStr = &utf8_str[0];
+
+ int result = MultiByteToWideChar( CodePage, dwFlags, lpMultiByteStr,
+ cbMultiByte, lpWideCharStr, cchWideChar );
+
+ if (result != numbytes) {
+ PRINT("ERROR: error converting w_char str to utf8 string");
+ }
+
+ return utf8_str;
+}
+
+
+// retrieve the path to 'My Documents' for the current user under windows
+// In XP this is 'c:\documents and settings\username\my documents'
+// In Vista, 7, 8+ this is 'c:\users\username\documents'
+// This code may have problems with unusual dir types in Vista because
+// Mingw does not provide access to the updated SHGetKnownFolderPath
+std::string PlatformUtils::documentsPath()
+{
+ std::string retval;
+ std::wstring path(MAX_PATH,0);
+
+ HRESULT result = SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL,
+ SHGFP_TYPE_CURRENT, &path[0]);
+
+ if (result == S_OK) {
+ path = std::wstring( path.c_str() ); // stip extra NULLs
+ retval = winapi_wstr_to_utf8( path );
+ } else {
+ PRINT("ERROR: Could not find My Documents location");
+ retval = "";
+ }
+ return retval;
+}
diff --git a/src/PlatformUtils-win32.cc b/src/PlatformUtils-win32.cc
deleted file mode 100644
index 61382dd..0000000
--- a/src/PlatformUtils-win32.cc
+++ /dev/null
@@ -1,15 +0,0 @@
-#include "PlatformUtils.h"
-#include <windows.h>
-#include <shlobj.h>
-
-std::string PlatformUtils::documentsPath()
-{
- std::string retval;
- CHAR my_documents[MAX_PATH];
- HRESULT result = SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL,
- SHGFP_TYPE_CURRENT, my_documents);
-
- if (result != S_OK) retval = "";
- else retval = my_documents;
- return retval;
-}
diff --git a/src/PlatformUtils.cc b/src/PlatformUtils.cc
index a7efe40..47569b0 100644
--- a/src/PlatformUtils.cc
+++ b/src/PlatformUtils.cc
@@ -1,26 +1,35 @@
#include "PlatformUtils.h"
#include "boosty.h"
+bool PlatformUtils::createLibraryPath()
+{
+ std::string path = PlatformUtils::libraryPath();
+ bool OK = false;
+ try {
+ if (!fs::exists(fs::path(path))) {
+ PRINTB("Creating library folder %s", path );
+ OK = fs::create_directories( path );
+ }
+ if (!OK) {
+ PRINTB("ERROR: Cannot create %s", path );
+ }
+ } catch (const fs::filesystem_error& ex) {
+ PRINTB("ERROR: %s",ex.what());
+ }
+ return OK;
+}
+
std::string PlatformUtils::libraryPath()
{
fs::path path;
- bool OK = true;
try {
path = boosty::canonical(fs::path(PlatformUtils::documentsPath()));
if (path.empty()) return "";
- PRINTB("path size %i",boosty::stringy(path).size());
path /= "OpenSCAD";
path /= "libraries";
- PRINTB("Appended path %s", path );
- PRINTB("Exists: %i", fs::exists(path) );
- if (!fs::exists(path)) {
- PRINTB("Creating library folder %s", boosty::stringy(path) );
- OK &= fs::create_directories( path );
- }
- if (!OK) {
- PRINTB("ERROR: Cannot find nor create %s", boosty::stringy(path) );
- path = fs::path("");
- }
+ //PRINTB("path size %i",boosty::stringy(path).size());
+ //PRINTB("Appended path %s", path );
+ //PRINTB("Exists: %i", fs::exists(path) );
} catch (const fs::filesystem_error& ex) {
PRINTB("ERROR: %s",ex.what());
}
diff --git a/src/PlatformUtils.h b/src/PlatformUtils.h
index 202abaa..089b3ca 100644
--- a/src/PlatformUtils.h
+++ b/src/PlatformUtils.h
@@ -7,6 +7,7 @@ namespace PlatformUtils {
std::string documentsPath();
std::string libraryPath();
+ bool createLibraryPath();
}
diff --git a/win32.pri b/win.pri
index bb41b09..bb41b09 100644
--- a/win32.pri
+++ b/win.pri
contact: Jan Huwald // Impressum