Check that floats are in the IEEE 754 format when building with CMake

SCons version is coming a bit later.
This commit is contained in:
Jyrki Vesterinen 2016-12-22 20:40:15 +02:00
parent 5dbff70e15
commit 7968f7ba5e
2 changed files with 26 additions and 0 deletions

View file

@ -55,6 +55,15 @@ option(ENABLE_OMP "Enables OpenMP, and has additional dependencies" OFF)
option(ENABLE_LIBPNG "Enable support for writing png files (screenshots, images)" ON)
option(ENABLE_HISTORY "Enable using GNU history for history in lua console" ON)
if(NOT CMAKE_CROSSCOMPILING)
try_run(IEEE754_TEST_RETURN_CODE IEEE754_TEST_COMPILED ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/src/compile_time_tests/ieee_754.cpp)
if(NOT IEEE754_TEST_RETURN_CODE EQUAL 0)
message(FATAL_ERROR "Your platform does not represent floating point numbers in the IEEE 754 format.")
endif()
else()
message(WARNING "You are cross-compiling. Skipping IEEE 754 test.")
endif()
if(DEFINED ENV{TRAVIS})
find_package(SDL2 2.0.2 REQUIRED)
else()

View file

@ -0,0 +1,17 @@
#include <cstdint>
// This test verifies that floating point numbers are represented in the IEEE 754 format.
// Wesnoth requires that.
int main()
{
union
{
double floating_point_number;
uint64_t integer;
} number;
number.floating_point_number = 1.2;
// Return code zero means success.
// Thus, check that the bit representation is *not* what IEEE 754 specifies.
return number.integer != 0x3FF3333333333333ull;
}