Skip to content

Commit

Permalink
cmake: check for valid isinf/isinff/isnan/isnanf macros
Browse files Browse the repository at this point in the history
  • Loading branch information
madebr committed Jun 24, 2024
1 parent ea11c9e commit d52ea20
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
37 changes: 37 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,43 @@ if(SDL_LIBC)
endforeach()
cmake_pop_check_state()

cmake_push_check_state()
if(MSVC)
string(APPEND CMAKE_REQUIRED_FLAGS " -we4244 -WX") # 'conversion' conversion from 'type1' to 'type2', possible loss of data
else()
string(APPEND CMAKE_REQUIRED_FLAGS " -Wfloat-conversion -Werror")
endif()
foreach(math_fn isinf isnan)
string(TOUPPER "${math_fn}" MATH_FN)
check_c_source_compiles("
#include <math.h>
int main() {
double d = 3.14159;
return ${math_fn}(d);
}
" LIBC_HAS_${MATH_FN})
set(HAVE_${MATH_FN} ${LIBC_HAS_${MATH_FN}})

check_c_source_compiles("
#include <math.h>
int main() {
float f = 3.14159f;
return ${math_fn}(f);
}
" LIBC_${MATH_FN}_HANDLES_FLOAT)
set(HAVE_${MATH_FN}_FLOAT_MACRO ${LIBC_${MATH_FN}_HANDLES_FLOAT})

check_c_source_compiles("
#include <math.h>
int main() {
float f = 3.14159f;
return ${math_fn}f(f);
}
" LIBC_HAS_${MATH_FN}F)
set(HAVE_${MATH_FN}F "${LIBC_HAS_${MATH_FN}}")
endforeach()
cmake_pop_check_state()

if(NOT WINDOWS)
check_symbol_exists(getpagesize "unistd.h" HAVE_GETPAGESIZE)
check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
Expand Down
6 changes: 6 additions & 0 deletions cmake/PreseedMSVCCache.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ function(SDL_Preseed_CMakeCache)
set(LIBC_HAS_ICONV_H "" CACHE INTERNAL "Have include iconv.h")
set(LIBC_HAS_INDEX "" CACHE INTERNAL "Have symbol index")
set(LIBC_HAS_INTTYPES_H "1" CACHE INTERNAL "Have include inttypes.h")
set(LIBC_HAS_ISINF "1" CACHE INTERNAL "Have include isinf(double)")
set(LIBC_ISINF_HANDLES_FLOAT "1" CACHE INTERNAL "Have include isinf(float)")
set(LIBC_HAS_ISINFF "" CACHE INTERNAL "Have include isinff(float)")
set(LIBC_HAS_ISNAN "1" CACHE INTERNAL "Have include isnan(double)")
set(LIBC_ISNAN_HANDLES_FLOAT "1" CACHE INTERNAL "Have include isnan(float)")
set(LIBC_HAS_ISNANF "" CACHE INTERNAL "Have include isnanf(float)")
set(LIBC_HAS_ITOA "1" CACHE INTERNAL "Have symbol itoa")
set(LIBC_HAS_LIMITS_H "1" CACHE INTERNAL "Have include limits.h")
set(LIBC_HAS_LOG "1" CACHE INTERNAL "Have symbol log")
Expand Down
2 changes: 2 additions & 0 deletions include/build_config/SDL_build_config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@
#cmakedefine HAVE_FMODF 1
#cmakedefine HAVE_ISINF 1
#cmakedefine HAVE_ISINFF 1
#cmakedefine HAVE_ISINF_FLOAT_MACRO 1
#cmakedefine HAVE_ISNAN 1
#cmakedefine HAVE_ISNANF 1
#cmakedefine HAVE_ISNAN_FLOAT_MACRO 1
#cmakedefine HAVE_LOG 1
#cmakedefine HAVE_LOGF 1
#cmakedefine HAVE_LOG10 1
Expand Down

0 comments on commit d52ea20

Please sign in to comment.