Skip to content

Commit

Permalink
Switch to boost::program_options (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
eile committed Jan 16, 2012
1 parent 310561b commit ad9f1c9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 26 deletions.
19 changes: 14 additions & 5 deletions apps/gpu_sd/CMakeLists.txt
Expand Up @@ -8,24 +8,33 @@ set(SOURCES
gpu_sd.cpp)

include_directories(${DNSSD_INCLUDE_DIRS})
set(LINK_LIBRARIES ${DNSSD_LIBRARIES} gpusd)

set(GPUSD_LIBRARIES gpusd)
if(APPLE)
add_definitions(-DGPUSD_CGL)
list(APPEND GPUSD_LIBRARIES gpusd_cgl)
list(APPEND LINK_LIBRARIES gpusd_cgl)
endif()
if(X11_FOUND)
add_definitions(-DGPUSD_GLX)
list(APPEND GPUSD_LIBRARIES gpusd_glx)
list(APPEND LINK_LIBRARIES gpusd_glx)
endif()
if(WIN32)
add_definitions(-DGPUSD_WGL)
list(APPEND GPUSD_LIBRARIES gpusd_wgl ws2_32)
list(APPEND LINK_LIBRARIES gpusd_wgl ws2_32)
endif()

find_package(Boost COMPONENTS program_options)
if(Boost_FOUND)
add_definitions(-DGPUSD_BOOST)
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
list(APPEND LINK_LIBRARIES ${Boost_PROGRAM_OPTIONS_LIBRARY})
else()
message(STATUS "boost::program_options missing, command line options not available")
endif()

source_group(\\ FILES ${SOURCES} ${HEADERS})
add_executable(gpu_sd ${SOURCES} ${HEADERS})
target_link_libraries(gpu_sd ${DNSSD_LIBRARIES} ${GPUSD_LIBRARIES})
target_link_libraries(gpu_sd ${LINK_LIBRARIES})
if(CMAKE_PROJECT_NAME MATCHES "gpusd")
install(TARGETS gpu_sd DESTINATION bin COMPONENT daemon)
endif()
61 changes: 40 additions & 21 deletions apps/gpu_sd/gpu_sd.cpp
Expand Up @@ -29,6 +29,13 @@
# include <gpusd/wgl/module.h>
#endif

#ifdef GPUSD_BOOST
# include <boost/program_options/options_description.hpp>
# include <boost/program_options/parsers.hpp>
# include <boost/program_options/variables_map.hpp>
namespace arg = boost::program_options;
#endif

#ifndef _WIN32
# include <arpa/inet.h>
# include <unistd.h>
Expand Down Expand Up @@ -150,7 +157,8 @@ static DNSServiceErrorType registerService( const TXTRecordRef& record )
htons( 4242 ) /* port */,
TXTRecordGetLength( &record ),
TXTRecordGetBytesPtr( &record ),
(DNSServiceRegisterReply)registerCB, 0 /* context* */ );
(DNSServiceRegisterReply)registerCB,
0 /* context */ );
if( error == kDNSServiceErr_NoError )
{
handleEvents( serviceRef );
Expand All @@ -171,32 +179,43 @@ int main (int argc, char * argv[])
gpusd::wgl::Module::use();
#endif

const GPUInfos gpus = gpusd::Module::discoverGPUs();
if( gpus.empty( ))
std::string session( "default" );

#ifdef GPUSD_BOOST
arg::variables_map vm;
arg::options_description desc("GPU service discovery daemon");
desc.add_options()
("help,h", "output this help message")
("session,s", arg::value< std::string >(), "set session name")
;


try
{
std::cerr << "No GPUs found, quitting" << std::endl;
return EXIT_FAILURE;
arg::store( arg::parse_command_line( argc, argv, desc ), vm );
arg::notify( vm );
}

std::string session( "default" );
#ifndef _WIN32
switch( getopt( argc, argv, "s:" ))
catch(...)
{
std::cout << desc << std::endl;
return EXIT_SUCCESS;
}
if( vm.count( "help" ))
{
case 's':
session = optarg;
break;
std::cout << desc << std::endl;
return EXIT_SUCCESS;
}

case '?':
std::cout << "Usage: " << argv[0] << " [-s sessionName]" << std::endl;
break;
if( vm.count( "session" ))
session = vm["session"].as< std::string >();
#endif

default: // ??
case -1: // end
break;
const GPUInfos gpus = gpusd::Module::discoverGPUs();
if( gpus.empty( ))
{
std::cerr << "No GPUs found, quitting" << std::endl;
return EXIT_FAILURE;
}
#else
// TODO: getopt not available for WIN32
#endif

TXTRecordRef record;
TXTRecordCreate( &record, 0, 0 );
Expand Down

0 comments on commit ad9f1c9

Please sign in to comment.