Skip to content
Snippets Groups Projects
Commit 763dd9a6 authored by Manuel Grizonnet's avatar Manuel Grizonnet
Browse files

ENH: restore MuParserHasCxxLogicalOperators mechanisms for backward compatibility

parent ce2b7d3b
No related branches found
No related tags found
No related merge requests found
......@@ -16,12 +16,10 @@
=========================================================================*/
#include "otbMath.h"
#include "otbConfigure.h"
#include "muParser.h"
#include "otbParser.h"
#include "otb_muparser.h"
namespace otb
{
......
#include <cstdlib>
#include "muParser.h"
int main(int argc, char *argv[])
{
// Test "&&" operator
// This will throw an exception if muParser version is < 2.0.0,
// which have "and" instead
mu::Parser parser;
parser.SetExpr("0 && 1");
try
{
double result = parser.Eval();
}
catch( const mu::Parser::exception_type& e )
{
std::cerr << "Message: " << e.GetMsg() << std::endl
<< "Formula: " << e.GetExpr() << std::endl
<< "Token: " << e.GetToken() << std::endl
<< "Position: " << e.GetPos() << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
......@@ -2,7 +2,43 @@ project(OTBMuParser)
set(OTBMuParser_SYSTEM_INCLUDE_DIRS ${MUPARSER_INCLUDE_DIRS})
set(OTBMuParser_LIBRARIES "${MUPARSER_LIBRARIES}")
set(OTBMuParser_INCLUDE_DIRS ${OTBMuParser_BINARY_DIR}/src)
# TODO : OTB_MUPARSER_HAS_CXX_LOGICAL_OPERATORS
# TODO : OTB_MUPARSER_HAS_CXX_LOGICAL_OPERATORS$
# Starting with muparser 2.0.0,
# intrinsic operators "and", "or", "xor" have been removed
# and intrinsic operators "&&" and "||" have been introduced as replacements
include(CheckCXXSourceRuns)
set(CMAKE_REQUIRED_INCLUDES ${OTBMuParser_SYSTEM_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${OTBMuParser_LIBRARIES})
unset(CMAKE_REQUIRED_FLAGS)
unset(CMAKE_REQUIRED_DEFINES)
file(READ ${OTBMuParser_SOURCE_DIR}/CMake/otbTestMuParserHasCxxLogicalOperators.cxx
OTB_MUPARSER_HAS_CXX_LOGICAL_OPERATORS_SOURCEFILE)
check_cxx_source_runs(
"${OTB_MUPARSER_HAS_CXX_LOGICAL_OPERATORS_SOURCEFILE}"
OTB_MUPARSER_HAS_CXX_LOGICAL_OPERATORS
)
unset(CMAKE_REQUIRED_INCLUDES)
unset(CMAKE_REQUIRED_LIBRARIES)
unset(CMAKE_REQUIRED_FLAGS)
unset(CMAKE_REQUIRED_DEFINES)
if(OTB_MUPARSER_HAS_CXX_LOGICAL_OPERATORS)
message(STATUS " MuParser version is >= 2.0.0 : "
"uses '&&' and '||' logical operators, and C++ like "
"ternary if-then-else operator")
else()
message(STATUS " MuParser version is < 2.0.0 : "
"uses 'and' and 'or' logical operators, and ternary "
"operator 'if( ; ; )'")
endif()
configure_file( src/otb_muparser.h.in src/otb_muparser.h )
otb_module_impl()
install(FILES ${OTBMuParser_BINARY_DIR}/src/otb_muparser.h
DESTINATION ${OTBMuParser_INSTALL_INCLUDE_DIR}
COMPONENT Development
)
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otb_muparser_h
/* MuParser has "&&" and "||" operators (version >= 2.0.0), instead of "and" and "or" (version <2.0.0 version) */
#cmakedefine OTB_MUPARSER_HAS_CXX_LOGICAL_OPERATORS
#include "muParser.h"
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment