From 29cbabdb8d6a1090e663b935523ee4073ca21387 Mon Sep 17 00:00:00 2001 From: Szilard Pall Date: Fri, 29 Oct 2010 15:44:31 +0200 Subject: [PATCH] added CMake option GMX_PREFER_STATIC_LIBS (also fixes bug #541) 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 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e6345269d8..420b0be24a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 "") -- 2.11.4.GIT