Changed defaults for building shared libraries
authorMark Abraham <mark.j.abraham@gmail.com>
Wed, 9 Jan 2013 15:29:50 +0000 (16:29 +0100)
committerMark Abraham <mark.j.abraham@gmail.com>
Sun, 13 Jan 2013 15:13:23 +0000 (16:13 +0100)
Some platforms have reasons for preferring shared or static
libraries and we should nudge the user in the right direction
if we can.

Also, the logic for detecting external shared vs static libraries
was conflated with the settings for building shared libraries. This
needed to be separated so there was a place where specific
toolchains could manage options settings correctly for their
contexts.

Change-Id: I76ed873f2ff5d8aba11c454dea497e5f329111af

CMakeLists.txt

index 6e2f8fb15692046af7f82ad720dd95568de6bc18..e67fb43fe8ce84cbfceb32f6e9a7488adc1fc9dc 100644 (file)
@@ -329,11 +329,6 @@ if(GMX_SOFTWARE_INVSQRT)
   set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_SOFTWARE_INVSQRT")
 endif(GMX_SOFTWARE_INVSQRT)
 
-########################################################################
-#Process MPI settings
-########################################################################
-include(gmxManageMPI)
-
 #######################################################################
 # Check for options incompatible with OpenMM build                    #
 #######################################################################
@@ -484,28 +479,57 @@ include(TestBigEndian)
 test_big_endian(GMX_INTEGER_BIG_ENDIAN)
 
 
+if(APPLE OR CYGWIN OR ${CMAKE_SYSTEM_NAME} MATCHES "Linux|.*BSD")
+    # Maybe Solaris should be here? Patch this if you know!
+    SET(SHARED_LIBS_DEFAULT ON)
+elseif(WIN32 OR ${CMAKE_SYSTEM_NAME} MATCHES "BlueGene")
+    # Support for shared libs on native Windows is a bit new. Its
+    # default might change later if/when we sort things out. Also,
+    # Cray should go here. What variable value can detect it?
+    SET(SHARED_LIBS_DEFAULT OFF)
+else()
+    message(STATUS "Defaulting to building static libraries")
+    SET(SHARED_LIBS_DEFAULT OFF)
+endif()
+
+# Management of GROMACS options for specific toolchains should go
+# here. Because the initial settings for some of the main options have
+# already happened, but things like library detection and MPI compiler
+# feature detection have not, the docstrings for any over-rides of
+# GROMACS defaults or user settings will make sense. Also, any
+# toolchain-related reasons for choosing whether to detect various
+# things can be sorted out now, before the detection takes place.
+
+if(UNIX AND GMX_PREFER_STATIC_LIBS AND SHARED_LIBS_DEFAULT)
+    if(BUILD_SHARED_LIBS)
+        # Warn the user about the combination. But don't overwrite the request.
+        message(WARNING "Searching for static libraries requested, and building shared Gromacs libraries requested. This might cause problems linking later.")
+    elseif(NOT DEFINED BUILD_SHARED_LIBS)
+        # Change default to OFF. Don't warn if it's already off.
+        message(WARNING "Searching for static libraries requested, so the GROMACS libraries will also be built statically (BUILD_SHARED_LIBS=OFF)")
+        set(SHARED_LIBS_DEFAULT OFF)
+    endif()
+endif()
 
+# By now, all tool chains should have spoken up if they care about
+# the setting of SHARED_LIBS_DEFAULT.
+option(BUILD_SHARED_LIBS "Enable shared libraries (can be problematic e.g. with MPI, or on some HPC systems)" ${SHARED_LIBS_DEFAULT})
+
+########################################################################
+#Process MPI settings
+########################################################################
+include(gmxManageMPI)
 
 ########################################################################
 # Find external packages                                               #
 ########################################################################
-SET(SHARED_LIBS_DEFAULT ON)
-if(UNIX)
-    if(GMX_PREFER_STATIC_LIBS)
-        # On Linux .a is the static library suffix, on Mac OS X .lib can also
-        # be used, so we'll add both to the preference list.
-        SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.a" ${CMAKE_FIND_LIBRARY_SUFFIXES})
-        if(BUILD_SHARED_LIBS) #Warn the user about the combination. But don't overwrite the request.
-            message(WARNING "Static libraries requested, and shared Gromacs libraries requested.")
-        elseif(NOT DEFINED BUILD_SHARED_LIBS) #Change default to OFF. Don't warn if it's already off.
-            message(WARNING "Static libraries requested, the GROMACS libraries will also be build static (BUILD_SHARED_LIBS=OFF)")
-            set(SHARED_LIBS_DEFAULT OFF)
-        endif()
-    endif()
+if(UNIX AND GMX_PREFER_STATIC_LIBS)
+    # On Linux .a is the static library suffix, on Mac OS X .lib can also
+    # be used, so we'll add both to the preference list.
+    SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.a" ${CMAKE_FIND_LIBRARY_SUFFIXES})
 endif()
 
 IF( WIN32 AND NOT CYGWIN)
-  SET(SHARED_LIBS_DEFAULT OFF) #becuase shared libs on Windows is still new - turning it off by default
   if (NOT BUILD_SHARED_LIBS)
       option(GMX_PREFER_STATIC_LIBS "When finding libraries prefer static system libraries (MT instead of MD)!" ON)
       if(NOT GMX_PREFER_STATIC_LIBS)
@@ -538,8 +562,6 @@ IF( WIN32 AND NOT CYGWIN)
   ENDIF()
 ENDIF()
 
-option(BUILD_SHARED_LIBS "Enable shared libraries (can be problematic e.g. with MPI)" ${SHARED_LIBS_DEFAULT})
-
 option(GMX_GSL "Add support for gsl" OFF)
 if (GMX_GSL)
   find_package(gsl)