intel / hyperscan

High-performance regular expression matching library
https://www.hyperscan.io
Other
4.71k stars 705 forks source link

CMake tests failing when compiling on OpenWrt with external toolchain #431

Open graysky2 opened 2 months ago

graysky2 commented 2 months ago

Using the OpenWrt external toolchain causes build errors. I am wondering if I can define the missing values by passing options to CMake?

Can you suggest what those options might be?

I am currently using:

CMAKE_OPTIONS += \
        -DCMAKE_INSTALL_PREFIX=/usr \
        -DCMAKE_INSTALL_LIBDIR=lib \
        -DBUILD_SHARED_LIBS=ON \
        -Wno-dev
-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/xtools-openwrt/toolchain-x86_64_gcc-13.2.0_musl/bin/x86_64-openwrt-linux-musl-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /opt/xtools-openwrt/toolchain-x86_64_gcc-13.2.0_musl/bin/x86_64-openwrt-linux-musl-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test ARCH_64_BIT
-- Performing Test ARCH_64_BIT - Success
-- Performing Test ARCH_32_BIT
-- Performing Test ARCH_32_BIT - Failed
-- Build type RELEASE
-- using release build
-- Boost version: 1.84.0
-- Found PythonInterp: /scratch/openwrt/staging_dir/host/bin/python (found version "3.11.8")
-- Build date: 2024-04-18
-- Building shared libraries
-- gcc version 13.2.0
CMake Error at CMakeLists.txt:198 (string):
  string begin index: -1 is out of range 0 - 0

CMake Error at CMakeLists.txt:209 (message):
  Something went wrong determining gcc tune: -mtune= not valid

-- g++ version 13.2.0
-- Looking for include file unistd.h
-- Looking for include file unistd.h - found
-- Looking for include file intrin.h
-- Looking for include file intrin.h - not found
-- Looking for C++ include intrin.h
-- Looking for C++ include intrin.h - not found
-- Looking for include file x86intrin.h
-- Looking for include file x86intrin.h - found
-- Looking for C++ include x86intrin.h
-- Looking for C++ include x86intrin.h - found
-- Looking for posix_memalign
-- Looking for posix_memalign - found
-- Looking for _aligned_malloc
-- Looking for _aligned_malloc - not found
-- Performing Test HAS_C_HIDDEN
-- Performing Test HAS_C_HIDDEN - Success
-- Performing Test HAS_CXX_HIDDEN
-- Performing Test HAS_CXX_HIDDEN - Success
-- Looking for _LIBCPP_VERSION
-- Looking for _LIBCPP_VERSION - not found
-- generator is Ninja
-- Performing Test HAS_C_ATTR_IFUNC
-- Performing Test HAS_C_ATTR_IFUNC - Failed
-- Compiler does not support ifunc attribute, cannot build fat runtime
-- Performing Test HAVE_SSSE3
-- Performing Test HAVE_SSSE3 - Success
-- Performing Test HAVE_AVX2
-- Performing Test HAVE_AVX2 - Failed
-- Performing Test HAVE_AVX512
-- Performing Test HAVE_AVX512 - Failed
-- Performing Test HAVE_AVX512VBMI
-- Performing Test HAVE_AVX512VBMI - Failed
-- Building without AVX2 support
-- Building without AVX512 support
-- Building without AVX512VBMI support
-- Performing Test HAVE_CC_BUILTIN_ASSUME_ALIGNED
-- Performing Test HAVE_CC_BUILTIN_ASSUME_ALIGNED - Success
-- Performing Test HAVE_CXX_BUILTIN_ASSUME_ALIGNED
-- Performing Test HAVE_CXX_BUILTIN_ASSUME_ALIGNED - Success
-- Performing Test HAVE__BUILTIN_CONSTANT_P
-- Performing Test HAVE__BUILTIN_CONSTANT_P - Success
-- Performing Test C_FLAG_Wvla
-- Performing Test C_FLAG_Wvla - Success
-- Performing Test C_FLAG_Wpointer_arith
-- Performing Test C_FLAG_Wpointer_arith - Success
-- Performing Test C_FLAG_Wstrict_prototypes
-- Performing Test C_FLAG_Wstrict_prototypes - Success
-- Performing Test C_FLAG_Wmissing_prototypes
-- Performing Test C_FLAG_Wmissing_prototypes - Success
-- Performing Test CXX_FLAG_Wvla
-- Performing Test CXX_FLAG_Wvla - Success
-- Performing Test CXX_FLAG_Wpointer_arith
-- Performing Test CXX_FLAG_Wpointer_arith - Success
-- Performing Test CC_SELF_ASSIGN
-- Performing Test CC_SELF_ASSIGN - Failed
-- Performing Test CXX_SELF_ASSIGN
-- Performing Test CXX_SELF_ASSIGN - Failed
-- Performing Test CC_PAREN_EQUALITY
-- Performing Test CC_PAREN_EQUALITY - Failed
-- Performing Test CXX_UNUSED_CONST_VAR
-- Performing Test CXX_UNUSED_CONST_VAR - Success
-- Performing Test CXX_UNUSED_BUT_SET_VAR
-- Performing Test CXX_UNUSED_BUT_SET_VAR - Success
-- Performing Test CXX_BITWISE_INSTEAD_OF_LOGICAL
-- Performing Test CXX_BITWISE_INSTEAD_OF_LOGICAL - Failed
-- Performing Test CXX_IGNORED_ATTR
-- Performing Test CXX_IGNORED_ATTR - Success
-- Performing Test CXX_REDUNDANT_MOVE
-- Performing Test CXX_REDUNDANT_MOVE - Success
-- Performing Test CXX_WEAK_VTABLES
-- Performing Test CXX_WEAK_VTABLES - Failed
-- Performing Test CXX_MISSING_DECLARATIONS
-- Performing Test CXX_MISSING_DECLARATIONS - Success
-- Performing Test CXX_UNUSED_LOCAL_TYPEDEFS
-- Performing Test CXX_UNUSED_LOCAL_TYPEDEFS - Success
-- Performing Test CXX_WUNUSED_VARIABLE
-- Performing Test CXX_WUNUSED_VARIABLE - Success
-- Performing Test CC_STRINGOP_OVERFLOW
-- Performing Test CC_STRINGOP_OVERFLOW - Success
-- Performing Test CXX_STRINGOP_OVERFLOW
-- Performing Test CXX_STRINGOP_OVERFLOW - Success
-- Building for current host CPU: 
-- Looking for mmap
-- Looking for mmap - found
-- Doxygen not found, unable to generate API reference
-- Sphinx not found, unable to generate developer reference
-- Found PkgConfig: /scratch/openwrt/staging_dir/host/bin/pkg-config (found version "2.1.1")
-- Checking for module 'libpcre>=8.41'
--   Found libpcre, version 8.45
-- PCRE version 8.41 or above
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Checking for module 'sqlite3'
--   Package 'sqlite3', required by 'virtual:world', not found
-- looking for sqlite3 in source tree
--   no sqlite3 in source tree
-- sqlite3 not found, not building hsbench
-- Performing Test BACKTRACE_LIBC
-- Performing Test BACKTRACE_LIBC - Failed
-- Performing Test BACKTRACE_LIBEXECINFO
-- Performing Test BACKTRACE_LIBEXECINFO - Failed
-- Performing Test BACKTRACE_LIBEXECINFO_LOCAL
-- Performing Test BACKTRACE_LIBEXECINFO_LOCAL - Failed
-- Configuring incomplete, errors occurred!
make[2]: *** [Makefile:87: /scratch/openwrt/build_dir/target-x86_64-openwrt-linux-musl_musl/hyperscan-5.4.2/.configured_68b329da9893e34099c7d8ad5cb9c940] Error 1
make[2]: Leaving directory '/scratch/openwrt/feeds/packages/libs/hyperscan'
time: package/feeds/packages/hyperscan/compile#3.24#1.72#5.14
    ERROR: package/feeds/packages/hyperscan failed to build.
