Check zlib can actually be linked
authorRoland Schulz <roland@utk.edu>
Thu, 27 Feb 2014 05:53:18 +0000 (00:53 -0500)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Wed, 5 Mar 2014 06:18:09 +0000 (07:18 +0100)
Only use zlib compression in tng if zlib can really be linked.
This is equivalent to ee26e1264 for libxml2.

It is slightly simpler than the approach in gmxTestLibXml2
and CheckLibraryExists could be used there too.
This does not detect potential linking errors with shared
libraries similar to those solved in #740 for FFTW.

Fixes #1435

Change-Id: I5009e50b6caf810a12e71ecd83bde2edb21a2b32

CMakeLists.txt
cmake/gmxTestZLib.cmake [new file with mode: 0644]

index a450d1a7be9159948916514d8346333bee4fb2f1..eb41e7a4d6a778c5c0566b6809907acb5bf9a03f 100644 (file)
@@ -804,6 +804,9 @@ endif()
 
 if(GMX_USE_TNG)
     find_package(ZLIB)
+    include(gmxTestZLib)
+    gmx_test_zlib(HAVE_ZLIB)
+    set(TNG_BUILD_WITH_ZLIB ${HAVE_ZLIB} CACHE BOOL  "Build TNG with zlib compression")
     set(TNG_BUILD_FORTRAN OFF CACHE BOOL "Build Fortran compatible TNG library and examples for testing")
     set(TNG_BUILD_EXAMPLES OFF CACHE BOOL "Build examples showing usage of the TNG API")
     set(TNG_BUILD_COMPRESSION_TESTS OFF CACHE BOOL "Build tests of the TNG compression library")
diff --git a/cmake/gmxTestZLib.cmake b/cmake/gmxTestZLib.cmake
new file mode 100644 (file)
index 0000000..21d2417
--- /dev/null
@@ -0,0 +1,60 @@
+#
+# This file is part of the GROMACS molecular simulation package.
+#
+# Copyright (c) 2014, by the GROMACS development team, led by
+# Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+# and including many others, as listed in the AUTHORS file in the
+# top-level source directory and at http://www.gromacs.org.
+#
+# GROMACS is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public License
+# as published by the Free Software Foundation; either version 2.1
+# of the License, or (at your option) any later version.
+#
+# GROMACS is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with GROMACS; if not, see
+# http://www.gnu.org/licenses, or write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+#
+# If you want to redistribute modifications to GROMACS, please
+# consider that scientific software is very special. Version
+# control is crucial - bugs must be traceable. We will be happy to
+# consider code for inclusion in the official distribution, but
+# derived work must not be called official GROMACS. Details are found
+# in the README & COPYING files - if they are missing, get the
+# official version at http://www.gromacs.org.
+#
+# To help us fund GROMACS development, we humbly ask that you cite
+# the research papers on the package. Check out http://www.gromacs.org.
+
+# - Define macro to check if linking to zlib actually works,
+# because the find_package macro is content if one exists.  This can
+# fail in cross-compilation environments, and we want to know about
+# zlib so the zlib TNG support is built only when it will work.
+#
+#  GMX_TEST_ZLIB(VARIABLE)
+#
+#  VARIABLE will be set to true if zlib support is present
+
+include(CheckLibraryExists)
+include(gmxOptionUtilities)
+function(GMX_TEST_ZLIB VARIABLE)
+    if(ZLIB_FOUND)
+        gmx_check_if_changed(_do_zlib_recompile ZLIB_INCLUDE_DIR ZLIB_LIBRARIES)
+        if(_do_zlib_recompile)
+            unset(ZLIB_LINKS_OK CACHE)
+        endif()
+        check_library_exists("${ZLIB_LIBRARIES}" "zlibVersion" "" ZLIB_LINKS_OK)
+        set(${VARIABLE} ${ZLIB_LINKS_OK} PARENT_SCOPE)
+    else()
+        set(${VARIABLE} OFF PARENT_SCOPE)
+    endif()
+endfunction()
+
+
+