Add RelWithAssert build type
authorRoland Schulz <roland@utk.edu>
Sun, 2 Mar 2014 19:40:47 +0000 (14:40 -0500)
committerRoland Schulz <roland@utk.edu>
Wed, 5 Mar 2014 23:08:12 +0000 (18:08 -0500)
Works mostly like Release just without -DNDEBUG.

Also generalized some machinery for managing compiler/linker flags so
that we can have an easier time later when we reconsider how to manage
all of our build types.

Also minor corrective changes to the behaviour of other build types.

Change-Id: I70283cb6069cb772c287c0aef329d95b8eacd987

CMakeLists.txt
cmake/gmxBuildTypeReleaseWithAssert.cmake [new file with mode: 0644]
cmake/gmxCFlags.cmake
cmake/gmxManageSharedLibraries.cmake

index 6a47b6d846d7017e3eb8a2fd6a2148c9d8b2af2e..74da62314cd58bc1d93c640f94c0f4f05e835b05 100644 (file)
@@ -96,14 +96,26 @@ mark_as_advanced(GMX_INSTALL_PREFIX)
 
 include(gmxBuildTypeReference)
 include(gmxBuildTypeThreadSanitizer)
+include(gmxBuildTypeReleaseWithAssert)
 
 if(NOT CMAKE_BUILD_TYPE)
-    set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel Reference." FORCE)
+    set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel Reference RelWithAssert." FORCE)
     # There's no need to offer a user the choice of ThreadSanitizer
     # Set the possible values of build type for cmake-gui
     set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
-        "MinSizeRel" "RelWithDebInfo")
-endif(NOT CMAKE_BUILD_TYPE)
+        "MinSizeRel" "RelWithDebInfo" "Reference" "RelWithAssert")
+endif()
+if(CMAKE_CONFIGURATION_TYPES)
+    # Add appropriate GROMACS-specific build types for the Visual
+    # Studio generator (Debug, Release, MinSizeRel and RelWithDebInfo
+    # are already present by default).
+    list(APPEND CMAKE_CONFIGURATION_TYPES "RelWithAssert" "Reference")
+    list(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
+    set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
+        "List of configuration types"
+        FORCE)
+endif()
+set(build_types_with_explicit_flags RELEASE DEBUG RELWITHDEBUGINFO RELWITHASSERT MINSIZEREL)
 
 enable_language(C)
 enable_language(CXX)
diff --git a/cmake/gmxBuildTypeReleaseWithAssert.cmake b/cmake/gmxBuildTypeReleaseWithAssert.cmake
new file mode 100644 (file)
index 0000000..9aca788
--- /dev/null
@@ -0,0 +1,41 @@
+#
+# 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.
+
+# Custom build type "ReleaseWithAssert".
+string(REGEX REPLACE "[/-][dD][^/-]*NDEBUG" "" CMAKE_C_FLAGS_RELWITHASSERT_INIT "${CMAKE_C_FLAGS_RELEASE_INIT}")
+string(REGEX REPLACE "[/-][dD][^/-]*NDEBUG" "" CMAKE_CXX_FLAGS_RELWITHASSERT_INIT "${CMAKE_CXX_FLAGS_RELEASE_INIT}")
+set( CMAKE_C_FLAGS_RELWITHASSERT "${CMAKE_C_FLAGS_RELWITHASSERT_INIT}" CACHE STRING "C flags for release with assert builds.")
+set( CMAKE_CXX_FLAGS_RELWITHASSERT "${CMAKE_CXX_FLAGS_RELWITHASSERT_INIT}" CACHE STRING "C++ flags for release with assert builds.")
+mark_as_advanced( CMAKE_CXX_FLAGS_RELWITHASSERT CMAKE_C_FLAGS_RELWITHASSERT)
+
index 7b4994a1e04933c0359dc49e45d5c1d7aef63321..aefd42a15eee601da3dbd56013450f779ce60996 100644 (file)
@@ -54,6 +54,44 @@ MACRO(GMX_TEST_CXXFLAG VARIABLE FLAGS CXXFLAGSVAR)
     ENDIF (${VARIABLE})
 ENDMACRO(GMX_TEST_CXXFLAG VARIABLE FLAGS CXXFLAGSVAR)
 
