Skip to content

Commit 24ae167

Browse files
committed
WIP: Refactor CMake build system to more modular
1 parent 0e40310 commit 24ae167

11 files changed

+620
-754
lines changed

CMakeLists.txt

+110-504
Large diffs are not rendered by default.

README.md

-16
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,6 @@ matching of regular expressions across streams of data.
2929

3030
Vectorscan is typically used in a DPI library stack, just like Hyperscan.
3131

32-
# Cross Compiling for AArch64
33-
34-
- To cross compile for AArch64, first adjust the variables set in cmake/setenv-arm64-cross.sh.
35-
- `export CROSS=<arm-cross-compiler-dir>/bin/aarch64-linux-gnu-`
36-
- `export CROSS_SYS=<arm-cross-compiler-system-dir>`
37-
- `export BOOST_PATH=<boost-source-dir>`
38-
- Set the environment variables:
39-
- `source cmake/setenv-arm64-cross.sh`
40-
- Configure Vectorscan:
41-
- `mkdir <build-dir-name>`
42-
- `cd <build-dir>`
43-
- `cmake -DCROSS_COMPILE_AARCH64=1 <hyperscan-source-dir> -DCMAKE_TOOLCHAIN_FILE=<hyperscan-source-dir>/cmake/arm64-cross.cmake`
44-
- Build Vectorscan:
45-
- `make -jT` where T is the number of threads used to compile.
46-
- `cmake --build . -- -j T` can also be used instead of make.
47-
4832
# Compiling for SVE
4933

5034
The following cmake variables can be set in order to target Arm's Scalable

cmake/arch.cmake

-207
This file was deleted.

