diff --git a/CMakeLists.txt b/CMakeLists.txt index 54409e9fd..85f1982ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ endif(InSourceBuild) # System detection/default settings include( DetectDistro ) +include( DetectBrowser ) set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "add a postfix, usually d on windows") set(CMAKE_RELEASE_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows") diff --git a/CMakeModules/DetectBrowser.cmake b/CMakeModules/DetectBrowser.cmake new file mode 100644 index 000000000..6d4be5452 --- /dev/null +++ b/CMakeModules/DetectBrowser.cmake @@ -0,0 +1,22 @@ +# DetectBrowser.cmake -- Detect web browser launcher application + +# Set default command to open browser. Override with -DWEB_BROWSER=... +if (APPLE OR MSVC) + # opening the web browser is hardcoded for Mac and Windows, + # so this doesn't really have an effect... + set(WEB_BROWSER "open") +else() + if(CMAKE_SYSTEM_NAME MATCHES "Linux") + # "xdg-open" provides run-time detection of user's preferred browser on (most) Linux. + if (NOT LINUX_DISTRO MATCHES "Debian") + set(WEB_BROWSER "xdg-open" CACHE STRING "Command to open web browser") + else() + # Debian is different: "sensible-browser" provides auto-detection + set(WEB_BROWSER "sensible-browser" CACHE STRING "Command to open web browser") + endif() + else() + # Default for non Linux/non Mac/non Windows platform... + set(WEB_BROWSER "firefox" CACHE STRING "Command to open web browser") + endif() + message(STATUS "Web browser launcher command is: ${WEB_BROWSER}") +endif() diff --git a/src/GUI/gui_funcs.cxx b/src/GUI/gui_funcs.cxx index 5d797d009..e8941e3d5 100644 --- a/src/GUI/gui_funcs.cxx +++ b/src/GUI/gui_funcs.cxx @@ -192,22 +192,7 @@ bool openBrowser(string address) } cocoaOpenUrl(address); - return ok; -#endif - -#ifndef _WIN32 - - string command = globals->get_browser(); - string::size_type pos; - if ((pos = command.find("%u", 0)) != string::npos) - command.replace(pos, 2, address); - else - command += " " + address; - - command += " &"; - ok = (system( command.c_str() ) == 0); - -#else // _WIN32 +#elif defined _WIN32 // Look for favorite browser char win32_name[1024]; @@ -218,7 +203,17 @@ bool openBrowser(string address) # endif ShellExecute ( NULL, "open", win32_name, NULL, NULL, SW_SHOWNORMAL ) ; +#else + // Linux, BSD, SGI etc + string command = globals->get_browser(); + string::size_type pos; + if ((pos = command.find("%u", 0)) != string::npos) + command.replace(pos, 2, address); + else + command += " \"" + address +"\""; + command += " &"; + ok = (system( command.c_str() ) == 0); #endif mkDialog("The file is shown in your web browser window."); diff --git a/src/Include/config_cmake.h.in b/src/Include/config_cmake.h.in index 245854c82..230b3d7b2 100644 --- a/src/Include/config_cmake.h.in +++ b/src/Include/config_cmake.h.in @@ -33,6 +33,7 @@ #cmakedefine HAVE_LIBSVN_CLIENT_1 #define PKGLIBDIR "@FG_DATA_DIR@" +#define WEB_BROWSER "@WEB_BROWSER@" #cmakedefine FG_HAVE_HLA #cmakedefine FG_JPEG_SERVER diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 7b7f7fff9..cb4a2e537 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -1028,7 +1028,9 @@ bool fgInitGeneral() { } SG_LOG( SG_GENERAL, SG_INFO, "FG_ROOT = " << '"' << root << '"' << endl ); - globals->set_browser(fgGetString("/sim/startup/browser-app", "firefox %u")); + // Note: browser command is hard-coded for Mac/Windows, so this only affects other platforms + globals->set_browser(fgGetString("/sim/startup/browser-app", WEB_BROWSER)); + fgSetString("/sim/startup/browser-app", globals->get_browser()); simgear::Dir cwd(simgear::Dir::current()); SGPropertyNode *curr = fgGetNode("/sim", true); diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 77bbd78c0..d5cc06e9a 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -175,17 +175,6 @@ fgSetDefaults () // fgSetString("/sim/startup/mouse-pointer", "disabled"); fgSetString("/sim/control-mode", "joystick"); fgSetBool("/controls/flight/auto-coordination", false); -#if defined(WIN32) - fgSetString("/sim/startup/browser-app", "webrun.bat"); -#elif defined(__APPLE__) - fgSetString("/sim/startup/browser-app", "open"); -#elif defined(sgi) - fgSetString("/sim/startup/browser-app", "launchWebJumper"); -#else - const char* browserEnv = ::getenv( "WEBBROWSER" ); - if (!browserEnv) browserEnv = "netscape"; - fgSetString("/sim/startup/browser-app", browserEnv); -#endif fgSetString("/sim/logging/priority", "alert"); // Features