added CMake option GMX_PREFER_STATIC_LIBS (also fixes bug #541)
authorSzilard Pall <pszilard@cbr.su.se>
Fri, 29 Oct 2010 13:44:31 +0000 (15:44 +0200)
committerSzilard Pall <pszilard@cbr.su.se>
Fri, 29 Oct 2010 16:06:33 +0000 (18:06 +0200)
This option instructs CMake to prefer static external libs when both static
and shared version available. This makes possible linking statically against
external libraries (e.g. fftw, xml2).

The option only available on *NIX platforms, except APPLE and CYGWIN.

Note, that when the option is enabled UILD_SHARED_LIBS gets disabled.
Also note, that with this option on, the binaries built will still be
dynamically linked against system libraries.

CMakeLists.txt

index e6345269d85cd1601422fc219b2f5707ef531f05..420b0be24a833a4bcdb1907718a8835ca53d3a11 100644 (file)
@@ -115,6 +115,11 @@ mark_as_advanced(USE_VERSION_H)
 
 option(GMX_DEFAULT_SUFFIX "Use default suffixes for GROMACS binaries and libs (_d for double, _mpi for MPI; rerun cmake after changing to see relevant options)" ON)
 
+if(UNIX AND NOT APPLE AND NOT CYGWIN)
+    option(GMX_PREFER_STATIC_LIBS "When finding libraries prefer \".a\" static archives (NOTE: this is enabled only for UNIX (excluding APPLE and CYGWIN) platforms but it might not always work!" OFF)
+    mark_as_advanced(GMX_PREFER_STATIC_LIBS)
+endif()
+
 ########################################################################
 # Set up binary and library suffixing 
 ########################################################################
@@ -346,6 +351,15 @@ test_big_endian(GMX_INTEGER_BIG_ENDIAN)
 ########################################################################
 # Find external packages                                               #
 ########################################################################
+if(UNIX AND NOT APPLE AND NOT CYGWIN)
+    if(GMX_PREFER_STATIC_LIBS)
+        SET(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
+        if(BUILD_SHARED_LIBS)
+            message(WARNING "Static libraries requested, the GROMACS libraries will also be build static (BUILD_SHARED_LIBS=OFF)")
+            set(BUILD_SHARED_LIBS OFF CACHE BOOL "Enable shared libraries (can be problematic with MPI, Windows)" FORCE)
+        endif()
+    endif()
+endif()
 
 find_package(LibXml2)
 set(PKG_XML "")