diff options
| author | Marius Kintel <marius@kintel.net> | 2013-10-07 22:47:08 (GMT) | 
|---|---|---|
| committer | Marius Kintel <marius@kintel.net> | 2013-10-07 22:47:08 (GMT) | 
| commit | aa1752a3a00c25649b290102fad745af1d3b4887 (patch) | |
| tree | 2b6df9683d1797286aaf4dec969d427603a9eeab | |
| parent | 4c06a4e78f1bf9cc86bd67ae792e2a54febd3d91 (diff) | |
Mac needs to know if we're a GUI app in order to find bundled libraries, Use Qt to find application path if available
| -rw-r--r-- | src/openscad.cc | 30 | ||||
| -rw-r--r-- | src/parsersettings.cc | 9 | ||||
| -rw-r--r-- | src/parsersettings.h | 2 | ||||
| -rw-r--r-- | tests/cgalcachetest.cc | 2 | ||||
| -rw-r--r-- | tests/csgtexttest.cc | 2 | ||||
| -rw-r--r-- | tests/modulecachetest.cc | 2 | 
6 files changed, 30 insertions, 17 deletions
| diff --git a/src/openscad.cc b/src/openscad.cc index f4f4014..e5eb69f 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -190,9 +190,9 @@ Camera get_camera( po::variables_map vm )  	return camera;  } -int cmdline(const char *deps_output_file, const std::string &filename, Camera &camera, const char *output_file, const fs::path &original_path, Render::type renderer, char ** argv ) +int cmdline(const std::string &application_path, const char *deps_output_file, const std::string &filename, Camera &camera, const char *output_file, const fs::path &original_path, Render::type renderer, char ** argv )  { -	parser_init(boosty::stringy(boost::filesystem::path( argv[0] ).parent_path())); +	parser_init(application_path, false);  	Tree tree;  #ifdef ENABLE_CGAL  	CGALEvaluator cgalevaluator(tree); @@ -454,7 +454,7 @@ bool QtUseGUI()  	return useGUI;  } -int gui(vector<string> &inputFiles, const fs::path &original_path, int argc, char ** argv) +int gui(const std::string &application_path, vector<string> &inputFiles, const fs::path &original_path, int argc, char ** argv)  {  	QApplication app(argc, argv, true); //useGUI);  #ifdef Q_WS_MAC @@ -465,7 +465,7 @@ int gui(vector<string> &inputFiles, const fs::path &original_path, int argc, cha  	QCoreApplication::setOrganizationDomain("openscad.org");  	QCoreApplication::setApplicationName("OpenSCAD");  	QCoreApplication::setApplicationVersion(TOSTRING(OPENSCAD_VERSION)); - +	  	QDir exdir(QApplication::instance()->applicationDirPath());  	QString qexamplesdir;  #ifdef Q_WS_MAC @@ -486,8 +486,7 @@ int gui(vector<string> &inputFiles, const fs::path &original_path, int argc, cha  					qexamplesdir = exdir.path();  				}  	MainWindow::setExamplesDir(qexamplesdir); - -	parser_init(QApplication::instance()->applicationDirPath().toLocal8Bit().constData()); +  parser_init(application_path, true);  #ifdef Q_WS_MAC  	installAppleEventHandlers(); @@ -520,7 +519,7 @@ int gui(vector<string> &inputFiles, const fs::path &original_path, int argc, cha  }  #else // OPENSCAD_QTGUI  bool QtUseGUI() { return false; } -int gui(const vector<string> &inputFiles, const fs::path &original_path, int argc, char ** argv) +int gui(const std::string &application_path, const vector<string> &inputFiles, const fs::path &original_path, int argc, char ** argv)  {  	fprintf(stderr,"Error: compiled without QT, but trying to run GUI\n");  	return 1; @@ -641,12 +640,23 @@ int main(int argc, char **argv)  	NodeCache nodecache;  	NodeDumper dumper(nodecache); -	if (output_file) { +	bool cmdlinemode = false; +	if (output_file) { // cmd-line mode +		cmdlinemode = true;  		if (!inputFiles.size()) help(argv[0]); -		rc = cmdline(deps_output_file, inputFiles[0], camera, output_file, original_path, renderer, argv); +	} +	const std::string application_path =  +#ifdef OPENSCAD_QTGUI +		QApplication::instance()->applicationDirPath().toLocal8Bit().constData(); +#else +		boosty::stringy(boosty::absolute(boost::filesystem::path(argv[0]).parent_path())); +#endif + +	if (cmdlinemode) { +		rc = cmdline(application_path, deps_output_file, inputFiles[0], camera, output_file, original_path, renderer, argv);  	}  	else if (QtUseGUI()) { -		rc = gui(inputFiles, original_path, argc, argv); +		rc = gui(application_path, inputFiles, original_path, argc, argv);  	}  	else {  		fprintf(stderr, "Requested GUI mode but can't open display!\n"); diff --git a/src/parsersettings.cc b/src/parsersettings.cc index 63a7713..de1ff98 100644 --- a/src/parsersettings.cc +++ b/src/parsersettings.cc @@ -88,7 +88,7 @@ fs::path find_valid_path(const fs::path &sourcepath,  	return fs::path();  } -void parser_init(const std::string &applicationpath) +void parser_init(const std::string &applicationpath, bool isgui)  {    // Add paths from OPENSCADPATH before adding built-in paths  	const char *openscadpaths = getenv("OPENSCADPATH"); @@ -116,8 +116,11 @@ void parser_init(const std::string &applicationpath)  	fs::path libdir(applicationpath);  	fs::path tmpdir;  #ifdef __APPLE__ -	libdir /= "../Resources"; // Libraries can be bundled -	if (!is_directory(libdir / "libraries")) libdir /= "../../.."; +	// Libraries can be bundled on Mac. If not, fall back to development layout +	if (isgui) { +		libdir /= "../Resources"; +		if (!is_directory(libdir / "libraries")) libdir /= "../../.."; +	}  #elif !defined(WIN32)  	if (is_directory(tmpdir = libdir / "../share/openscad/libraries")) {  		librarydir = boosty::stringy(tmpdir); diff --git a/src/parsersettings.h b/src/parsersettings.h index 52172b6..2aef85b 100644 --- a/src/parsersettings.h +++ b/src/parsersettings.h @@ -6,7 +6,7 @@  extern int parser_error_pos; -void parser_init(const std::string &applicationpath); +void parser_init(const std::string &applicationpath, bool isgui);  void add_librarydir(const std::string &libdir);  fs::path search_libs(const fs::path &localpath);  fs::path find_valid_path(const fs::path &sourcepath,  diff --git a/tests/cgalcachetest.cc b/tests/cgalcachetest.cc index 67d3313..598879c 100644 --- a/tests/cgalcachetest.cc +++ b/tests/cgalcachetest.cc @@ -126,7 +126,7 @@ int main(int argc, char **argv)  	currentdir = boosty::stringy(fs::current_path()); -	parser_init(boosty::stringy(fs::path(argv[0]).branch_path())); +	parser_init(boosty::stringy(fs::path(argv[0]).branch_path()), false);  	add_librarydir(boosty::stringy(fs::path(argv[0]).branch_path() / "../libraries"));  	ModuleContext top_ctx; diff --git a/tests/csgtexttest.cc b/tests/csgtexttest.cc index 97902f6..0be3123 100644 --- a/tests/csgtexttest.cc +++ b/tests/csgtexttest.cc @@ -77,7 +77,7 @@ int main(int argc, char **argv)  	currentdir = boosty::stringy( fs::current_path() ); -	parser_init(boosty::stringy(fs::path(argv[0]).branch_path())); +	parser_init(boosty::stringy(fs::path(argv[0]).branch_path()), false);  	add_librarydir(boosty::stringy(fs::path(argv[0]).branch_path() / "../libraries"));  	ModuleContext top_ctx; diff --git a/tests/modulecachetest.cc b/tests/modulecachetest.cc index 5531461..423cffc 100644 --- a/tests/modulecachetest.cc +++ b/tests/modulecachetest.cc @@ -73,7 +73,7 @@ int main(int argc, char **argv)  	currentdir = boosty::stringy( fs::current_path() ); -	parser_init(boosty::stringy(fs::path(argv[0]).branch_path())); +	parser_init(boosty::stringy(fs::path(argv[0]).branch_path()), false);  	add_librarydir(boosty::stringy(fs::path(argv[0]).branch_path() / "../libraries"));  	ModuleContext top_ctx; | 
