]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
Enable cross compilation to aarch64
authorGeorge Wort <george.wort@arm.com>
Mon, 17 May 2021 14:17:38 +0000 (15:17 +0100)
committerKonstantinos Margaritis <konstantinos@vectorcamp.gr>
Tue, 12 Oct 2021 08:51:34 +0000 (11:51 +0300)
Change-Id: Iafc8ac60926f5286990ce63a4ff4f8b6a7c46bef

CMakeLists.txt
LICENSE
README.md
cmake/arm64-cross.cmake [new file with mode: 0644]
cmake/config.h.in
cmake/platform.cmake
cmake/setenv-arm64-cross.sh [new file with mode: 0644]

index 6b001e945d09200c59c3455cb4b97212729664df..e32be7b30f9e1f9a6f7283a378766f77ea5ca115 100644 (file)
@@ -209,7 +209,7 @@ else()
             message(SEND_ERROR "Something went wrong determining gcc tune: -mtune=${GNUCC_ARCH} not valid")
         endif()
         set(TUNE_FLAG ${GNUCC_ARCH})
-    else ()
+    elseif (NOT TUNE_FLAG)
         set(TUNE_FLAG native)
     endif()
 
@@ -252,11 +252,11 @@ else()
     endif()
 
     if (NOT CMAKE_C_FLAGS MATCHES .*march.* AND NOT CMAKE_C_FLAGS MATCHES .*mtune.*)
-        set(ARCH_C_FLAGS "-march=native -mtune=${TUNE_FLAG}")
+        set(ARCH_C_FLAGS "-march=${GNUCC_ARCH} -mtune=${TUNE_FLAG}")
     endif()
 
     if (NOT CMAKE_CXX_FLAGS MATCHES .*march.* AND NOT CMAKE_CXX_FLAGS MATCHES .*mtune.*)
-        set(ARCH_CXX_FLAGS "-march=native -mtune=${TUNE_FLAG}")
+        set(ARCH_CXX_FLAGS "-march=${GNUCC_ARCH} -mtune=${TUNE_FLAG}")
     endif()
 
     if(CMAKE_COMPILER_IS_GNUCC)
@@ -460,7 +460,11 @@ endif()
 endif()
 
 if (NOT FAT_RUNTIME)
-    message(STATUS "Building for current host CPU: ${ARCH_C_FLAGS}")
+    if (CROSS_COMPILE_AARCH64)
+        message(STATUS "Building for target CPU: ${ARCH_C_FLAGS}")
+    else()
+        message(STATUS "Building for current host CPU: ${ARCH_C_FLAGS}")
+    endif()
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARCH_C_FLAGS}")
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARCH_CXX_FLAGS}")
 else()
diff --git a/LICENSE b/LICENSE
index 3a32e2810e3cb946b01348bb0367b758492338a8..8324617bf5fb2e219c8b3bb6327b9b39422002c8 100644 (file)
--- a/LICENSE
+++ b/LICENSE
@@ -5,6 +5,7 @@ Copyright (c) 2015, Intel Corporation
 Vectorscan is licensed under the BSD License.
 
 Copyright (c) 2020, VectorCamp PC
+Copyright (c) 2021, Arm Limited
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:
index 4a6e6fc0976aa7b4b5436e090f33e2b5c2123c2c..e780238f651c88da8f83d0d013d3af32f89ec726 100644 (file)
--- a/README.md
+++ b/README.md
@@ -29,6 +29,22 @@ matching of regular expressions across streams of data.
 
 Vectorscan is typically used in a DPI library stack, just like Hyperscan.
 
+# Cross Compiling for AArch64
+
+- To cross compile for AArch64, first adjust the variables set in cmake/setenv-arm64-cross.sh.
+  - `export CROSS=<arm-cross-compiler-dir>/bin/aarch64-linux-gnu-`
+  - `export CROSS_SYS=<arm-cross-compiler-system-dir>`
+  - `export BOOST_PATH=<boost-source-dir>`
+- Set the environment variables:
+  - `source cmake/setenv-arm64-cross.sh`
+- Configure Vectorscan:
+  - `mkdir <build-dir-name>`
+  - `cd <build-dir>`
+  - `cmake -DCROSS_COMPILE_AARCH64=1 <hyperscan-source-dir> -DCMAKE_TOOLCHAIN_FILE=<hyperscan-source-dir>/cmake/arm64-cross.cmake`
+- Build Vectorscan:
+  - `make -jT` where T is the number of threads used to compile.
+  - `cmake --build . -- -j T` can also be used instead of make.
+
 # Documentation
 
 Information on building the Hyperscan library and using its API is available in
