You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2018/12/20 14:37:03 UTC

[arrow] branch master updated: ARROW-4082: [C++] Allow RelWithDebInfo, improve FindClangTools

This is an automated email from the ASF dual-hosted git repository.

wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new c39db63  ARROW-4082: [C++] Allow RelWithDebInfo, improve FindClangTools
c39db63 is described below

commit c39db631f74e617b5317a64997364ea61c82c5f1
Author: Benjamin Kietzman <be...@gmail.com>
AuthorDate: Thu Dec 20 08:36:54 2018 -0600

    ARROW-4082: [C++] Allow RelWithDebInfo, improve FindClangTools
    
    SetupCxxFlags.cmake does not list "RELWITHDEBINFO" in the final flag
    setup, so cmake will error out if that build config is selected. It's
    handy for quick debugging without switching your python build etc over
    to "DEBUG".
    
    FindClangTools.cmake could check the version of 'clang-format' (no
    version suffix) to see if it satisfies a version requirement. Also the doccomment lists the incorrect variable name for the hint path
    
    Author: Benjamin Kietzman <be...@gmail.com>
    
    Closes #3227 from bkietz/ARROW-4082-tweak-cmake and squashes the following commits:
    
    15526cf01 <Benjamin Kietzman> allow RelWithDebInfo, improve FindClangTools
---
 cpp/README.md                          |  6 ++++++
 cpp/cmake_modules/FindClangTools.cmake | 29 +++++++++++++++++++++++++----
 cpp/cmake_modules/SetupCxxFlags.cmake  |  1 +
 3 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/cpp/README.md b/cpp/README.md
index 5940db1..b602bef 100644
--- a/cpp/README.md
+++ b/cpp/README.md
@@ -428,6 +428,12 @@ You may find the required packages at http://releases.llvm.org/download.html
 or use the Debian/Ubuntu APT repositories on https://apt.llvm.org/. On macOS
 with [Homebrew][1] you can get it via `brew install llvm@6`.
 
+Depending on how you installed clang-format, the build system may not be able
+to find it. You can provide an explicit path to your LLVM installation (or the
+root path for the clang tools) with the environment variable
+`$CLANG_TOOLS_PATH` or by passing `-DClangTools_PATH=$PATH_TO_CLANG_TOOLS` when
+invoking CMake.
+
 ## Checking for ABI and API stability
 
 To build ABI compliance reports, you need to install the two tools
diff --git a/cpp/cmake_modules/FindClangTools.cmake b/cpp/cmake_modules/FindClangTools.cmake
index 2ddf788..62ee8c3 100644
--- a/cpp/cmake_modules/FindClangTools.cmake
+++ b/cpp/cmake_modules/FindClangTools.cmake
@@ -20,7 +20,7 @@
 # Variables used by this module, they can change the default behaviour and need
 # to be set before calling find_package:
 #
-#  ClangToolsBin_HOME -
+#  ClangTools_PATH -
 #   When set, this path is inspected instead of standard library binary locations
 #   to find clang-tidy and clang-format
 #
@@ -75,10 +75,11 @@ if (CLANG_FORMAT_VERSION)
     )
 
     # If not found yet, search alternative locations
-    if (("${CLANG_FORMAT_BIN}" STREQUAL "CLANG_FORMAT_BIN-NOTFOUND") AND APPLE)
+    if ("${CLANG_FORMAT_BIN}" STREQUAL "CLANG_FORMAT_BIN-NOTFOUND")
+      STRING(REGEX REPLACE "^([0-9]+)\\.[0-9]+" "\\1" CLANG_FORMAT_MAJOR_VERSION "${CLANG_FORMAT_VERSION}")
+      STRING(REGEX REPLACE "^[0-9]+\\.([0-9]+)" "\\1" CLANG_FORMAT_MINOR_VERSION "${CLANG_FORMAT_VERSION}")
+      if (APPLE)
         # Homebrew ships older LLVM versions in /usr/local/opt/llvm@version/
-        STRING(REGEX REPLACE "^([0-9]+)\\.[0-9]+" "\\1" CLANG_FORMAT_MAJOR_VERSION "${CLANG_FORMAT_VERSION}")
-        STRING(REGEX REPLACE "^[0-9]+\\.([0-9]+)" "\\1" CLANG_FORMAT_MINOR_VERSION "${CLANG_FORMAT_VERSION}")
         if ("${CLANG_FORMAT_MINOR_VERSION}" STREQUAL "0")
             find_program(CLANG_FORMAT_BIN
               NAMES clang-format
@@ -102,7 +103,27 @@ if (CLANG_FORMAT_VERSION)
                   NO_DEFAULT_PATH
           )
         endif()
+      else()
+        # try searching for "clang-format" and check the version
+        find_program(CLANG_FORMAT_BIN
+          NAMES clang-format
+          PATHS
+                ${ClangTools_PATH}
+                $ENV{CLANG_TOOLS_PATH}
+                /usr/local/bin /usr/bin
+                NO_DEFAULT_PATH
+        )
+        if (NOT ("${CLANG_FORMAT_BIN}" STREQUAL "CLANG_FORMAT_BIN-NOTFOUND"))
+          execute_process(COMMAND ${CLANG_FORMAT_BIN} "-version"
+            OUTPUT_VARIABLE CLANG_FORMAT_FOUND_VERSION_MESSAGE
+            OUTPUT_STRIP_TRAILING_WHITESPACE)
+          if (NOT ("${CLANG_FORMAT_FOUND_VERSION_MESSAGE}" MATCHES "^clang-format version ${CLANG_FORMAT_MAJOR_VERSION}\\.${CLANG_FORMAT_MINOR_VERSION}.*"))
+            set(CLANG_FORMAT_BIN "CLANG_FORMAT_BIN-NOTFOUND")
+          endif()
+        endif()
+      endif()
     endif()
+
 else()
     find_program(CLANG_FORMAT_BIN
       NAMES clang-format-4.0
diff --git a/cpp/cmake_modules/SetupCxxFlags.cmake b/cpp/cmake_modules/SetupCxxFlags.cmake
index 61fd14c..1160835 100644
--- a/cpp/cmake_modules/SetupCxxFlags.cmake
+++ b/cpp/cmake_modules/SetupCxxFlags.cmake
@@ -365,6 +365,7 @@ message("Configured for ${CMAKE_BUILD_TYPE} build (set with cmake -DCMAKE_BUILD_
 if ("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG")
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_FLAGS_DEBUG}")
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_FLAGS_DEBUG}")
+elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "RELWITHDEBINFO")
 elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "FASTDEBUG")
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_FLAGS_FASTDEBUG}")
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_FLAGS_FASTDEBUG}")