Detect support for memfd_create at compilation 64/14364/3
authorPierre Pfister <ppfister@cisco.com>
Mon, 20 Aug 2018 12:59:45 +0000 (14:59 +0200)
committerDamjan Marion <dmarion@me.com>
Mon, 20 Aug 2018 14:43:01 +0000 (14:43 +0000)
Compilation was failing on systems without memfd_create.
This uses check_c_source_compiles to check whether the memfd_create
function is available on the system.

Credits to Damjan for his help troubleshooting.

Change-Id: I136d9504d7978e3a09438d0d76b2de1042702b2c
Signed-off-by: Pierre Pfister <ppfister@cisco.com>
src/CMakeLists.txt

index 790d6a2..84971c7 100644 (file)
@@ -118,7 +118,20 @@ find_package(Threads REQUIRED)
 find_package(OpenSSL REQUIRED)
 include_directories(${OPENSSL_INCLUDE_DIR})
 
-add_definitions(-DHAVE_MEMFD_CREATE -DVPP_API_TEST_BUILTIN=1)
+add_definitions(-DVPP_API_TEST_BUILTIN=1)
+
+##############################################################################
+# Check for memfd_create headers and libs
+##############################################################################
+check_c_source_compiles("
+  #define _GNU_SOURCE
+  #include <sys/mman.h>
+  int main() { return memfd_create (\"/dev/false\", 0); }
+" HAVE_MEMFD_CREATE)
+
+if (HAVE_MEMFD_CREATE)
+    add_definitions(-DHAVE_MEMFD_CREATE)
+endif()
 
 ##############################################################################
 # API