Skip to content

Commit 01d1ae5

Browse files
committed
Fix -Wdeprecated-ofast warning in Clang
1 parent 74ee64a commit 01d1ae5

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

cmake/FastMathOptimizations.cmake

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,37 @@
44
# visible artifacts, but may be undesirable in some uses. In this case, disable the ENABLE_FAST_MATH option
55
# and specify the safe set of flags via the CMAKE_C_FLAGS and CMAKE_CXX_FLAGS variables.
66

7-
if(ENABLE_FAST_MATH)
7+
if (ENABLE_FAST_MATH)
88
include(CheckCCompilerFlag)
9-
if(MSVC)
9+
if (CMAKE_C_COMPILER_ID STREQUAL "MSVC")
1010
check_c_compiler_flag("/fp:fast" FAST_MATH_OPTIMIZATION_SUPPORTED)
11-
if(FAST_MATH_OPTIMIZATION_SUPPORTED)
11+
if (FAST_MATH_OPTIMIZATION_SUPPORTED)
1212
add_compile_options($<$<CONFIG:Release,RelWithDebInfo>:/fp:fast>)
13-
endif()
14-
else()
13+
endif ()
14+
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
15+
check_c_compiler_flag("-O3" ALL_OPTIMIZATIONS_FLAG_SUPPORTED)
16+
if (ALL_OPTIMIZATIONS_FLAG_SUPPORTED)
17+
add_compile_options($<$<CONFIG:Release,RelWithDebInfo>:-O3>)
18+
endif ()
19+
20+
# Clang has deprecated -Ofast, use -ffast-math instead.
21+
check_c_compiler_flag("-ffast-math" FAST_MATH_OPTIMIZATION_SUPPORTED)
22+
if (FAST_MATH_OPTIMIZATION_SUPPORTED)
23+
add_compile_options($<$<CONFIG:Release,RelWithDebInfo>:-ffast-math>)
24+
endif ()
25+
elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU")
1526
check_c_compiler_flag("-Ofast" FAST_MATH_OPTIMIZATION_SUPPORTED)
16-
if(FAST_MATH_OPTIMIZATION_SUPPORTED)
27+
if (FAST_MATH_OPTIMIZATION_SUPPORTED)
1728
add_compile_options($<$<CONFIG:Release,RelWithDebInfo>:-Ofast>)
18-
else()
29+
else ()
1930
check_c_compiler_flag("-O3" ALL_OPTIMIZATIONS_FLAG_SUPPORTED)
20-
if(ALL_OPTIMIZATIONS_FLAG_SUPPORTED)
31+
if (ALL_OPTIMIZATIONS_FLAG_SUPPORTED)
2132
add_compile_options($<$<CONFIG:Release,RelWithDebInfo>:-O3>)
22-
endif()
23-
endif()
24-
endif()
25-
endif()
33+
endif ()
34+
endif ()
35+
else ()
36+
message(AUTHOR_WARNING
37+
"ENABLE_FAST_MATH was requested, but compiler is not supported: ${CMAKE_C_COMPILER_ID}. "
38+
"Please use CMAKE_C_FLAGS to pass the correct optimization flags manually.")
39+
endif ()
40+
endif ()

0 commit comments

Comments
 (0)