+# Set the real CMake variables for compiler flags. This should be a function
+# so we can have proper local variables while avoiding duplicating code.
+function(gmx_set_cmake_compiler_flags)
+    foreach(language C CXX)
+        # Copy the flags for the release build type to the build types
+        # that are modified forms of it. Ideally, the list of build
+        # types that are modifications of the Release build type would
+        # be set up elsewhere and passed to this function, but it is
+        # inconvenient in CMake to pass more than one list, and such a
+        # list is only used here.
+        foreach(build_type RELWITHDEBUGINFO RELWITHASSERT MINSIZEREL)
+            set(GMXC_${language}FLAGS_${build_type} "${GMXC_${language}FLAGS_RELEASE}")
+        endforeach()
+        # Copy the flags that are only used by the real Release build
+        # type. Currently unused, but we plan to use -Wno-array-bounds
+        # in Release to work around gcc-4.8 being a little too vocal
+        # about some perfectly good code, while using RelWithAssert
+        # (ie. without that suppression) in Jenkins.
+        set(GMXC_${language}FLAGS_RELEASE "${GMXC_${language}FLAGS_RELEASE} ${GMXC_${language}FLAGS_RELEASE_ONLY}")
+
+        # Modify the real CMake variables for compiler flags for all
+        # builds and language types, and also those common to all
+        # build types.
+        foreach(build_type "" ${build_types_with_explicit_flags})
+            if("${build_type}" STREQUAL "")
+                set(punctuation "") # for general compiler flags (e.g.) CMAKE_CXX_FLAGS
+            else()
+                set(punctuation "_") # for build-type-specific compiler flags (e.g.) CMAKE_CXX_FLAGS_RELEASE
+            endif()
+
+            # Append to the variables for the given build type for
+            # each language, in the parent scope.
+            set(CMAKE_${language}_FLAGS${punctuation}${build_type}
+                "${GMXC_${language}FLAGS${punctuation}${build_type}} ${CMAKE_${language}_FLAGS${punctuation}${build_type}}"
+                PARENT_SCOPE)
+        endforeach()
+    endforeach()
+endfunction()
 
 # This is the actual exported function to be called 
 MACRO(gmx_c_flags)
@@ -182,20 +220,8 @@ MACRO(gmx_c_flags)
     endif()
 
     # now actually set the flags:
-    # C
-    if ( NOT GMX_SKIP_DEFAULT_CFLAGS )
-        set(CMAKE_C_FLAGS "${GMXC_CFLAGS} ${CMAKE_C_FLAGS}")
-        set(CMAKE_C_FLAGS_RELEASE "${GMXC_CFLAGS_RELEASE} ${CMAKE_C_FLAGS_RELEASE}")
-        set(CMAKE_C_FLAGS_DEBUG "${GMXC_CFLAGS_DEBUG} ${CMAKE_C_FLAGS_DEBUG}")
-    endif()
-
-    # C++
-    if ( NOT GMX_SKIP_DEFAULT_CFLAGS)
-        set(CMAKE_CXX_FLAGS "${GMXC_CXXFLAGS} ${CMAKE_CXX_FLAGS}")
-        set(CMAKE_CXX_FLAGS_RELEASE 
-            "${GMXC_CXXFLAGS_RELEASE} ${CMAKE_CXX_FLAGS_RELEASE}")
-        set(CMAKE_CXX_FLAGS_DEBUG 
-            "${GMXC_CXXFLAGS_DEBUG} ${CMAKE_CXX_FLAGS_DEBUG}")
+    if (NOT GMX_SKIP_DEFAULT_CFLAGS)
+        gmx_set_cmake_compiler_flags()
     endif()
 ENDMACRO(gmx_c_flags)
 
index 6d3d18d4058313fa3b87fe7b7744554fe71c27ba..d4794d1378651e37f9df4ae207322ff6a06cbedf 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2012,2013, by the GROMACS development team, led by
+# Copyright (c) 2012,2013,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.
@@ -87,6 +87,27 @@ if (UNIX AND GMX_PREFER_STATIC_LIBS)
     # be used, so we'll add both to the preference list.
     SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.a" ${CMAKE_FIND_LIBRARY_SUFFIXES})
 endif()
+
+# ==========
+# Only things for managing shared libraries and build types on Windows follow
+
+# Change the real CMake variables so we prefer static linking. This
+# should be a function so we can have proper local variables while
+# avoiding duplicating code.
+function(gmx_manage_prefer_static_libs_flags build_type)
+    if("${build_type}" STREQUAL "")
+        set(punctuation "") # for general compiler flags (e.g.) CMAKE_CXX_FLAGS
+    else()
+        set(punctuation "_") # for build-type-specific compiler flags (e.g.) CMAKE_CXX_FLAGS_RELEASE
+    endif()
+
+    # Change the real CMake variables for the given build type in each
+    # language, in the parent scope.
+    foreach(language C CXX)
+        string(REPLACE /MD /MT CMAKE_${language}_FLAGS${punctuation}${build_type} ${CMAKE_${language}_FLAGS${punctuation}${build_type}} PARENT_SCOPE)
+    endforeach()
+endfunction()
+
 IF( WIN32 AND NOT CYGWIN)
   if (NOT BUILD_SHARED_LIBS)
       if(NOT GMX_PREFER_STATIC_LIBS)
@@ -103,11 +124,9 @@ IF( WIN32 AND NOT CYGWIN)
   endif()
 
   IF (GMX_PREFER_STATIC_LIBS)
-      #Only setting Debug and Release flags. Others configurations are current not used.
-      STRING(REPLACE /MD /MT CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
-      STRING(REPLACE /MD /MT CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
-      STRING(REPLACE /MD /MT CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
-      STRING(REPLACE /MD /MT CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
+      foreach(build_type "" ${build_types_with_explicit_flags})
+          gmx_manage_prefer_static_libs_flags("${build_type}")
+      endforeach()
   ENDIF()
   IF( CMAKE_C_COMPILER_ID MATCHES "Intel" )
     if(BUILD_SHARED_LIBS) #not sure why incremental building with shared libs doesn't work