Skip to content

Commit

Permalink
Build: Handle CMAKE_C_COMPILER_ID=AppleClang
Browse files Browse the repository at this point in the history
Because of 96a80b4, we are now
effectively using the NEW behavior for all CMake policies introduced in
all CMake versions up to and including CMake 3.28.  The NEW behavior for
CMP0025, introduced in CMake 3.0, sets CMAKE_C_COMPILER_ID to
"AppleClang" instead of "Clang" when using Apple's variant of Clang (in
Xcode), so we need to match all values of CMAKE_C_COMPILER_ID that
contain "Clang".

This fixes three issues:

- -O2 was not replaced with -O3 in CMAKE_C_FLAGS_RELWITHDEBINFO.  This
  was a minor issue, since -O3 is now the default in
  CMAKE_C_FLAGS_RELEASE, and we use CMAKE_BUILD_TYPE=Release in our
  official builds.

- The build system erroneously set the default value of FLOATTEST8 and
  FLOATTEST12 to no-fp-contract when compiling for PowerPC or Arm using
  Apple Clang 14+ (effectively reverting
  29d1904.)  Because Clang 14+ now
  enables -ffp-contract=on by default, this issue caused floating point
  test failures unless FLOATTEST8 and FLOATTEST12 were overridden.

- The build system set MD5_PPM_3x2_FLOAT_FP_CONTRACT as appropriate for
  GCC, not as appropriate for Clang (effectively reverting
  aa5efa3.)  This also caused floating
  point test failures.

Fixes #753
Closes #755
  • Loading branch information
dcommander committed Mar 18, 2024
1 parent 8b235de commit 0573a9c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions CMakeLists.txt
Expand Up @@ -436,7 +436,7 @@ if(MSVC)
add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
endif()

if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
# Use the maximum optimization level for release builds
foreach(var CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO)
if(${var} MATCHES "-O2")
Expand Down Expand Up @@ -507,7 +507,7 @@ if(UNIX)
endif()
endif()

if(NOT MSVC OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
if(NOT MSVC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
check_c_source_compiles("extern const int table[1]; const int __attribute__((visibility(\"hidden\"))) table[1] = { 0 }; int main(void) { return table[0]; }"
HIDDEN_WORKS)
if(HIDDEN_WORKS)
Expand Down Expand Up @@ -825,7 +825,7 @@ if(WITH_12BIT)
set(MD5_PPM_3x2_FLOAT_NO_FP_CONTRACT ${MD5_PPM_3x2_FLOAT_SSE})
set(MD5_JPEG_3x2_FLOAT_PROG_FP_CONTRACT
${MD5_JPEG_3x2_FLOAT_PROG_NO_FP_CONTRACT})
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(MD5_PPM_3x2_FLOAT_FP_CONTRACT 2da9de6ae869e88b8372de815d366b03)
else()
set(MD5_PPM_3x2_FLOAT_FP_CONTRACT ${MD5_PPM_3x2_FLOAT_SSE})
Expand Down Expand Up @@ -884,7 +884,7 @@ else()
set(MD5_PPM_3x2_FLOAT_NO_FP_CONTRACT f6bfab038438ed8f5522fbd33595dcdc)
set(MD5_JPEG_3x2_FLOAT_PROG_FP_CONTRACT
${MD5_JPEG_3x2_FLOAT_PROG_NO_FP_CONTRACT})
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(MD5_PPM_3x2_FLOAT_FP_CONTRACT ${MD5_PPM_3x2_FLOAT_NO_FP_CONTRACT})
else()
set(MD5_PPM_3x2_FLOAT_FP_CONTRACT 0e917a34193ef976b679a6b069b1be26)
Expand Down Expand Up @@ -999,7 +999,7 @@ if(CPU_TYPE STREQUAL "x86_64" OR CPU_TYPE STREQUAL "i386")
set(DEFAULT_FLOATTEST no-fp-contract)
endif()
elseif(CPU_TYPE STREQUAL "powerpc" OR CPU_TYPE STREQUAL "arm64")
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
if(CMAKE_C_COMPILER_VERSION VERSION_EQUAL 14.0.0 OR
CMAKE_C_COMPILER_VERSION VERSION_GREATER 14.0.0)
set(DEFAULT_FLOATTEST fp-contract)
Expand Down

0 comments on commit 0573a9c

Please sign in to comment.