From 09f595a269b43896b4de400447a2e253fc87d4d3 Mon Sep 17 00:00:00 2001 From: Susi Lehtola Date: Sat, 24 Oct 2020 06:16:50 +0000 Subject: Make sure compiler does not optimize away calls to math functions --- cmake/FindStandardMathLibrary.cmake | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'cmake') diff --git a/cmake/FindStandardMathLibrary.cmake b/cmake/FindStandardMathLibrary.cmake index fc4728a82..b174cbb4f 100644 --- a/cmake/FindStandardMathLibrary.cmake +++ b/cmake/FindStandardMathLibrary.cmake @@ -10,6 +10,7 @@ # pass the "-lm" linker flag. # # Copyright (c) 2010 Benoit Jacob +# 2020 Susi Lehtola # Redistribution and use is allowed according to the terms of the 2-clause BSD license. @@ -19,9 +20,15 @@ include(CheckCXXSourceCompiles) # notice the std:: is required on some platforms such as QNX # notice the (void) is required if -Wall (-Wunused-value) is added to CMAKE_CXX_FLAG +# We read in the arguments from standard input to avoid the compiler optimizing away the calls set(find_standard_math_library_test_program -"#include -int main() { (void)std::sin(0.0); (void)std::log(0.0f); }") +" +#include +int main(int argc, char **argv) { + (void)std::sin(argc)); + (void)std::log(argc)); + return 0; +}") # first try compiling/linking the test program without any linker flags -- cgit v1.2.3