blob: b106f32b639340c0da0120363cb3b289bc41e83b [file] [log] [blame]
Eric Fiselierb08d8b12016-07-19 23:07:03 +00001# - Compile and run code to check for C++ features
2#
3# This functions compiles a source file under the `cmake` folder
4# and adds the corresponding `HAVE_[FILENAME]` flag to the CMake
5# environment
6#
7# cxx_feature_check(<FLAG> [<VARIANT>])
8#
9# - Example
10#
11# include(CXXFeatureCheck)
12# cxx_feature_check(STD_REGEX)
13# Requires CMake 2.6+
14
15if(__cxx_feature_check)
16 return()
17endif()
18set(__cxx_feature_check INCLUDED)
19
20function(cxx_feature_check FILE)
21 string(TOLOWER ${FILE} FILE)
22 string(TOUPPER ${FILE} VAR)
23 string(TOUPPER "HAVE_${VAR}" FEATURE)
24 if (DEFINED HAVE_${VAR})
25 return()
26 endif()
27 message("-- Performing Test ${FEATURE}")
28 try_run(RUN_${FEATURE} COMPILE_${FEATURE}
Eric Fiselier4d5e91d2016-08-29 19:12:01 +000029 ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${FILE}.cpp
30 CMAKE_FLAGS ${BENCHMARK_CXX_LINKER_FLAGS}
31 LINK_LIBRARIES ${BENCHMARK_CXX_LIBRARIES})
Eric Fiselierb08d8b12016-07-19 23:07:03 +000032 if(RUN_${FEATURE} EQUAL 0)
33 message("-- Performing Test ${FEATURE} -- success")
34 set(HAVE_${VAR} 1 CACHE INTERNAL "Feature test for ${FILE}" PARENT_SCOPE)
35 add_definitions(-DHAVE_${VAR})
36 else()
37 if(NOT COMPILE_${FEATURE})
38 message("-- Performing Test ${FEATURE} -- failed to compile")
39 else()
40 message("-- Performing Test ${FEATURE} -- compiled but failed to run")
41 endif()
42 endif()
43endfunction()
44