Example #1
0
int main(int argc, char *argv[])
{
  auto start = std::chrono::system_clock::now();

  // parse command line
  try
  {
    boost::program_options::options_description program("SC Reflection Parser");

    program.add_options()
        (
          SWITCH_OPTION(Help),
          "Displays help information."
          )
        (
          SWITCH_OPTION(TargetName),
          boost::program_options::value<std::string>()->required(),
          "Input target project name."
          )
        (
          SWITCH_OPTION(Input),
          boost::program_options::value<std::string>()->required(),
          "Source path to parse headers in."
          )
        (
          SWITCH_OPTION(Output),
          boost::program_options::value<std::string>()->required(),
          "Output path for generated headers."
          )
        (
          SWITCH_OPTION(BuildDirectory),
          boost::program_options::value<std::string>()->default_value("./build"),
          "Directory that contains the build intermediate files."
          )
        (
          SWITCH_OPTION(CompilerFlags),
          boost::program_options::value<std::vector<std::string>>()->multitoken()->required(),
          "Optional list of flags to pass to the compiler."
          );

    boost::program_options::variables_map cmdLine;

    boost::program_options::store(boost::program_options::parse_command_line(argc, argv, program), cmdLine);

    if (cmdLine.count("help"))
    {
      std::cout << program << std::endl;

      return EXIT_SUCCESS;
    }

    boost::program_options::notify(cmdLine);

    std::string const appName = argv[0];
    parse(appName, cmdLine);
  }
  catch (std::exception &e)
  {
    utils::FatalError(e.what());
  }
  catch (...)
  {
    utils::FatalError("Unhandled exception occurred!");
  }

  auto duration = std::chrono::system_clock::now() - start;

  std::cout << "Completed in "
            << std::chrono::duration_cast<std::chrono::milliseconds>(duration).count()
            << "ms" << std::endl;

  return EXIT_SUCCESS;
}
Example #2
0
int main(int argc, char *argv[])
{
    auto start = std::chrono::system_clock::now( );

    // misc initialization
    {
        // path to the executable
        auto exeDir = fs::path( argv[ 0 ] );

        // set the working directory to the executable directory
        fs::current_path( exeDir.parent_path( ) );
    }

    // parse command line
    try 
    {
        po::options_description program( "Ursine3D Reflection Parser" );

        program.add_options( )
        ( 
            SWITCH_OPTION( Help ), 
            "Displays help information." 
        )
        ( 
            SWITCH_OPTION( TargetName ), 
            po::value<std::string>( )->required( ),
            "Input target project name." 
        )
        ( 
            SWITCH_OPTION( InputSource ), 
            po::value<std::string>( )->required( ), 
            "Source file (header) to compile reflection data from." 
        )
        ( 
            SWITCH_OPTION( OutputHeader ), 
            po::value<std::string>( )->required( ), 
            "Output generated C++ header file." 
        )
        ( 
            SWITCH_OPTION( OutputSource ), 
            po::value<std::string>( )->required( ), 
            "Output generated C++ source file." 
        )
        ( 
            SWITCH_OPTION( TemplateDirectory ), 
            po::value<std::string>( )->default_value( "Templates/" ), 
            "Directory that contains the mustache templates." 
        )
        ( 
            SWITCH_OPTION( PrecompiledHeader ), 
            po::value<std::string>( ), 
            "Optional name of the precompiled header file for the project." 
        )
        ( 
            SWITCH_OPTION( CompilerFlags ), 
            po::value<std::vector<std::string>>( )->multitoken( )->required( ),
            "Optional list of flags to pass to the compiler." 
        );

        po::variables_map cmdLine;

        po::store( po::parse_command_line( argc, argv, program ), cmdLine );

        if (cmdLine.count( "help" )) 
        {
            std::cout << program << std::endl;

            return EXIT_SUCCESS;
        }

        po::notify( cmdLine );

        parse( cmdLine );
    }
    catch (std::exception &e) 
    {
        utils::FatalError( e.what( ) );
    }
    catch (...) 
    {
        utils::FatalError( "Unhandled exception occurred!" );
    }

    auto duration = std::chrono::system_clock::now( ) - start;

    std::cout << "Completed in " 
              << std::chrono::duration_cast<std::chrono::milliseconds>( duration ).count( ) 
              << "ms" << std::endl;

    return EXIT_SUCCESS;
}