make[1]: *** [package/Makefile:129: package/feeds/packages/hyperscan/compile] Error 1
make[1]: Leaving directory '/scratch/openwrt'
make: *** [/scratch/openwrt/include/toplevel.mk:233: package/hyperscan/compile] Error 2
graysky2 commented 2 months ago

I can hack this to work by modifying CMakeLists.txt like this but I feel like that's a dirty hack:

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -183,34 +183,7 @@ else()
     endforeach ()

     if (CMAKE_COMPILER_IS_GNUCC)
-        message(STATUS "gcc version ${CMAKE_C_COMPILER_VERSION}")
-        # If gcc doesn't recognise the host cpu, then mtune=native becomes
-        # generic, which isn't very good in some cases. march=native looks at
-        # cpuid info and then chooses the best microarch it can (and replaces
-        # the flag), so use that for tune.
-
-        # arg1 might exist if using ccache
-        string (STRIP "${CMAKE_C_COMPILER_ARG1}" CC_ARG1)
-        set (EXEC_ARGS ${CC_ARG1} -c -Q --help=target -march=native -mtune=native)
-        execute_process(COMMAND ${CMAKE_C_COMPILER} ${EXEC_ARGS}
-            OUTPUT_VARIABLE _GCC_OUTPUT)
-        string(FIND "${_GCC_OUTPUT}" "march" POS)
-        string(SUBSTRING "${_GCC_OUTPUT}" ${POS} -1 _GCC_OUTPUT)
-        string(REGEX REPLACE "march=[ \t]*([^ \n]*)[ \n].*" "\\1"
-            GNUCC_ARCH "${_GCC_OUTPUT}")
-
-        # test the parsed flag
-        set (EXEC_ARGS ${CC_ARG1} -E - -mtune=${GNUCC_ARCH})
-        execute_process(COMMAND ${CMAKE_C_COMPILER} ${EXEC_ARGS}
-            OUTPUT_QUIET ERROR_QUIET
-            INPUT_FILE /dev/null
-            RESULT_VARIABLE GNUCC_TUNE_TEST)
-        if (NOT GNUCC_TUNE_TEST EQUAL 0)
-            message(SEND_ERROR "Something went wrong determining gcc tune: -mtune=${GNUCC_ARCH} not valid")
-        endif()
-        set(TUNE_FLAG ${GNUCC_ARCH})
-    else ()
-        set(TUNE_FLAG native)
+        set(TUNE_FLAG x86-64-v2)
     endif()

     # compiler version checks TODO: test more compilers