cmake/cflags-arm.cmake

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
if (NOT FAT_RUNTIME)
2+
if (BUILD_SVE2_BITPERM)
3+
message (STATUS "SVE2_BITPERM implies SVE2, enabling BUILD_SVE2")
4+
set(BUILD_SVE2 ON)
5+
endif ()
6+
if (BUILD_SVE2)
7+
message (STATUS "SVE2 implies SVE, enabling BUILD_SVE")
8+
set(BUILD_SVE ON)
9+
endif ()
10+
endif ()
11+
12+
if (ARCH_AARCH64)
13+
if (NOT FAT_RUNTIME)
14+
if (BUILD_SVE2_BITPERM AND NOT SVE2_BITPERM_FOUND)
15+
set(GNUCC_ARCH "${GNUCC_ARCH}+sve2-bitperm")
16+
elseif (BUILD_SVE2 AND NOT SVE2_FOUND)
17+
set(GNUCC_ARCH "${GNUCC_ARCH}+sve2")
18+
elseif (BUILD_SVE AND NOT SVE_FOUND)
19+
set(GNUCC_ARCH "${GNUCC_ARCH}+sve")
20+
endif ()
21+
else()
22+
set(ARCH_C_FLAGS "")
23+
set(ARCH_CXX_FLAGS "")
24+
endif()
25+
endif(ARCH_AARCH64)
26+
27+
CHECK_INCLUDE_FILE_CXX(arm_neon.h HAVE_C_ARM_NEON_H)
28+
if (BUILD_SVE OR BUILD_SVE2 OR BUILD_SVE2_BITPERM OR FAT_RUNTIME)
29+
if (CMAKE_COMPILER_IS_CLANG)
30+
set(CMAKE_REQUIRED_FLAGS "-${ARCH_FLAG}=armv8-a+sve")
31+
else()
32+
set(CMAKE_REQUIRED_FLAGS ${ARCH_CXX_FLAGS})
33+
endif()
34+
CHECK_INCLUDE_FILE_CXX(arm_sve.h HAVE_C_ARM_SVE_H)
35+
if (NOT HAVE_C_ARM_SVE_H)
36+
message(FATAL_ERROR "arm_sve.h is required to build for SVE.")
37+
endif()
38+
endif()
39+
40+
if (HAVE_C_EC_H)
41+
set (INTRIN_INC_H "altivec.h")
42+
else()
43+
message (FATAL_ERROR "No intrinsics header found for VSX")
44+
endif ()
45+
46+
if (ARCH_ARM32 OR ARCH_AARCH64)
47+
CHECK_C_SOURCE_COMPILES("#include <${INTRIN_INC_H}>
48+
int main() {
49+
int32x4_t a = vdupq_n_s32(1);
50+
(void)a;
51+
}" HAVE_NEON)
52+
endif ()
53+
54+
set(PREV_FLAGS "${CMAKE_C_FLAGS}")
55+
if (BUILD_SVE2_BITPERM)
56+
set(CMAKE_C_FLAGS "-march=${GNUCC_ARCH} ${CMAKE_C_FLAGS}")
57+
CHECK_C_SOURCE_COMPILES("#include <arm_sve.h>
58+
int main() {
59+
svuint8_t a = svbext(svdup_u8(1), svdup_u8(2));
60+
(void)a;
61+
}" HAVE_SVE2_BITPERM)
62+
if (HAVE_SVE2_BITPERM AND NOT FAT_RUNTIME)
63+
add_definitions(-DHAVE_SVE2_BITPERM)
64+
endif ()
65+
endif()
66+
if (BUILD_SVE2)
67+
set(CMAKE_C_FLAGS "-march=${GNUCC_ARCH} ${CMAKE_C_FLAGS}")
68+
CHECK_C_SOURCE_COMPILES("#include <arm_sve.h>
69+
int main() {
70+
svuint8_t a = svbsl(svdup_u8(1), svdup_u8(2), svdup_u8(3));
71+
(void)a;
72+
}" HAVE_SVE2)
73+
endif()
74+
if ((HAVE_SVE2 OR HAVE_SVE2_BITPERM) AND NOT FAT_RUNTIME)
75+
add_definitions(-DHAVE_SVE2)
76+
endif ()
77+
if (BUILD_SVE)
78+
set(CMAKE_C_FLAGS "-march=${GNUCC_ARCH} ${CMAKE_C_FLAGS}")
79+
CHECK_C_SOURCE_COMPILES("#include <arm_sve.h>
80+
int main() {
81+
svuint8_t a = svdup_u8(1);
82+
(void)a;
83+
}" HAVE_SVE)
84+
endif ()
85+
if ((HAVE_SVE OR HAVE_SVE2 OR HAVE_SVE2_BITPERM) AND NOT FAT_RUNTIME)
86+
add_definitions(-DHAVE_SVE)
87+
endif ()
88+
set(CMAKE_C_FLAGS "${PREV_FLAGS}")
89+
endif()
90+
91+
if (FAT_RUNTIME)
92+
if ((ARCH_IA32 OR ARCH_X86_64) AND NOT HAVE_SSE42)
93+
message(FATAL_ERROR "SSE4.2 support required to build fat runtime")
94+
endif ()
95+
if ((ARCH_IA32 OR ARCH_X86_64) AND BUILD_AVX2 AND NOT HAVE_AVX2)
96+
message(FATAL_ERROR "AVX2 support required to build fat runtime")
97+
endif ()
98+
if ((ARCH_IA32 OR ARCH_X86_64) AND BUILD_AVX512 AND NOT HAVE_AVX512)
99+
message(FATAL_ERROR "AVX512 support requested but not supported")
100+
endif ()
101+
if ((ARCH_IA32 OR ARCH_X86_64) AND BUILD_AVX512VBMI AND NOT HAVE_AVX512VBMI)
102+
message(FATAL_ERROR "AVX512VBMI support requested but not supported")
103+
endif ()
104+
else (NOT FAT_RUNTIME)
105+
if (ARCH_AARCH64 AND NOT BUILD_SVE)
106+
message(STATUS "Building without SVE support")
107+
endif ()
108+
if (ARCH_AARCH64 AND NOT BUILD_SVE2)
109+
message(STATUS "Building without SVE2 support")
110+
endif ()
111+
if ((ARCH_ARM32 OR ARCH_AARCH64) AND NOT HAVE_NEON)
112+
message(FATAL_ERROR "Neon/ASIMD support required for Arm support")
113+
endif ()
114+
endif ()
115+
116+
string(FIND "${GNUCC_ARCH}" "sve" POS_SVE)
117+
string(FIND "${GNUCC_ARCH}" "sve2" POS_SVE2)
118+
string(FIND "${GNUCC_ARCH}" "sve2-bitperm" POS_SVE2_BITPERM)
119+
if(NOT POS_SVE2_BITPERM EQUAL 0)
120+
set(SVE2_BITPERM_FOUND 1)
121+
set(SVE2_FOUND 1)
122+
set(SVE_FOUND 1)
123+
elseif(NOT POS_SVE2 EQUAL 0)
124+
set(SVE2_FOUND 1)
125+
set(SVE_FOUND 1)
126+
elseif (NOT POS_SVE EQUAL 0)
127+
set(SVE_FOUND 1)
128+
set(SVE2_BITPERM_FOUND 1)
129+
endif()
130+

0 commit comments

Comments
 (0)