From 6039cf84e23fd2482386ea6c8f44dd295b7ba93f Mon Sep 17 00:00:00 2001
From: Your Name <you@example.com>
Date: Tue, 19 Jun 2018 16:35:06 +0000
Subject: [PATCH] guard CXXFLAGS setting with check to see if it's already set

---
 cpp/cmake_modules/SetupCxxFlags.cmake | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/cpp/cmake_modules/SetupCxxFlags.cmake b/cpp/cmake_modules/SetupCxxFlags.cmake
index 9151860..0d34992 100644
--- a/cpp/cmake_modules/SetupCxxFlags.cmake
+++ b/cpp/cmake_modules/SetupCxxFlags.cmake
@@ -220,21 +220,23 @@ endif(NOT CMAKE_BUILD_TYPE)
 
 string (TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
 
-# Set compile flags based on the build type.
-message("Configured for ${CMAKE_BUILD_TYPE} build (set with cmake -DCMAKE_BUILD_TYPE={release,debug,...})")
-if ("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG")
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_FLAGS_DEBUG}")
-elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "FASTDEBUG")
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_FLAGS_FASTDEBUG}")
-elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "RELEASE")
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_FLAGS_RELEASE}")
-elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "PROFILE_GEN")
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_FLAGS_PROFILE_GEN}")
-elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "PROFILE_BUILD")
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_FLAGS_PROFILE_BUILD}")
-else()
-  message(FATAL_ERROR "Unknown build type: ${CMAKE_BUILD_TYPE}")
-endif ()
+if ("${CMAKE_CXX_FLAGS}" STREQUAL "")
+	# Set compile flags based on the build type.
+	message("Configured for ${CMAKE_BUILD_TYPE} build (set with cmake -DCMAKE_BUILD_TYPE={release,debug,...})")
+	if ("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG")
+	  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_FLAGS_DEBUG}")
+	elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "FASTDEBUG")
+	  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_FLAGS_FASTDEBUG}")
+	elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "RELEASE")
+	  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_FLAGS_RELEASE}")
+	elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "PROFILE_GEN")
+	  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_FLAGS_PROFILE_GEN}")
+	elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "PROFILE_BUILD")
+	  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_FLAGS_PROFILE_BUILD}")
+	else()
+	  message(FATAL_ERROR "Unknown build type: ${CMAKE_BUILD_TYPE}")
+	endif ()
+endif()
 
 if ("${CMAKE_CXX_FLAGS}" MATCHES "-DNDEBUG")
   set(ARROW_DEFINITION_FLAGS "-DNDEBUG")
-- 
2.16.1

