diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d81cd5e5..67d27d319 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -301,6 +301,8 @@ OPTION(OSG_GL_VERTEX_FUNCS_AVAILABLE "Set to OFF to disable use of OpenGL vertex OPTION(OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE "Set to OFF to disable use of OpenGL vertex functions such as glVertex/glColor etc." ${OSG_GL1_AVAILABLE}) OPTION(OSG_GL_FIXED_FUNCTION_AVAILABLE "Set to OFF to disable use of OpenGL fixed function pipeline." ${OSG_GL1_AVAILABLE}) +OPTION(OSG_CPP_EXCEPTIONS_AVAILABLE "Set to OFF to disable compile of OSG components that use C++ exceptions." ON) + ################################################################################ # Set Config file diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 6a75383b8..4730eea67 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -58,7 +58,6 @@ IF(DYNAMIC_OPENSCENEGRAPH) ADD_SUBDIRECTORY(osglogicop) ADD_SUBDIRECTORY(osglogo) ADD_SUBDIRECTORY(osgmanipulator) - ADD_SUBDIRECTORY(osgmemorytest) ADD_SUBDIRECTORY(osgmovie) ADD_SUBDIRECTORY(osgmultiplerendertargets) ADD_SUBDIRECTORY(osgmultitexture) @@ -107,7 +106,6 @@ IF(DYNAMIC_OPENSCENEGRAPH) ADD_SUBDIRECTORY(osgtexturerectangle) ADD_SUBDIRECTORY(osgtexturecompression) ADD_SUBDIRECTORY(osgthirdpersonview) - ADD_SUBDIRECTORY(osgunittests) ADD_SUBDIRECTORY(osgvertexprogram) ADD_SUBDIRECTORY(osgvertexattributes) ADD_SUBDIRECTORY(osgvolume) @@ -137,16 +135,21 @@ IF(DYNAMIC_OPENSCENEGRAPH) ADD_SUBDIRECTORY(osgwidgettable) ADD_SUBDIRECTORY(osgwidgetwindow) -IF(NOT OSG_GLES1_AVAILABLE AND NOT OSG_GLES2_AVAILABLE AND NOT OSG_GL3_AVAILABLE) - ADD_SUBDIRECTORY(osgscreencapture) - ADD_SUBDIRECTORY(osgmotionblur) - ADD_SUBDIRECTORY(osgteapot) -ENDIF() + IF(OSG_CPP_EXCEPTIONS_AVAILABLE) + ADD_SUBDIRECTORY(osgunittests) + ADD_SUBDIRECTORY(osgmemorytest) + ENDIF() -IF(OSG_GLU_AVAILABLE) - ADD_SUBDIRECTORY(osgphotoalbum) - ADD_SUBDIRECTORY(osgtessellate) -ENDIF() + IF(NOT OSG_GLES1_AVAILABLE AND NOT OSG_GLES2_AVAILABLE AND NOT OSG_GL3_AVAILABLE) + ADD_SUBDIRECTORY(osgscreencapture) + ADD_SUBDIRECTORY(osgmotionblur) + ADD_SUBDIRECTORY(osgteapot) + ENDIF() + + IF(OSG_GLU_AVAILABLE) + ADD_SUBDIRECTORY(osgphotoalbum) + ADD_SUBDIRECTORY(osgtessellate) + ENDIF() ADD_SUBDIRECTORY(osgpdf) diff --git a/src/osgPlugins/CMakeLists.txt b/src/osgPlugins/CMakeLists.txt index 9fb5aefb9..4bc8b365f 100644 --- a/src/osgPlugins/CMakeLists.txt +++ b/src/osgPlugins/CMakeLists.txt @@ -164,7 +164,6 @@ ENDIF() ADD_SUBDIRECTORY(bvh) ADD_SUBDIRECTORY(x) -ADD_SUBDIRECTORY(ply) ADD_SUBDIRECTORY(dxf) ADD_SUBDIRECTORY(OpenFlight) # ADD_SUBDIRECTORY(flt) @@ -186,13 +185,17 @@ ADD_SUBDIRECTORY(md2) ADD_SUBDIRECTORY(osgtgz) ADD_SUBDIRECTORY(tgz) -ADD_SUBDIRECTORY(txp) ADD_SUBDIRECTORY(shp) ADD_SUBDIRECTORY(txf) ADD_SUBDIRECTORY(bsp) ADD_SUBDIRECTORY(mdl) +IF(OSG_CPP_EXCEPTIONS_AVAILABLE) + ADD_SUBDIRECTORY(ply) + ADD_SUBDIRECTORY(txp) +ENDIF() + IF(XINE_FOUND) ADD_SUBDIRECTORY(xine) ENDIF() diff --git a/src/osgPlugins/png/CMakeLists.txt b/src/osgPlugins/png/CMakeLists.txt index feeb14cd2..b090fb7ab 100644 --- a/src/osgPlugins/png/CMakeLists.txt +++ b/src/osgPlugins/png/CMakeLists.txt @@ -1,8 +1,13 @@ INCLUDE_DIRECTORIES( ${PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} ) +IF(OSG_CPP_EXCEPTIONS_AVAILABLE) + ADD_DEFINITIONS(-DOSG_CPP_EXCEPTIONS_AVAILABLE) +ENDIF() SET(TARGET_SRC ReaderWriterPNG.cpp ) SET(TARGET_LIBRARIES_VARS PNG_LIBRARY ZLIB_LIBRARY ) + + #### end var setup ### SETUP_PLUGIN(png) diff --git a/src/osgPlugins/png/ReaderWriterPNG.cpp b/src/osgPlugins/png/ReaderWriterPNG.cpp index e72f022ef..e652e09f7 100644 --- a/src/osgPlugins/png/ReaderWriterPNG.cpp +++ b/src/osgPlugins/png/ReaderWriterPNG.cpp @@ -51,7 +51,11 @@ private: void user_error_fn(png_structp png_ptr, png_const_charp error_msg) { +#ifdef OSG_CPP_EXCEPTIONS_AVAILABLE throw PNGError(error_msg); +#else + osg::notify(osg::WARN) << "PNG lib warning : " << error_msg << std::endl; +#endif } void user_warning_fn(png_structp png_ptr, png_const_charp warning_msg) @@ -166,9 +170,10 @@ class ReaderWriterPNG : public osgDB::ReaderWriter // Set custom error handlers png_set_error_fn(png, png_get_error_ptr(png), user_error_fn, user_warning_fn); + #ifdef OSG_CPP_EXCEPTIONS_AVAILABLE try + #endif { - info = png_create_info_struct(png); endinfo = png_create_info_struct(png); @@ -300,13 +305,16 @@ class ReaderWriterPNG : public osgDB::ReaderWriter osg::Image::USE_NEW_DELETE); return pOsgImage; + } + #ifdef OSG_CPP_EXCEPTIONS_AVAILABLE catch (PNGError& err) { osg::notify(osg::WARN) << err << std::endl; png_destroy_read_struct(&png, &info, &endinfo); return ReadResult::ERROR_IN_READING_FILE; } + #endif } int getCompressionLevel(const osgDB::ReaderWriter::Options *options) const