OFF)
mark_as_advanced(GMX_DEVELOPER_BUILD)
+option(GMX_BUILD_SHARED_EXE
+ "Build exectuables as shared binaries. If not set, this disables rpath and dynamic linker flags in an attempt to build a static binary, but this may require setting up the toolchain properly and making appropriate libraries available."
+ ON)
+mark_as_advanced(GMX_BUILD_SHARED_EXE)
+
######################################################################
# Detect OpenMP support
######################################################################
# CMake supports RPATH on OS X only from 2.8.12 upwards.
# CMAKE_SYSTEM_VERSION > 8.0 matches OS X 10.5 and above, where RPATH support
# was added.
-if((NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin") OR
+
+if(NOT GMX_BUILD_SHARED_EXE)
+ # No rpath
+ set(CMAKE_SKIP_RPATH TRUE)
+ set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS) # remove -Wl,-Bdynamic
+ set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS)
+elseif((NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin") OR
((CMAKE_SYSTEM_VERSION VERSION_GREATER 8.0) AND (NOT CMAKE_VERSION VERSION_LESS 2.8.12)))
# The build folder always has bin/ and lib/; if we are also going to
# install to lib/, then the installation RPATH works also in the build
#
# This file is part of the GROMACS molecular simulation package.
#
-# Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+# Copyright (c) 2012,2013,2014,2015, 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.
if (WIN32 AND NOT CYGWIN AND NOT BUILD_SHARED_LIBS)
set(GMX_PREFER_STATIC_LIBS_DEFAULT ON)
endif()
+if (NOT GMX_BUILD_SHARED_EXE)
+ set(GMX_PREFER_STATIC_LIBS_DEFAULT ON)
+ set(SHARED_LIBS_DEFAULT OFF)
+endif()
# Declare the user-visible options
option(BUILD_SHARED_LIBS "Enable shared libraries (can be problematic e.g. with MPI, or on some HPC systems)" ${SHARED_LIBS_DEFAULT})
where that is the default. To use static system libraries, additional
compiler/linker flags are necessary, e.g. `-static-libgcc
-static-libstdc++`.
+* To attempt to link a fully static binary set
+`-DGMX_BUILD_SHARED_EXE=OFF`. This will prevent CMake from explicitly
+setting any dynamic linking flags. This option also sets
+`-DBUILD_SHARED_LIBS=OFF` and `-DGMX_PREFER_STATIC_LIBS=ON` by
+default, but the above caveats apply. For compilers which don't
+default to static linking, the required flags have to be specified. On
+Linux, this is usually `CFLAGS=-static CXXFLAGS=-static`.
### Portability aspects ###
## Building on Cray ##
GROMACS builds mostly out of the box on modern Cray machines, but
-* you may need to specify the use of static or dynamic libraries
- (depending on the machine) with `-DBUILD_SHARED_LIBS=off`,
+* you may need to specify the use of static binaries
+ with `-DGMX_BUILD_SHARED_EXE=off`,
* you may need to set the F77 environmental variable to `ftn` when
compiling FFTW,
-* you may need to use `-DCMAKE_SKIP_RPATH=YES`, and
-* you may need to modify the CMakeLists.txt files to specify the
- `BUILD_SEARCH_END_STATIC` target property.
## Building on BlueGene ##