Fix usage of CMAKE_REQUIRED_*
authorRoland Schulz <roland@utk.edu>
Fri, 19 Oct 2012 02:14:20 +0000 (22:14 -0400)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Fri, 26 Oct 2012 19:41:19 +0000 (21:41 +0200)
Always reset all variables.
Only require libm if it is avaiable (only on Unix)

Also prefer usage of _finite. ICC on Windows gives warnings
for isfinite (we don't inlude mathimf.h).

Fixes #998

Change-Id: Ib7c064aaf6d26d2ab96f5e88345091a2eb096998

cmake/FindFFTW.cmake
cmake/ThreadMPI.cmake
cmake/gmxTestIsfinite.cmake
cmake/gmxTestMPI_IN_PLACE.cmake
cmake/gmxTestdlopen.cmake
src/gmxlib/maths.c

index 5905c465643ee530f6589d6beef6baec94558113..ea98eaefc382df0803b38a766d21310ef5501d35 100644 (file)
@@ -80,7 +80,9 @@ if (FFTW_FOUND AND HAVE_LIBM AND NOT "${FFTW_LIBRARY_PREVIOUS}" STREQUAL "${FFTW
   #The user could specify trash in FFTW_LIBRARY, so test if we can link it
   include(CheckLibraryExists)
   #adding MATH_LIBRARIES here to allow static libs, this does not harm us as we are anyway using it
-  set(CMAKE_REQUIRED_LIBRARIES m)
+  if (HAVE_LIBM)
+    set(CMAKE_REQUIRED_LIBRARIES m)
+  endif()
   unset(FOUND_FFTW_PLAN_${FFTW_PKG} CACHE)
   check_library_exists("${FFTW_LIBRARIES}" "${FFTW_FUNCTION}" "" FOUND_FFTW_PLAN_${FFTW_PKG})
   if(NOT FOUND_FFTW_PLAN_${FFTW_PKG})
index 30e2767b77c1c5a592ff190eaad92643604b57aa..b528af0c249849c39d6f794d6e8635cca5f8569b 100644 (file)
@@ -142,6 +142,7 @@ int main(void) { cpu_set_t set;
     if (PTHREAD_SETAFFINITY)
         set(HAVE_PTHREAD_SETAFFINITY 1)
     endif (PTHREAD_SETAFFINITY)
+    set(CMAKE_REQUIRED_LIBRARIES)
 endif (THREAD_PTHREADS)
 
 
index cb026b7f5ddeca1b87f98aa3ed70dbc949a6a390..ff0e147be0f8843d081bef5dc86ff11c9f70015c 100644 (file)
@@ -18,7 +18,9 @@ MACRO(gmx_test_isfinite VARIABLE)
     MESSAGE(STATUS "Checking for isfinite")
 
     set(CMAKE_REQUIRED_INCLUDES "math.h")
-    set(CMAKE_REQUIRED_LIBRARIES "m")
+    if (HAVE_LIBM)
+        set(CMAKE_REQUIRED_LIBRARIES "m")
+    endif()
     check_c_source_compiles(
       "#include <math.h>
 int main(void) {
@@ -32,6 +34,8 @@ int main(void) {
         MESSAGE(STATUS "Checking for isfinite - no")
     endif(isfinite_compile_ok)
     set(isfinite_compile_ok "${isfinite_compile_ok}" CACHE INTERNAL "Result of isfinite check")
+    set(CMAKE_REQUIRED_INCLUDES)
+    set(CMAKE_REQUIRED_LIBRARIES)
   endif(NOT DEFINED isfinite_compile_ok)
   if(isfinite_compile_ok)
     set(${VARIABLE} ${isfinite_compile_ok}
@@ -44,7 +48,9 @@ MACRO(gmx_test__isfinite VARIABLE)
     MESSAGE(STATUS "Checking for _isfinite")
 
     set(CMAKE_REQUIRED_INCLUDES "math.h")
-    set(CMAKE_REQUIRED_LIBRARIES "m")
+    if (HAVE_LIBM)
+        set(CMAKE_REQUIRED_LIBRARIES "m")
+    endif()
     check_c_source_compiles(
       "#include <math.h>
 int main(void) {
@@ -58,6 +64,8 @@ int main(void) {
         MESSAGE(STATUS "Checking for _isfinite - no")
     endif(_isfinite_compile_ok)
     set(_isfinite_compile_ok "${_isfinite_compile_ok}" CACHE INTERNAL "Result of _isfinite check")
+    set(CMAKE_REQUIRED_INCLUDES)
+    set(CMAKE_REQUIRED_LIBRARIES)
   endif(NOT DEFINED _isfinite_compile_ok)
   if(_isfinite_compile_ok)
     set(${VARIABLE} ${_isfinite_compile_ok}
@@ -84,6 +92,7 @@ int main(void) {
         MESSAGE(STATUS "Checking for _finite - no")
     endif(_finite_compile_ok)
     set(_finite_compile_ok "${_finite_compile_ok}" CACHE INTERNAL "Result of _finite check")
+    set(CMAKE_REQUIRED_INCLUDES)
   endif(NOT DEFINED _finite_compile_ok)
   if(_finite_compile_ok)
     set(${VARIABLE} ${_finite_compile_ok}
index 7bce601bcb63e671981ed70803fbf917cf675fb3..07fb140926ecba494c12a32c17fcaf9dd0b689e6 100644 (file)
@@ -26,6 +26,9 @@ int main(void) {
         MESSAGE(STATUS "Checking for MPI_IN_PLACE - no")
     endif(MPI_IN_PLACE_COMPILE_OK)
     set(MPI_IN_PLACE_COMPILE_OK "${MPI_IN_PLACE_COMPILE_OK}" CACHE INTERNAL "Result of mpi_in_place check")
+    set(CMAKE_REQUIRED_DEFINITIONS)
+    set(CMAKE_REQUIRED_INCLUDES)
+    set(CMAKE_REQUIRED_LIBRARIES)
   endif()
   if (MPI_IN_PLACE_COMPILE_OK)
     set(${VARIABLE} ${MPI_IN_PLACE_COMPILE_OK} 
index dcf571e569a23a297afc7251312fb7cdb825788f..b3885b827d133ab21682b69770cd5530dbdfa82c 100644 (file)
@@ -24,5 +24,7 @@ int main(void) {
       MESSAGE(STATUS "Checking for dlopen - not found")
       set(${VARIABLE} 0 CACHE INTERNAL "Result of test for dlopen" FORCE)
     ENDIF()
+    set(CMAKE_REQUIRED_INCLUDES)
+    set(CMAKE_REQUIRED_LIBRARIES)
   ENDIF()
 ENDMACRO()
\ No newline at end of file
index 13388c5d937ba1a2c2416d6223be368e8207b682..593cd4901ab9728074edbd0b56eaf1ea0fab2bd3 100644 (file)
@@ -649,12 +649,12 @@ gmx_bool gmx_isfinite(real x)
     /* If no suitable function was found, assume the value is
      * finite. */
 
-#ifdef HAVE_ISFINITE
+#ifdef HAVE__FINITE
+    returnval = _finite(x);
+#elif defined HAVE_ISFINITE
     returnval = isfinite(x);
 #elif defined HAVE__ISFINITE
     returnval = _isfinite(x);
-#elif defined HAVE__FINITE
-    returnval = _finite(x);
 #endif
     return returnval;
 }