diff --git a/cmake/arm64-cross.cmake b/cmake/arm64-cross.cmake
new file mode 100644 (file)
index 0000000..b95ca33
--- /dev/null
@@ -0,0 +1,22 @@
+set(CMAKE_SYSTEM_NAME "Linux")
+set(CMAKE_SYSTEM_PROCESSOR "aarch64")
+
+# specify the cross compiler
+set(CMAKE_C_COMPILER "$ENV{CROSS}gcc")
+set(CMAKE_CXX_COMPILER "$ENV{CROSS}g++")
+# where is the target environment
+set(CMAKE_SYSROOT $ENV{CROSS_SYS})
+
+set(Boost_INCLUDE_DIR $ENV{BOOST_PATH})
+
+# for libraries and headers in the target directories
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
+
+set(THREADS_PTHREAD_ARG "2" CACHE STRING "Result from TRY_RUN" FORCE)
+
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -falign-functions=16 -falign-jumps=16 -falign-labels=16 -falign-loops=16" CACHE STRING "" FORCE)
+
+set(GNUCC_ARCH "armv8.2-a+fp16+simd+rcpc+dotprod+crypto")
+set(TUNE_FLAG "neoverse-n1")
\ No newline at end of file
index 0de8cca2184741d920672f1c003d7b00a38ac70f..17c1e72933034f6dc9b21bfec02e500be9eecc2a 100644 (file)
@@ -21,6 +21,9 @@
 /* "Define if building for AARCH64" */
 #cmakedefine ARCH_AARCH64
 
+/* "Define if cross compiling for AARCH64" */
+#cmakedefine CROSS_COMPILE_AARCH64
+
 /* internal build, switch on dump support. */
 #cmakedefine DUMP_SUPPORT
 
index 479b36806b856a773629dadc062e79645d2d2aa8..295775df61c2fca4188b2260103279a1e1af4397 100644 (file)
@@ -1,15 +1,21 @@
 # determine the target arch
 
-# really only interested in the preprocessor here
-CHECK_C_SOURCE_COMPILES("#if !(defined(__x86_64__) || defined(_M_X64))\n#error not 64bit\n#endif\nint main(void) { return 0; }" ARCH_X86_64)
+if (CROSS_COMPILE_AARCH64)
+  set(ARCH_AARCH64 TRUE)
+  set(ARCH_64_BIT TRUE)
+  message(STATUS "Cross compiling for aarch64")
+else()
+  # really only interested in the preprocessor here
+  CHECK_C_SOURCE_COMPILES("#if !(defined(__x86_64__) || defined(_M_X64))\n#error not 64bit\n#endif\nint main(void) { return 0; }" ARCH_X86_64)
 
-CHECK_C_SOURCE_COMPILES("#if !(defined(__i386__) || defined(_M_IX86))\n#error not 32bit\n#endif\nint main(void) { return 0; }" ARCH_IA32)
+  CHECK_C_SOURCE_COMPILES("#if !(defined(__i386__) || defined(_M_IX86))\n#error not 32bit\n#endif\nint main(void) { return 0; }" ARCH_IA32)
 
-CHECK_C_SOURCE_COMPILES("#if !defined(__ARM_ARCH_ISA_A64)\n#error not 64bit\n#endif\nint main(void) { return 0; }" ARCH_AARCH64)
-CHECK_C_SOURCE_COMPILES("#if !defined(__ARM_ARCH_ISA_ARM)\n#error not 32bit\n#endif\nint main(void) { return 0; }" ARCH_ARM32)
+  CHECK_C_SOURCE_COMPILES("#if !defined(__ARM_ARCH_ISA_A64)\n#error not 64bit\n#endif\nint main(void) { return 0; }" ARCH_AARCH64)
+  CHECK_C_SOURCE_COMPILES("#if !defined(__ARM_ARCH_ISA_ARM)\n#error not 32bit\n#endif\nint main(void) { return 0; }" ARCH_ARM32)
 
-if (ARCH_X86_64 OR ARCH_AARCH64)
-  set(ARCH_64_BIT TRUE)
-else()
-  set(ARCH_32_BIT TRUE)
-endif()
+  if (ARCH_X86_64 OR ARCH_AARCH64)
+    set(ARCH_64_BIT TRUE)
+  else()
+    set(ARCH_32_BIT TRUE)
+  endif()
+endif()
\ No newline at end of file
diff --git a/cmake/setenv-arm64-cross.sh b/cmake/setenv-arm64-cross.sh
new file mode 100644 (file)
index 0000000..4858da1
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/bash
+export BOOST_VERSION=1_57_0
+export BOOST_DOT_VERSION=${BOOST_VERSION//_/.}
+export CROSS=<arm-cross-compiler-dir>/bin/aarch64-linux-gnu-
+export CROSS_SYS=<arm-cross-compiler-system-dir>
+
+# if [ ! -d "boost_$BOOST_VERSION" ];
+# then
+#      wget -O boost_$BOOST_VERSION.tar.gz https://sourceforge.net/projects/boost/files/boost/$BOOST_DOT_VERSION/boost_$BOOST_VERSION.tar.gz/download
+#      tar xf boost_$BOOST_VERSION.tar.gz
+# fi
+if [ ! -d "pcre-8.41" ];
+then
+       wget -O pcre-8.41.tar.bz2 https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.bz2
+       tar xf pcre-8.41.tar.bz2
+       export PCRE_SOURCE=1
+fi
+
+export BOOST_PATH=<boost-source-dir>
\ No newline at end of file