diff options
author | Marcus Asteborg <maastebo@microsoft.com> | 2020-04-13 15:51:48 -0700 |
---|---|---|
committer | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2020-04-20 22:47:56 -0400 |
commit | a0e14e7117fbb05e0ebcfd891188746096531d02 (patch) | |
tree | 5710a1e24ab4e7007e1908587df20a5f291a0e94 /cmake | |
parent | 7628d844b4a0435c676fbe9ef03b3c2f8bf3eb5f (diff) | |
download | libopus-a0e14e7117fbb05e0ebcfd891188746096531d02.tar.gz |
cmake - Add variable length detection and alloca detection
Signed-off-by: Jean-Marc Valin <jmvalin@jmvalin.ca>
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/CFeatureCheck.cmake | 39 | ||||
-rw-r--r-- | cmake/vla.c | 7 |
2 files changed, 46 insertions, 0 deletions
diff --git a/cmake/CFeatureCheck.cmake b/cmake/CFeatureCheck.cmake new file mode 100644 index 00000000..4059f434 --- /dev/null +++ b/cmake/CFeatureCheck.cmake @@ -0,0 +1,39 @@ +# - 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 +# +# c_feature_check(<FLAG> [<VARIANT>]) +# +# - Example +# +# include(CFeatureCheck) +# c_feature_check(VLA) + +if(__c_feature_check) + return() +endif() +set(__c_feature_check INCLUDED) + +function(c_feature_check FILE) + string(TOLOWER ${FILE} FILE) + string(TOUPPER ${FILE} VAR) + string(TOUPPER "${VAR}_SUPPORTED" FEATURE) + if (DEFINED ${VAR}_SUPPORTED) + set(${VAR}_SUPPORTED 1 PARENT_SCOPE) + return() + endif() + + if (NOT DEFINED COMPILE_${FEATURE}) + message(STATUS "Performing Test ${FEATURE}") + try_compile(COMPILE_${FEATURE} ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/${FILE}.c) + endif() + + if(COMPILE_${FEATURE}) + message(STATUS "Performing Test ${FEATURE} -- success") + set(${VAR}_SUPPORTED 1 PARENT_SCOPE) + else() + message(STATUS "Performing Test ${FEATURE} -- failed to compile") + endif() +endfunction()
\ No newline at end of file diff --git a/cmake/vla.c b/cmake/vla.c new file mode 100644 index 00000000..e83829e5 --- /dev/null +++ b/cmake/vla.c @@ -0,0 +1,7 @@ +int main() { + static int x; + char a[++x]; + a[sizeof a - 1] = 0; + int N; + return a[0]; +}
\ No newline at end of file |