aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Clarkson <mattyclarkson@gmail.com>2014-07-31 15:20:20 +0100
committerMatt Clarkson <mattyclarkson@gmail.com>2014-08-22 14:55:46 +0100
commitedfa60a1d12ab746e088c216fafbfc4d7a6c50e6 (patch)
treef22410f58671a266f9b4439cd45f688525631983
parentfac16a662efb4ded79f74c795d81bdd688cb49a7 (diff)
downloadgoogle-benchmark-edfa60a1d12ab746e088c216fafbfc4d7a6c50e6.tar.gz
Resolve regular expression engines
-rw-r--r--CMakeLists.txt6
-rw-r--r--cmake/AddCXXCompilerFlag.cmake16
-rw-r--r--cmake/CXXFeatureCheck.cmake35
-rw-r--r--cmake/gnu_posix_regex.cpp12
-rw-r--r--cmake/posix_regex.cpp12
-rw-r--r--cmake/std_regex.cpp8
6 files changed, 81 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 80650c5..340055c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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)
diff --git a/cmake/AddCXXCompilerFlag.cmake b/cmake/AddCXXCompilerFlag.cmake
index d4a2de0..31a284f 100644
--- a/cmake/AddCXXCompilerFlag.cmake
+++ b/cmake/AddCXXCompilerFlag.cmake
@@ -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)
diff --git a/cmake/CXXFeatureCheck.cmake b/cmake/CXXFeatureCheck.cmake
new file mode 100644
index 0000000..9d80904
--- /dev/null
+++ b/cmake/CXXFeatureCheck.cmake
@@ -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()
+
diff --git a/cmake/gnu_posix_regex.cpp b/cmake/gnu_posix_regex.cpp
new file mode 100644
index 0000000..480ab25
--- /dev/null
+++ b/cmake/gnu_posix_regex.cpp
@@ -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;
+}
+
diff --git a/cmake/posix_regex.cpp b/cmake/posix_regex.cpp
new file mode 100644
index 0000000..1f7fe07
--- /dev/null
+++ b/cmake/posix_regex.cpp
@@ -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;
+}
+
diff --git a/cmake/std_regex.cpp b/cmake/std_regex.cpp
new file mode 100644
index 0000000..4f227d4
--- /dev/null
+++ b/cmake/std_regex.cpp
@@ -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;
+}
+