From 7968f7ba5e1217eeff7cbe019aa07383a20133ef Mon Sep 17 00:00:00 2001 From: Jyrki Vesterinen Date: Thu, 22 Dec 2016 20:40:15 +0200 Subject: [PATCH] Check that floats are in the IEEE 754 format when building with CMake SCons version is coming a bit later. --- CMakeLists.txt | 9 +++++++++ src/compile_time_tests/ieee_754.cpp | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/compile_time_tests/ieee_754.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f9cdeb954134..2900c67c1885 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/src/compile_time_tests/ieee_754.cpp b/src/compile_time_tests/ieee_754.cpp new file mode 100644 index 000000000000..29178c2c6aec --- /dev/null +++ b/src/compile_time_tests/ieee_754.cpp @@ -0,0 +1,17 @@ +#include + +// 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; +}