Skip to content

Commit

Permalink
Check that floats are in the IEEE 754 format when building with CMake
Browse files Browse the repository at this point in the history
SCons version is coming a bit later.
  • Loading branch information
jyrkive committed Dec 22, 2016
1 parent 5dbff70 commit 7968f7b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Expand Up @@ -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()
Expand Down
17 changes: 17 additions & 0 deletions src/compile_time_tests/ieee_754.cpp
@@ -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;
}

0 comments on commit 7968f7b

Please sign in to comment.