Commit b547a03f authored by Sylvain Thery's avatar Sylvain Thery

Merge branch 'develop' into 'develop'

Develop

Checking in cmake with try_run if std::regex are supported.

See merge request !58
parents 80265842 5897cc74
......@@ -40,7 +40,7 @@ qt_wrap_cpp( viewer_moc viewer.h )
add_executable( viewer viewer.cpp ${viewer_moc} ${viewer_ui} )
target_link_libraries( viewer ${CGoGN_LIBS} ${NUMERICAL_LIBS} ${CGoGN_EXT_LIBS} )
IF (CGoGN_GCC_4_9)
IF (HAS_CPP11_REGEX)
qt_wrap_ui( clipping_ui clipping.ui )
qt_wrap_cpp( clipping_moc clipping.h )
add_executable( clipping clipping.cpp ${clipping_ui} ${clipping_moc} )
......
......@@ -2,4 +2,9 @@
cgogn_gmx.h
cgogn_mr.h
cgogn_onelib.h
cgogn_assimp.h
cgogn_defs.h
cgogn_ext_includes.h
cgogn_ext_libs.h
cgogn_qt.h
cgogn_zinri.h
......@@ -22,8 +22,16 @@
* *
*******************************************************************************/
#define CGoGN_UTILS_DLL_EXPORT 1
#include "Utils/shaderMutator.h"
#ifndef HAS_CPP11_REGEX
#include <boost/regex.hpp>
#define REGEX_NAMESPACE boost
#else
#include <regex>
#define REGEX_NAMESPACE std
#endif
#include "Utils/shaderMutator.h"
namespace CGoGN
{
......@@ -38,8 +46,6 @@ namespace Utils
*
***********************************************/
#ifdef CGOGN_GCC_4_9
ShaderMutator::ShaderMutator(const std:: string& shaderName, const std::string& vertShaderSrc, const std::string& fragShaderSrc, const std::string& geomShaderSrc)
{
......@@ -454,15 +460,15 @@ bool ShaderMutator::srcContainsVariableDeclaration(const std::string& variableNa
{
// Regular expression for variable declaration
// <',' OR white-space[1 or more times]> <variableName> <',' OR ';' OR white-space>
std::regex var_re("(,|\\s+)" + variableName + "(,|;|\\s)");
REGEX_NAMESPACE::regex var_re("(,|\\s+)" + variableName + "(,|;|\\s)");
// Matches results
std::match_results <std::string::iterator> matches;
REGEX_NAMESPACE::match_results <std::string::iterator> matches;
// Search for the first expression that matches and isn't commented
std::string::iterator start = src.begin();
std::string::iterator end = src.end();
while (std::regex_search(start, end, matches, var_re, std::regex_constants::format_first_only))
while (REGEX_NAMESPACE::regex_search(start, end, matches, var_re, REGEX_NAMESPACE::regex_constants::format_first_only))
{
// Start position of the match
size_t startPosition = std::distance(src.begin(), matches[0].first);
......@@ -483,10 +489,10 @@ bool ShaderMutator::srcSetMinShadingLanguageVersion(int version, std::string& mo
{
// Regular expression for shading language version
// <#version> <white-space>[1 or more times] <digit>[1 or more times]
std::regex version_re("#version\\s+(\\d+)");
REGEX_NAMESPACE::regex version_re("#version\\s+(\\d+)");
// Matches results
std::match_results <std::string::iterator> matches;
REGEX_NAMESPACE::match_results <std::string::iterator> matches;
// Build the version string
std::string versionStr;
......@@ -497,7 +503,7 @@ bool ShaderMutator::srcSetMinShadingLanguageVersion(int version, std::string& mo
// Search for the first expression that matches and isn't commented
std::string::iterator start = modifiedSrc.begin();
std::string::iterator end = modifiedSrc.end();
while (std::regex_search(start, end, matches, version_re, std::regex_constants::format_first_only))
while (REGEX_NAMESPACE::regex_search(start, end, matches, version_re, REGEX_NAMESPACE::regex_constants::format_first_only))
{
// Start position of the match
size_t startPosition = std::distance(modifiedSrc.begin(), matches[0].first);
......@@ -538,10 +544,10 @@ bool ShaderMutator::srcChangeIntConstantValue(int newVal, const std::string& con
{
// Regular expression for constant expression
// <#define> <white-space>[1 or more times] <constant name> <white-space>[1 or more times] <digit>[1 or more times]
std::regex const_re("#define\\s+" + constantName + "\\s+(\\d+)");
REGEX_NAMESPACE::regex const_re("#define\\s+" + constantName + "\\s+(\\d+)");
// Matches results
std::match_results <std::string::iterator> matches;
REGEX_NAMESPACE::match_results <std::string::iterator> matches;
// Build the constant value string
std::string newValStr;
......@@ -552,7 +558,7 @@ bool ShaderMutator::srcChangeIntConstantValue(int newVal, const std::string& con
// Search for the first expression that matches and isn't commented
std::string::iterator start = modifiedSrc.begin();
std::string::iterator end = modifiedSrc.end();
while (std::regex_search(start, end, matches, const_re, std::regex_constants::format_first_only))
while (REGEX_NAMESPACE::regex_search(start, end, matches, const_re, REGEX_NAMESPACE::regex_constants::format_first_only))
{
// Start position of the match
size_t startPosition = std::distance(modifiedSrc.begin(), matches[0].first);
......@@ -585,10 +591,10 @@ bool ShaderMutator::srcChangeFloatConstantValue(float newVal, const std::string&
// Regular expression for constant expression
// <#define> <white-space>[1 or more times] <constant name> <white-space>[1 or more times]
// <digit>[1 or more times] <.>[0 or 1 time] <digit>[0 or more times]
std::regex const_re("#define\\s+" + constantName + "\\s+(\\d+\\.?\\d*)");
REGEX_NAMESPACE::regex const_re("#define\\s+" + constantName + "\\s+(\\d+\\.?\\d*)");
// Matches results
std::match_results <std::string::iterator> matches;
REGEX_NAMESPACE::match_results <std::string::iterator> matches;
// Build the constant value string
std::string newValStr;
......@@ -599,7 +605,7 @@ bool ShaderMutator::srcChangeFloatConstantValue(float newVal, const std::string&
// Search for the first expression that matches and isn't commented
std::string::iterator start = modifiedSrc.begin();
std::string::iterator end = modifiedSrc.end();
while (std::regex_search(start, end, matches, const_re, std::regex_constants::format_first_only))
while (REGEX_NAMESPACE::regex_search(start, end, matches, const_re, REGEX_NAMESPACE::regex_constants::format_first_only))
{
// Start position of the match
size_t startPosition = std::distance(modifiedSrc.begin(), matches[0].first);
......@@ -631,15 +637,15 @@ bool ShaderMutator::srcInsertCodeBeforeMainFunction(const std::string& insertedC
{
// Regular expression for main function
// <void> <white-space>[1 or more times] <main> <white-space>[0 or more times] <'('>
std::regex main_re("(void)\\s+(main)\\s*\\(");
REGEX_NAMESPACE::regex main_re("(void)\\s+(main)\\s*\\(");
// Matches results
std::match_results <std::string::iterator> matches;
REGEX_NAMESPACE::match_results <std::string::iterator> matches;
// Search for the first expression that matches and isn't commented
std::string::iterator start = modifiedSrc.begin();
std::string::iterator end = modifiedSrc.end();
while (std::regex_search(start, end, matches, main_re, std::regex_constants::format_first_only))
while (REGEX_NAMESPACE::regex_search(start, end, matches, main_re, REGEX_NAMESPACE::regex_constants::format_first_only))
{
// Start position of the match
size_t startPosition = std::distance(modifiedSrc.begin(), matches[0].first);
......@@ -667,15 +673,15 @@ bool ShaderMutator::srcInsertCodeAtMainFunctionBeginning(const std::string& inse
// <void> <white-space>[1 or more times] <main> <white-space>[0 or more times]
// <'('> <white-space>[0 or more times] <')'>
// <white-space>[0 or more times] <'{'>
std::regex main_re("(void)\\s+(main)\\s*\\(\\s*\\)\\s*\\{");
REGEX_NAMESPACE::regex main_re("(void)\\s+(main)\\s*\\(\\s*\\)\\s*\\{");
// Matches results
std::match_results <std::string::iterator> matches;
REGEX_NAMESPACE::match_results <std::string::iterator> matches;
// Search for the first expression that matches and isn't commented
std::string::iterator start = modifiedSrc.begin();
std::string::iterator end = modifiedSrc.end();
while (std::regex_search(start, end, matches, main_re, std::regex_constants::format_first_only))
while (REGEX_NAMESPACE::regex_search(start, end, matches, main_re, REGEX_NAMESPACE::regex_constants::format_first_only))
{
// Start position of the match
size_t startPosition = std::distance(modifiedSrc.begin(), matches[0].first);
......@@ -706,16 +712,16 @@ bool ShaderMutator::srcInsertCodeAtMainFunctionEnd(const std::string& insertedCo
// <void> <white-space>[1 or more times] <main> <white-space>[0 or more times]
// <'('> <white-space>[0 or more times] <')'>
// <white-space>[0 or more times] <'{'>
std::regex main_re("(void)\\s+(main)\\s*\\(\\s*\\)\\s*\\{");
REGEX_NAMESPACE::regex main_re("(void)\\s+(main)\\s*\\(\\s*\\)\\s*\\{");
// Matches results
std::match_results <std::string::iterator> matches;
REGEX_NAMESPACE::match_results <std::string::iterator> matches;
// Search for the first expression that matches and isn't commented
std::string::iterator start = modifiedSrc.begin();
std::string::iterator end = modifiedSrc.end();
size_t mainFirstBracePos = 0; // The aim is first to find this position
while (std::regex_search(start, end, matches, main_re, std::regex_constants::format_first_only) && (mainFirstBracePos == 0))
while (REGEX_NAMESPACE::regex_search(start, end, matches, main_re, REGEX_NAMESPACE::regex_constants::format_first_only) && (mainFirstBracePos == 0))
{
// Start position of the match
size_t startPosition = std::distance(modifiedSrc.begin(), matches[0].first);
......@@ -782,106 +788,6 @@ bool ShaderMutator::srcInsertCodeAtMainFunctionEnd(const std::string& insertedCo
return true;
}
#else
ShaderMutator::ShaderMutator(const std:: string& /*shaderName*/, const std::string& /*vertShaderSrc*/, const std::string& /*fragShaderSrc*/, const std::string& /*geomShaderSrc*/)
{
}
bool ShaderMutator::containsVariableDeclaration(shaderSrcType /*srcType*/, const std::string& /*variableName*/)
{
bool result = false;
return result;
}
bool ShaderMutator::setMinShadingLanguageVersion(shaderSrcType /*srcType*/, int /*version*/)
{
bool result = false;
return result;
}
bool ShaderMutator::changeIntConstantValue(shaderSrcType /*srcType*/, const std::string& /*constantName*/, int /*newVal*/)
{
return true;
}
bool ShaderMutator::changeFloatConstantValue(shaderSrcType /*srcType*/, const std::string& /*constantName*/, float /*newVal*/)
{
return true;
}
bool ShaderMutator::insertCodeBeforeMainFunction(shaderSrcType /*srcType*/, const std::string& /*insertedCode*/)
{
return true;
}
bool ShaderMutator::insertCodeAtMainFunctionBeginning(shaderSrcType /*srcType*/, const std::string& /*insertedCode*/)
{
return true;
}
bool ShaderMutator::insertCodeAtMainFunctionEnd(shaderSrcType /*srcType*/, const std::string& /*insertedCode*/)
{
return true;
}
/***********************************************
*
* Private Section
*
***********************************************/
bool ShaderMutator::srcIsCommented(size_t /*pos*/, const std::string& /*src*/)
{
return false;
}
bool ShaderMutator::srcIsOneLineCommented(size_t /*pos*/, const std::string& /*src*/)
{
return false;
}
bool ShaderMutator::srcContainsVariableDeclaration(const std::string& /*variableName*/, std::string& /*src*/)
{
return false;
}
bool ShaderMutator::srcSetMinShadingLanguageVersion(int /*version*/, std::string& /*modifiedSrc*/)
{
return true;
}
bool ShaderMutator::srcChangeIntConstantValue(int /*newVal*/, const std::string& /*constantName*/, std::string& /*modifiedSrc*/)
{
return false;
}
bool ShaderMutator::srcChangeFloatConstantValue(float /*newVal*/, const std::string& /*constantName*/, std::string& /*modifiedSrc*/)
{
return false;
}
bool ShaderMutator::srcInsertCodeBeforeMainFunction(const std::string& /*insertedCode*/, std::string& /*modifiedSrc*/)
{
return false;
}
bool ShaderMutator::srcInsertCodeAtMainFunctionBeginning(const std::string& /*insertedCode*/, std::string& /*modifiedSrc*/)
{
return false;
}
bool ShaderMutator::srcInsertCodeAtMainFunctionEnd(const std::string& /*insertedCode*/, std::string& /*modifiedSrc*/)
{
return true;
}
#endif
} // namespace Utils
} // namespace CGoGN
......@@ -35,17 +35,11 @@ IF (WIN32)
SET ( CGoGN_WITH_QTCREATOR OFF CACHE BOOL "use QtCreator to compile (Experimental" )
ENDIF()
IF (NOT(WIN32 OR APPLE))
SET ( CGoGN_GCC_4_9 OFF CACHE BOOL "using gcc version > 4.9 (std::regex ok !)" )
ENDIF()
SET ( BUILD_SHARED_LIBS ON CACHE BOOL "if used all library are build as shared type (.so/.dylib/.dll)" )
checkCpp11Support()
checkCpp11Feature("regex" HAS_CPP11_REGEX "False")
setBuildType()
SET(EXECUTABLE_OUTPUT_PATH ${CGoGN_ROOT_DIR}/bin/)
IF(WIN32)
IF (CGoGN_WITH_QTCREATOR)
......@@ -176,8 +170,8 @@ IF (APPLE)
LIST(APPEND CGoGN_DEFS -DCGOGN_APPLE)
ENDIF ()
IF (CGoGN_GCC_4_9)
LIST(APPEND CGoGN_DEFS -DCGOGN_GCC_4_9)
IF (HAS_CPP11_REGEX)
LIST(APPEND CGoGN_DEFS -DHAS_CPP11_REGEX)
ENDIF ()
......@@ -249,6 +243,12 @@ IF(NOT WIN32)
LIST(APPEND CGoGN_EXT_LIBS pthread) #for c++11 thread
ENDIF()
IF (NOT HAS_CPP11_REGEX)
find_package(Boost COMPONENTS regex REQUIRED)
include_directories( ${Boost_INCLUDE_DIR} )
list(APPEND CGoGN_EXT_LIBS ${Boost_LIBRARIES})
ENDIF ()
include_directories(
${CGoGN_SRC_DIR}/include
......
# ignoring all build directory
*
# ignoring all build directory
*
......@@ -24,6 +24,29 @@ function(checkCpp11Support)
endfunction(checkCpp11Support)
function(checkCpp11Feature FEATURE RESULT IS_FATAL)
set(definitions "")
if (NOT MSVC)
set(definitions "-std=c++11")
endif(NOT MSVC)
set(source "${CMAKE_MODULE_PATH}/tests/cxx11-test-${FEATURE}.cpp")
set(bindir "${CMAKE_CURRENT_BINARY_DIR}/cxx11/cxx11_${FEATURE}")
try_run(run_result compile_result
${bindir} ${source}
COMPILE_DEFINITIONS ${definitions})
if (${run_result} EQUAL "1")
set(${RESULT} "True" PARENT_SCOPE)
message("Checking cpp11 feature support ${FEATURE} : OK")
else()
set(${RESULT} "False" PARENT_SCOPE)
if (${IS_FATAL})
message(FATAL_ERROR "Checking cpp11 feature support ${FEATURE} : Fail. Please update your compiler (GCC >= 4.9, Clang >= 3.5, VS 2013).")
else()
message("Checking cpp11 feature support ${FEATURE} : Fail.")
endif()
endif()
endfunction(checkCpp11Feature)
function(setBuildType)
IF (NOT (${CMAKE_BUILD_TYPE} MATCHES "Debug|Release"))
IF (${CMAKE_CURRENT_BINARY_DIR} MATCHES "(.*)Debug|(.*)debug|(.*)DEBUG")
......
#include <algorithm>
#include <regex>
int parse_line(std::string const& line)
{
std::string tmp;
if(std::regex_search(line, std::regex("(\\s)+(-)?(\\d)+//(-)?(\\d)+(\\s)+"))) {
tmp = std::regex_replace(line, std::regex("(-)?(\\d)+//(-)?(\\d)+"), std::string("V"));
} else if(std::regex_search(line, std::regex("(\\s)+(-)?(\\d)+/(-)?(\\d)+(\\s)+"))) {
tmp = std::regex_replace(line, std::regex("(-)?(\\d)+/(-)?(\\d)+"), std::string("V"));
} else if(std::regex_search(line, std::regex("(\\s)+(-)?(\\d)+/(-)?(\\d)+/(-)?(\\d)+(\\s)+"))) {
tmp = std::regex_replace(line, std::regex("(-)?(\\d)+/(-)?(\\d)+/(-)?(\\d)+"), std::string("V"));
} else {
tmp = std::regex_replace(line, std::regex("(-)?(\\d)+"), std::string("V"));
}
return static_cast<int>(std::count(tmp.begin(), tmp.end(), 'V'));
}
int main()
{
bool test = (parse_line("f 7/7/7 -3/3/-3 2/-2/2") == 3) &&
(parse_line("f 7//7 3//-3 -2//2") == 3) &&
(parse_line("f 7/7 3/-3 -2/2") == 3) &&
(parse_line("f 7 3 -2") == 3);
return test;
}
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