diff --git a/LaunchAPPL/CMakeLists.txt b/LaunchAPPL/CMakeLists.txt index ce0bc61630..ad801680fa 100644 --- a/LaunchAPPL/CMakeLists.txt +++ b/LaunchAPPL/CMakeLists.txt @@ -9,9 +9,7 @@ if(APPLE) LIST(APPEND LAUNCHMETHODS Classic.h Classic.cc ) - find_program(LAUNCHCFMAPP LaunchCFMApp) if(LAUNCHCFMAPP) - add_definitions(-DHAS_LAUNCHCFMAPP) LIST(APPEND LAUNCHMETHODS Carbon.h Carbon.cc) endif() diff --git a/LaunchAPPL/Carbon.cc b/LaunchAPPL/Carbon.cc index 22ef6e92e6..9c36553c9c 100644 --- a/LaunchAPPL/Carbon.cc +++ b/LaunchAPPL/Carbon.cc @@ -1,6 +1,9 @@ #include "Carbon.h" #include "Launcher.h" +const std::string launchCFM = + "/System/Library/Frameworks/Carbon.framework/Versions/A/Support/LaunchCFMApp"; + namespace po = boost::program_options; class CarbonLauncher : public Launcher @@ -26,7 +29,15 @@ CarbonLauncher::~CarbonLauncher() bool CarbonLauncher::Go(int timeout) { - return ChildProcess("LaunchCarbon", { appPath.string() }, timeout) == 0; + return ChildProcess(launchCFM, { appPath.string() }, timeout) == 0; +} + +bool Carbon::CheckPlatform() +{ + /* If LaunchCFMApp doesn't exist, we're likely on a Mac OS X version + where it doesn't exist anymore (10.7 Lion or later), + or on an entirely different platform. */ + return CheckExecutable(launchCFM); } std::unique_ptr Carbon::MakeLauncher(variables_map &options) diff --git a/LaunchAPPL/Carbon.h b/LaunchAPPL/Carbon.h index f9c2ce219e..ff68272f47 100644 --- a/LaunchAPPL/Carbon.h +++ b/LaunchAPPL/Carbon.h @@ -8,6 +8,7 @@ class Carbon : public LaunchMethod public: virtual std::string GetName() { return "carbon"; } + virtual bool CheckPlatform(); virtual std::unique_ptr MakeLauncher(variables_map& options); }; diff --git a/LaunchAPPL/Classic.cc b/LaunchAPPL/Classic.cc index 71d5dc49fa..8d71ba0041 100644 --- a/LaunchAPPL/Classic.cc +++ b/LaunchAPPL/Classic.cc @@ -1,9 +1,11 @@ -#if defined(__APPLE__) && defined(__powerpc) +#define ResType MacResType +#include +#undef ResType + +#if TARGET_CPU_PPC #include "Classic.h" #include "Launcher.h" -#define ResType MacResType -#include namespace po = boost::program_options; @@ -63,6 +65,16 @@ bool ClassicLauncher::Go(int timeout) return false; } +bool Classic::CheckPlatform() +{ + long sysver = 0; + Gestalt(gestaltSystemVersion, &sysver); + if(sysver >= 0x1050) + return false; + else + return true; +} + std::unique_ptr Classic::MakeLauncher(variables_map &options) { return std::unique_ptr(new ClassicLauncher(options)); diff --git a/LaunchAPPL/Classic.h b/LaunchAPPL/Classic.h index 17b5627603..22d869c545 100644 --- a/LaunchAPPL/Classic.h +++ b/LaunchAPPL/Classic.h @@ -8,6 +8,7 @@ class Classic : public LaunchMethod public: virtual std::string GetName() { return "classic"; } + virtual bool CheckPlatform(); virtual std::unique_ptr MakeLauncher(variables_map& options); }; diff --git a/LaunchAPPL/LaunchAPPL.cc b/LaunchAPPL/LaunchAPPL.cc index 64baf29173..3948eb7239 100644 --- a/LaunchAPPL/LaunchAPPL.cc +++ b/LaunchAPPL/LaunchAPPL.cc @@ -8,10 +8,13 @@ #include "LaunchMethod.h" #include "Launcher.h" -#if defined(__APPLE__) && defined(__powerpc) -# include "Classic.h" -#endif -#ifdef HAS_LAUNCHCFMAPP +#if defined(__APPLE__) +# define ResType MacResType +# include +# undef ResType +# if TARGET_CPU_PPC +# include "Classic.h" +# endif # include "Carbon.h" #endif #include "Executor.h" @@ -30,16 +33,22 @@ static vector launchMethods; static void RegisterLaunchMethods() { - launchMethods = { -#if defined(__APPLE__) && defined(__powerpc) - new Classic(), + vector methods = { +#if defined(__APPLE__) +# if TARGET_CPU_PPC + new Classic(), +# endif + new Carbon(), #endif -#ifdef HAS_LAUNCHCFMAPP - new Carbon(), -#endif - new Executor(), new MiniVMac() - // #### Add new `LaunchMethod`s here. - }; + new Executor(), new MiniVMac() + // #### Add new `LaunchMethod`s here. + }; + + for(LaunchMethod *m : methods) + { + if(m->CheckPlatform()) + launchMethods.push_back(m); + } } static void usage() @@ -59,7 +68,7 @@ static void usage() vector configuredMethods, unconfiguredMethods; for(LaunchMethod *method : launchMethods) (method->CheckOptions(options) ? configuredMethods : unconfiguredMethods) - .push_back(method->GetName()); + .push_back(method->GetName()); if(!configuredMethods.empty()) { @@ -79,10 +88,10 @@ static void usage() string e = options["emulator"].as(); std::cerr << "\nChosen emulator/environment: " << e; if(std::find(configuredMethods.begin(), configuredMethods.end(), e) - != configuredMethods.end()) + != configuredMethods.end()) std::cerr << "\n"; else if(std::find(unconfiguredMethods.begin(), unconfiguredMethods.end(), e) - != unconfiguredMethods.end()) + != unconfiguredMethods.end()) std::cerr << " (needs more configuration)\n"; else std::cerr << " (UNKNOWN)\n"; @@ -101,33 +110,33 @@ int main(int argc, char *argv[]) configFiles = { string(getenv("HOME")) + "/.LaunchAPPL.cfg", RETRO68_PREFIX "/LaunchAPPL.cfg"}; desc.add_options() - ("help,h", "show this help message") - ("list-emulators,l", "get the list of available, fully configured emulators/environments") - ("make-executable,x", po::value(), "make a MacBinary file executable") + ("help,h", "show this help message") + ("list-emulators,l", "get the list of available, fully configured emulators/environments") + ("make-executable,x", po::value(), "make a MacBinary file executable") ; po::options_description configdesc; configdesc.add_options() - ("emulator,e", po::value(), "what emulator/environment to use") + ("emulator,e", po::value(), "what emulator/environment to use") ; for(LaunchMethod *lm : launchMethods) lm->GetOptions(configdesc); desc.add(configdesc); desc.add_options() - ("timeout,t", po::value(),"abort after timeout") + ("timeout,t", po::value(),"abort after timeout") ; po::options_description hidden, alldesc; hidden.add_options() - ("application,a", po::value(), "application" ) + ("application,a", po::value(), "application" ) ; alldesc.add(desc).add(hidden); try { auto parsed = po::command_line_parser(argc, argv) - .options(alldesc) - .positional(po::positional_options_description().add("application", -1)) - .style(po::command_line_style::default_style) - .run(); + .options(alldesc) + .positional(po::positional_options_description().add("application", -1)) + .style(po::command_line_style::default_style) + .run(); po::store(parsed, options); } diff --git a/LaunchAPPL/LaunchMethod.cc b/LaunchAPPL/LaunchMethod.cc index b79928552c..dfe67cf980 100644 --- a/LaunchAPPL/LaunchMethod.cc +++ b/LaunchAPPL/LaunchMethod.cc @@ -18,6 +18,11 @@ void LaunchMethod::GetOptions(boost::program_options::options_description &desc) { } +bool LaunchMethod::CheckPlatform() +{ + return true; +} + bool LaunchMethod::CheckOptions(boost::program_options::variables_map &options) { return true; diff --git a/LaunchAPPL/LaunchMethod.h b/LaunchAPPL/LaunchMethod.h index 5fa1eb53f9..bcbf69742c 100644 --- a/LaunchAPPL/LaunchMethod.h +++ b/LaunchAPPL/LaunchMethod.h @@ -20,6 +20,8 @@ public: virtual std::string GetName() = 0; virtual void GetOptions(options_description& desc); + + virtual bool CheckPlatform(); virtual bool CheckOptions(variables_map& options); virtual std::unique_ptr MakeLauncher(variables_map& options) = 0;