Resolve regular expression engines

This commit is contained in:
Matt Clarkson 2014-07-31 15:20:20 +01:00
parent fac16a662e
commit edfa60a1d1
6 changed files with 81 additions and 8 deletions

View File

@ -77,6 +77,12 @@ message("-- Version: ${VERSION}")
set(GENERIC_LIB_VERSION ${VERSION})
string(SUBSTRING ${VERSION} 0 1 GENERIC_LIB_SOVERSION)
# C++ feature checks
include(CXXFeatureCheck)
cxx_feature_check(STD_REGEX)
cxx_feature_check(GNU_POSIX_REGEX)
cxx_feature_check(POSIX_REGEX)
# Set up directories
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${PROJECT_SOURCE_DIR}/src)

View File

@ -1,21 +1,21 @@
# - Adds a compiler FLAG if it is supported by the compiler
# - Adds a compiler flag if it is supported by the compiler
#
# This function checks that the supplied compiler FLAG is supported and then
# adds it to the corresponding compiler FLAGs
# This function checks that the supplied compiler flag is supported and then
# adds it to the corresponding compiler flags
#
# add_cxx_compiler_FLAG(<FLAG> [<VARIANT>])
# add_cxx_compiler_flag(<FLAG> [<VARIANT>])
#
# - Example
#
# include(AddCXXCompilerFlag)
# add_cxx_compiler_FLAG(-Wall)
# add_cxx_compiler_FLAG(-no-strict-aliasing RELEASE)
# add_cxx_compiler_flag(-Wall)
# add_cxx_compiler_flag(-no-strict-aliasing RELEASE)
# Requires CMake 2.6+
if(__add_cxx_compiler_FLAG)
if(__add_cxx_compiler_flag)
return()
endif()
set(__add_cxx_compiler_FLAG INCLUDED)
set(__add_cxx_compiler_flag INCLUDED)
include(CheckCXXCompilerFlag)

View File

@ -0,0 +1,35 @@
# - Compile and run code to check for C++ features
#
# This functions compiles a source file under the `cmake` folder
# and adds the corresponding `HAVE_[FILENAME]` flag to the CMake
# environment
#
# add_cxx_compiler_FLAG(<FLAG> [<VARIANT>])
#
# - Example
#
# include(AddCXXCompilerFlag)
# add_cxx_compiler_FLAG(-Wall)
# add_cxx_compiler_FLAG(-no-strict-aliasing RELEASE)
# Requires CMake 2.6+
if(__cxx_feature_check_FLAG)
return()
endif()
set(__cxx_feature_check_FLAG INCLUDED)
function(cxx_feature_check FILE)
string(TOLOWER ${FILE} FILE)
string(TOUPPER ${FILE} VAR)
string(TOUPPER "HAVE_${VAR}" FEATURE)
message("-- Performing Test ${FEATURE}")
try_run(RUN_${FEATURE} COMPILE_${FEATURE} ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${FILE}.cpp)
if(RUN_${FEATURE} EQUAL 0)
message("-- Performing Test ${FEATURE} -- Success")
set(HAVE_${VAR} 1 PARENT_SCOPE)
add_definitions(-DHAVE_${VAR})
else()
message("-- Performing Test ${FEATURE} -- Failed")
endif()
endfunction()

12
cmake/gnu_posix_regex.cpp Normal file
View File

@ -0,0 +1,12 @@
#include <gnuregex.h>
#include <string>
int main() {
std::string str = "test0159";
regex_t re;
int ec = regcomp(&re, "^[a-z]+[0-9]+$", REG_EXTENDED | REG_NOSUB);
if (ec != 0) {
return ec;
}
return regexec(&re, str.c_str(), 0, NULL, 0) ? -1 : 0;
}

12
cmake/posix_regex.cpp Normal file
View File

@ -0,0 +1,12 @@
#include <regex.h>
#include <string>
int main() {
std::string str = "test0159";
regex_t re;
int ec = regcomp(&re, "^[a-z]+[0-9]+$", REG_EXTENDED | REG_NOSUB);
if (ec != 0) {
return ec;
}
return regexec(&re, str.c_str(), 0, NULL, 0) ? -1 : 0;
}

8
cmake/std_regex.cpp Normal file
View File

@ -0,0 +1,8 @@
#include <regex>
#include <string>
int main() {
const std::string str = "test0159";
const std::regex re("^[a-z]+[0-9]+$", std::regex_constants::extended | std::regex_constants::nosubs);
return std::regex_search(str, re) ? 0 : -1;
}