Commit c53c5ae6 authored by Chris Cantwell's avatar Chris Cantwell

Updated Boost detection to look for Regex library

Moved all ErrorUtil code to header file to avoid needing to link LibUtilities
parent 024b0176
......@@ -7,7 +7,8 @@ IF (THIRDPARTY_BUILD_BOOST)
IF (NOT WIN32)
# Only build the libraries we need
SET(BOOST_LIB_LIST --with-system --with-iostreams --with-filesystem
--with-program_options --with-date_time --with-thread)
--with-program_options --with-date_time --with-thread
--with-regex)
# We need -fPIC for 64-bit builds
IF( CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )
......@@ -56,6 +57,9 @@ IF (THIRDPARTY_BUILD_BOOST)
SET(Boost_PROGRAM_OPTIONS_LIBRARY boost_program_options)
SET(Boost_PROGRAM_OPTIONS_LIBRARY_DEBUG boost_program_options)
SET(Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE boost_program_options)
SET(Boost_REGEX_LIBRARY boost_regex)
SET(Boost_REGEX_LIBRARY_DEBUG boost_regex)
SET(Boost_REGEX_LIBRARY_RELEASE boost_regex)
SET(Boost_SYSTEM_LIBRARY boost_system)
SET(Boost_SYSTEM_LIBRARY_DEBUG boost_system)
SET(Boost_SYSTEM_LIBRARY_RELEASE boost_system)
......@@ -88,13 +92,13 @@ ELSE (THIRDPARTY_BUILD_BOOST)
IF( NOT BOOST_ROOT )
#If the user has not set BOOST_ROOT, look in a couple common places first.
SET(BOOST_ROOT ${CMAKE_SOURCE_DIR}/ThirdParty/boost)
FIND_PACKAGE( Boost COMPONENTS thread iostreams zlib date_time filesystem system program_options)
FIND_PACKAGE( Boost COMPONENTS thread iostreams zlib date_time filesystem system program_options regex)
SET(BOOST_ROOT ${CMAKE_SOURCE_DIR}/../ThirdParty/boost)
FIND_PACKAGE( Boost COMPONENTS thread iostreams zlib date_time filesystem system program_options)
FIND_PACKAGE( Boost COMPONENTS thread iostreams zlib date_time filesystem system program_options regex)
SET(BOOST_ROOT ${CMAKE_SOURCE_DIR}/ThirdParty/dist)
FIND_PACKAGE( Boost COMPONENTS thread iostreams zlib date_time filesystem system program_options)
FIND_PACKAGE( Boost COMPONENTS thread iostreams zlib date_time filesystem system program_options regex)
ELSE()
FIND_PACKAGE( Boost COMPONENTS thread iostreams zlib date_time filesystem system program_options)
FIND_PACKAGE( Boost COMPONENTS thread iostreams zlib date_time filesystem system program_options regex)
ENDIF()
ENDIF (THIRDPARTY_BUILD_BOOST)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
///////////////////////////////////////////////////////////////////////////////
//
// File ErrorUtil.cpp
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: error related utilities
//
///////////////////////////////////////////////////////////////////////////////
#include <LibUtilities/BasicUtils/ErrorUtil.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/optional.hpp>
#include <iostream>
namespace ErrorUtil
{
boost::optional<std::ostream&> outStream;
void SetErrorStream(std::ostream& o)
{
outStream = o;
}
bool HasCustomErrorStream()
{
return outStream;
}
void Error(ErrType type, const char *routine, int lineNumber, const char *msg, unsigned int level)
{
// The user of outStream is primarily for the unit tests.
// The unit tests often generate errors on purpose to make sure
// invalid usage is flagged appropriately. Printing the error
// messages to cerr made the unit test output hard to parse.
std::string baseMsg = std::string("Level ") +
boost::lexical_cast<std::string>(level) +
std::string(" assertion violation\n") +
#if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
std::string("Where : ") + boost::lexical_cast<std::string>(routine) + std::string("[") + boost::lexical_cast<std::string>(lineNumber) + std::string("]\n") + std::string("Message : ") +
#endif
msg;
switch(type)
{
case efatal:
if( outStream )
{
(*outStream) << "Fatal : " << baseMsg << std::endl;
}
else
{
std::cerr << std::endl << "Fatal : " << baseMsg << std::endl;
}
throw NekError(baseMsg);
break;
case ewarning:
if( outStream )
{
(*outStream) << "Warning: " << baseMsg << std::endl;
}
else
{
std::cerr << "Warning: " << baseMsg << std::endl;
}
break;
default:
std::cerr << "Unknown warning type: " << baseMsg << std::endl;
}
}
void Error(ErrType type, const char *routine, int lineNumber, const std::string& msg, unsigned int level)
{
Error(type, routine, lineNumber, msg.c_str(), level);
}
void Error(ErrType type, const char *routine, int lineNumber, const char *msg)
{
Error(type, routine, lineNumber, msg, 0);
}
}
......@@ -38,12 +38,22 @@
#include <iostream>
#include <stdexcept>
#include <boost/lexical_cast.hpp>
#include <boost/optional.hpp>
#include <LibUtilities/LibUtilitiesDeclspec.h>
namespace ErrorUtil
{
LIB_UTILITIES_EXPORT void SetErrorStream(std::ostream& o);
LIB_UTILITIES_EXPORT bool HasCustomErrorStream();
static boost::optional<std::ostream&> outStream;
LIB_UTILITIES_EXPORT static void SetErrorStream(std::ostream& o)
{
outStream = o;
}
LIB_UTILITIES_EXPORT static bool HasCustomErrorStream()
{
return outStream;
}
enum ErrType
{
......@@ -57,10 +67,62 @@ namespace ErrorUtil
NekError(const std::string& message) : std::runtime_error(message) {}
};
LIB_UTILITIES_EXPORT void Error(ErrType type, const char *routine, int lineNumber, const char *msg, unsigned int level);
LIB_UTILITIES_EXPORT void Error(ErrType type, const char *routine, int lineNumber, const std::string& msg, unsigned int level);
LIB_UTILITIES_EXPORT void Error(ErrType type, const char *routine, int lineNumber, const char *msg);
LIB_UTILITIES_EXPORT static void Error(ErrType type, const char *routine, int lineNumber, const char *msg, unsigned int level)
{
// The user of outStream is primarily for the unit tests.
// The unit tests often generate errors on purpose to make sure
// invalid usage is flagged appropriately. Printing the error
// messages to cerr made the unit test output hard to parse.
std::string baseMsg = std::string("Level ") +
boost::lexical_cast<std::string>(level) +
std::string(" assertion violation\n") +
#if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
std::string("Where : ") + boost::lexical_cast<std::string>(routine) + std::string("[") + boost::lexical_cast<std::string>(lineNumber) + std::string("]\n") + std::string("Message : ") +
#endif
msg;
switch(type)
{
case efatal:
if( outStream )
{
(*outStream) << "Fatal : " << baseMsg << std::endl;
}
else
{
std::cerr << std::endl << "Fatal : " << baseMsg << std::endl;
}
throw NekError(baseMsg);
break;
case ewarning:
if( outStream )
{
(*outStream) << "Warning: " << baseMsg << std::endl;
}
else
{
std::cerr << "Warning: " << baseMsg << std::endl;
}
break;
default:
std::cerr << "Unknown warning type: " << baseMsg << std::endl;
}
}
LIB_UTILITIES_EXPORT static void Error(ErrType type, const char *routine, int lineNumber, const std::string& msg, unsigned int level)
{
Error(type, routine, lineNumber, msg.c_str(), level);
}
LIB_UTILITIES_EXPORT static void Error(ErrType type, const char *routine, int lineNumber, const char *msg)
{
Error(type, routine, lineNumber, msg, 0);
}
} // end of namespace
......
......@@ -113,7 +113,6 @@ SET(BasicUtilsHeaders
./BasicUtils/ConsistentObjectAccess.hpp
./BasicUtils/Equation.h
./BasicUtils/ErrorUtil.hpp
./BasicUtils/ErrorUtil.cpp
./BasicUtils/MeshPartition.h
./BasicUtils/NekManager.hpp
./BasicUtils/NekFactory.hpp
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment