From patchwork Fri Sep 23 19:16:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 9348675 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1682C607F2 for ; Fri, 23 Sep 2016 19:17:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04D3F2AD7D for ; Fri, 23 Sep 2016 19:17:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED5A72AD7E; Fri, 23 Sep 2016 19:17:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 896312AD81 for ; Fri, 23 Sep 2016 19:17:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760968AbcIWTRf (ORCPT ); Fri, 23 Sep 2016 15:17:35 -0400 Received: from quartz.orcorp.ca ([184.70.90.242]:54201 "EHLO quartz.orcorp.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760173AbcIWTRQ (ORCPT ); Fri, 23 Sep 2016 15:17:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=obsidianresearch.com; s=rsa1; h=References:In-Reply-To:Message-Id:Date:Subject:To:From; bh=VdNiDJOjkk+U/UgdjnS65MhMTRBMUQHXn+szWV8iMBw=; b=PCdXNjkd9sT1gbZieQcET8UbWT7XKt6kst2XgXL6hxTDWnhEhy3ivLMz+KXtEXUgYngOnLpuTU+o99YeQk10CRs/JGAXrjtRem8CWuHKItThA3pNuMhKHOCwBaP1NABda+exjsOQ03C0K14S24rA1bj6uwFuK47wjNxnHeR9zAc=; Received: from [10.0.0.151] (helo=jggl.edm.orcorp.ca) by quartz.orcorp.ca with esmtps (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1bnVyF-0007dS-DN for linux-rdma@vger.kernel.org; Fri, 23 Sep 2016 13:17:15 -0600 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Subject: [PATCH 01/13] Be consistent about defining NDEBUG Date: Fri, 23 Sep 2016 13:16:56 -0600 Message-Id: <1474658228-5390-2-git-send-email-jgunthorpe@obsidianresearch.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1474658228-5390-1-git-send-email-jgunthorpe@obsidianresearch.com> References: <1474658228-5390-1-git-send-email-jgunthorpe@obsidianresearch.com> X-Broken-Reverse-DNS: no host name found for IP address 10.0.0.151 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We setup the two standard CMake build_types so that Release includes NDEBUG and RelWithDebInfo does not (by default CMake sets it in both). The recommendation is for packagers to use Release (by setting -DCMAKE_BUILD_TYPE=Release) and developers use RelWithDebInfo (the default) This also replaces the default flags for Release with the RelWithDebInfo, flags (-O2 -g -DNDEBUG) which is what we consider suitable for packaging. The CMake default of -O3 is not tested. Note that all the packaging systems I looked at force NDEBUG into the CFLAGS. Signed-off-by: Jason Gunthorpe --- CMakeLists.txt | 5 +++++ buildlib/RDMA_BuildType.cmake | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 buildlib/RDMA_BuildType.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index a829cd477c52..06dd98203349 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,9 @@ # Common options passed to cmake are: # -DCMAKE_EXPORT_COMPILE_COMMANDS=1 # Write a compile_commands.json file for clang tooling +# -DCMAKE_BUILD_TYPE=RelWithDebInfo +# Change the optimization level, Debug disables optimization, +# Release is for packagers # -DENABLE_VALGRIND=1 (default disabled) # Embed valgrind notations, this has a tiny negative performance impact # -DENABLE_RESOLVE_NEIGH=0 (default enabled) @@ -58,12 +61,14 @@ include(CheckCCompilerFlag) include(CheckIncludeFile) include(CheckTypeSize) include(RDMA_EnableCStd) +include(RDMA_BuildType) include(RDMA_DoFixup) include(publish_headers) include(rdma_functions) #------------------------- # Setup the basic C compiler +RDMA_BuildType() include_directories(${BUILD_INCLUDE}) # FIXME: Eliminate HAVE_CONFIG_H, we always have it. add_definitions(-DHAVE_CONFIG_H) diff --git a/buildlib/RDMA_BuildType.cmake b/buildlib/RDMA_BuildType.cmake new file mode 100644 index 000000000000..4f7485c397a0 --- /dev/null +++ b/buildlib/RDMA_BuildType.cmake @@ -0,0 +1,41 @@ +# COPYRIGHT (c) 2015 Obsidian Research Corporation. See COPYING file + +function(RDMA_BuildType) + set(build_types Debug Release RelWithDebInfo MinSizeRel) + + # Set the default build type to RelWithDebInfo. Since RDMA is typically used + # in performance contexts it doesn't make much sense to have the default build + # turn off the optimizer. + if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE String + "Options are ${build_types}" + FORCE + ) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${build_types}) + endif() + + # Release should be used by packagers, it is the same as the default RelWithDebInfo, + # this means it uses -O2 and -DNDEBUG (not -O3) + foreach (language CXX C) + set(VAR_TO_MODIFY "CMAKE_${language}_FLAGS_RELEASE") + if ("${${VAR_TO_MODIFY}}" STREQUAL "${${VAR_TO_MODIFY}_INIT}") + set(${VAR_TO_MODIFY} "${CMAKE_${language}_FLAGS_RELWITHDEBINFO_INIT}" + CACHE STRING "Default flags for Release configuration" FORCE) + endif() + endforeach() + + # RelWithDebInfo should be used by developers, it is the same as Release but + # with the -DNDEBUG removed + foreach (language CXX C) + set(VAR_TO_MODIFY "CMAKE_${language}_FLAGS_RELWITHDEBINFO") + if (${${VAR_TO_MODIFY}} STREQUAL ${${VAR_TO_MODIFY}_INIT}) + string(REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" + " " + replacement + "${${VAR_TO_MODIFY}}" + ) + set(${VAR_TO_MODIFY} "${replacement}" + CACHE STRING "Default flags for RelWithDebInfo configuration" FORCE) + endif() + endforeach() +endfunction()