Commit 8fb65182 authored by Etienne Schmitt's avatar Etienne Schmitt

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

Signed-off-by: Etienne Schmitt's avatarÉtienne Schmitt <etienne.schmitt@inria.fr>
parent 80265842
......@@ -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
......@@ -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 ()
......
# 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