@@ -30,6 +30,7 @@ option(TPCH_USE_PREBUILT_LANCE_FFI "Use pre-compiled Lance FFI library when avai
3030option (TPCH_ENABLE_PERF_COUNTERS "Enable performance counters instrumentation" OFF )
3131option (TPCH_ENABLE_MOLD "Enable mold linker if available (incompatible with GTest in this project)" ON )
3232option (TPCDS_ENABLE "Enable TPC-DS data generation (tpcds_benchmark executable)" OFF )
33+ option (TPCH_ENABLE_NATIVE_OPTIMIZATIONS "Enable host-specific CPU optimizations such as -march=native" ON )
3334
3435# Compiler configuration
3536include (cmake/CompilerWarnings.cmake )
@@ -38,30 +39,38 @@ include(cmake/CompilerWarnings.cmake)
3839if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" )
3940 # Enable aggressive optimizations with SIMD support
4041 if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" )
41- add_compile_options (-O3 -march=native )
42+ add_compile_options (-O3 )
43+
44+ if (TPCH_ENABLE_NATIVE_OPTIMIZATIONS)
45+ add_compile_options (-march=native )
46+ endif ()
4247
4348 # Enable auto-vectorization and report optimizations
4449 add_compile_options (
4550 -ftree-vectorize # Enable loop vectorization
4651 -fopt-info-vec-optimized # Report successful vectorizations
4752 )
4853
49- # Check for AVX2 support (preferred)
50- include (CheckCXXCompilerFlag )
51- check_cxx_compiler_flag ("-mavx2" COMPILER_SUPPORTS_AVX2 )
54+ if (TPCH_ENABLE_NATIVE_OPTIMIZATIONS)
55+ # Check for AVX2 support (preferred)
56+ include (CheckCXXCompilerFlag )
57+ check_cxx_compiler_flag ("-mavx2" COMPILER_SUPPORTS_AVX2 )
5258
53- if (COMPILER_SUPPORTS_AVX2)
54- message (STATUS "Enabling AVX2 SIMD optimizations" )
55- add_compile_options (-mavx2 -mfma )
56- else ()
57- # Fallback to SSE4.2 (required for SIMD string utils)
58- check_cxx_compiler_flag ("-msse4.2" COMPILER_SUPPORTS_SSE42 )
59- if (COMPILER_SUPPORTS_SSE42)
60- message (STATUS "Enabling SSE4.2 SIMD optimizations" )
61- add_compile_options (-msse4.2 )
59+ if (COMPILER_SUPPORTS_AVX2)
60+ message (STATUS "Enabling AVX2 SIMD optimizations" )
61+ add_compile_options (-mavx2 -mfma )
6262 else ()
63- message (WARNING "No SIMD support detected - performance will be degraded" )
63+ # Fallback to SSE4.2 (required for SIMD string utils)
64+ check_cxx_compiler_flag ("-msse4.2" COMPILER_SUPPORTS_SSE42 )
65+ if (COMPILER_SUPPORTS_SSE42)
66+ message (STATUS "Enabling SSE4.2 SIMD optimizations" )
67+ add_compile_options (-msse4.2 )
68+ else ()
69+ message (WARNING "No SIMD support detected - performance will be degraded" )
70+ endif ()
6471 endif ()
72+ else ()
73+ message (STATUS "Host-specific CPU optimizations disabled (TPCH_ENABLE_NATIVE_OPTIMIZATIONS=OFF)" )
6574 endif ()
6675 endif ()
6776elseif (CMAKE_BUILD_TYPE STREQUAL "Debug" )
0 commit comments