Skip to content

Commit 0cb73a8

Browse files
JanWielemakerclaude
andcommitted
FIXED: crmath build failed on old compilers not knowing -march=x86-64-v3
Upstream core-math adds -march=x86-64-v3 unconditionally on x86_64. This microarchitecture level is only known to gcc >= 11 and clang >= 12; older compilers error out. Drop the flag in our crmath.cmake layer when check_c_compiler_flag() reports it is unsupported. It is only a tuning hint, so dropping it loses AVX2 tuning but not correctness. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 4a04fdc commit 0cb73a8

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

cmake/crmath.cmake

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,30 @@
22
# FetchContent_MakeAvailable() in Deps.cmake. Here we adjust the
33
# target to fit the libswipl build without modifying the sources.
44

5+
include(CheckCCompilerFlag)
6+
57
if(TARGET crmath)
68
if(LIBSWIPL_TYPE STREQUAL "SHARED")
79
set_property(TARGET crmath PROPERTY POSITION_INDEPENDENT_CODE 1)
810
endif()
911

10-
# Upstream hard-codes -O2, which would override our
11-
# CMAKE_C_FLAGS_<CONFIG>. Remove it so the project optimization
12-
# flags apply, while keeping upstream's strict FP options
13-
# (-fno-fast-math -ffp-contract=off).
12+
# Adjust the compile options set by the upstream CMakeLists.txt:
13+
# - Remove -O2, which would override our CMAKE_C_FLAGS_<CONFIG>, so
14+
# the project optimization flags apply. Upstream's strict FP
15+
# options (-fno-fast-math -ffp-contract=off) are kept.
16+
# - Remove -march=x86-64-v3 when the compiler does not understand
17+
# it. This microarchitecture level is only known to gcc >= 11 and
18+
# clang >= 12; older compilers error out on it. It is only a
19+
# performance hint, so dropping it merely loses AVX2 tuning.
1420
get_target_property(_crmath_options crmath COMPILE_OPTIONS)
1521
if(_crmath_options)
1622
list(REMOVE_ITEM _crmath_options -O2)
23+
if("-march=x86-64-v3" IN_LIST _crmath_options)
24+
check_c_compiler_flag(-march=x86-64-v3 HAVE_MARCH_X86_64_V3)
25+
if(NOT HAVE_MARCH_X86_64_V3)
26+
list(REMOVE_ITEM _crmath_options -march=x86-64-v3)
27+
endif()
28+
endif()
1729
set_target_properties(crmath PROPERTIES
1830
COMPILE_OPTIONS "${_crmath_options}")
1931
endif()

0 commit comments

Comments
 (0)