[libcxxabi] Refactor CMakeLists.txt's handling of compile and link flags to suppress...
authorEric Fiselier <eric@efcs.ca>
Tue, 18 Nov 2014 20:37:53 +0000 (20:37 +0000)
committerEric Fiselier <eric@efcs.ca>
Tue, 18 Nov 2014 20:37:53 +0000 (20:37 +0000)
Summary:
This patch mirrors the recent change to libc++ found here http://reviews.llvm.org/D6277.
This fixes PR20395 (http://llvm.org/bugs/show_bug.cgi?id=20395).

Reviewers: jroelofs, mclow.lists, danalbert

Reviewed By: danalbert

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D6286

llvm-svn: 222252

libcxxabi/CMakeLists.txt
libcxxabi/src/CMakeLists.txt
libcxxabi/src/Unwind/CMakeLists.txt

index 494b18d..87901a5 100644 (file)
@@ -152,69 +152,78 @@ macro(append_if list condition var)
   endif()
 endmacro()
 
+set(LIBCXXABI_CXX_FLAGS "")
+set(LIBCXXABI_COMPILE_FLAGS "")
+set(LIBCXXABI_LINK_FLAGS "")
+
+
 if (LIBCXXABI_HAS_NOSTDINCXX_FLAG)
-  list(APPEND LIBCXXABI_CXX_REQUIRED_FLAGS -nostdinc++)
+  list(APPEND LIBCXXABI_COMPILE_FLAGS -nostdinc++)
+  # Remove -stdlib flags to prevent them from causing an unused flag warning.
+  string(REPLACE "-stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+  string(REPLACE "-stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
 endif()
 
-append_if(LIBCXXABI_CXX_REQUIRED_FLAGS LIBCXXABI_HAS_WERROR_FLAG -Werror=return-type)
+
+append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_WERROR_FLAG -Werror=return-type)
 
 # Get warning flags
-append_if(LIBCXXABI_CXX_WARNING_FLAGS LIBCXXABI_HAS_W_FLAG -W)
-append_if(LIBCXXABI_CXX_WARNING_FLAGS LIBCXXABI_HAS_WALL_FLAG -Wall)
-append_if(LIBCXXABI_CXX_WARNING_FLAGS LIBCXXABI_HAS_WCHAR_SUBSCRIPTS_FLAG -Wchar-subscripts)
-append_if(LIBCXXABI_CXX_WARNING_FLAGS LIBCXXABI_HAS_WCONVERSION_FLAG -Wconversion)
-append_if(LIBCXXABI_CXX_WARNING_FLAGS LIBCXXABI_HAS_WMISMATCHED_TAGS_FLAG -Wmismatched-tags)
-append_if(LIBCXXABI_CXX_WARNING_FLAGS LIBCXXABI_HAS_WMISSING_BRACES_FLAG -Wmissing-braces)
-append_if(LIBCXXABI_CXX_WARNING_FLAGS LIBCXXABI_HAS_WNEWLINE_EOF_FLAG -Wnewline-eof)
-append_if(LIBCXXABI_CXX_WARNING_FLAGS LIBCXXABI_HAS_WNO_UNUSED_FUNCTION_FLAG -Wno-unused-function)
-append_if(LIBCXXABI_CXX_WARNING_FLAGS LIBCXXABI_HAS_WSHADOW_FLAG -Wshadow)
-append_if(LIBCXXABI_CXX_WARNING_FLAGS LIBCXXABI_HAS_WSHORTEN_64_TO_32_FLAG -Wshorten-64-to-32)
-append_if(LIBCXXABI_CXX_WARNING_FLAGS LIBCXXABI_HAS_WSIGN_COMPARE_FLAG -Wsign-compare)
-append_if(LIBCXXABI_CXX_WARNING_FLAGS LIBCXXABI_HAS_WSIGN_CONVERSION_FLAG -Wsign-conversion)
-append_if(LIBCXXABI_CXX_WARNING_FLAGS LIBCXXABI_HAS_WSTRICT_ALIASING_FLAG -Wstrict-aliasing=2)
-append_if(LIBCXXABI_CXX_WARNING_FLAGS LIBCXXABI_HAS_WSTRICT_OVERFLOW_FLAG -Wstrict-overflow=4)
-append_if(LIBCXXABI_CXX_WARNING_FLAGS LIBCXXABI_HAS_WUNUSED_PARAMETER_FLAG -Wunused-parameter)
-append_if(LIBCXXABI_CXX_WARNING_FLAGS LIBCXXABI_HAS_WUNUSED_VARIABLE_FLAG -Wunused-variable)
-append_if(LIBCXXABI_CXX_WARNING_FLAGS LIBCXXABI_HAS_WWRITE_STRINGS_FLAG -Wwrite-strings)
+append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_W_FLAG -W)
+append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_WALL_FLAG -Wall)
+append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_WCHAR_SUBSCRIPTS_FLAG -Wchar-subscripts)
+append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_WCONVERSION_FLAG -Wconversion)
+append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_WMISMATCHED_TAGS_FLAG -Wmismatched-tags)
+append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_WMISSING_BRACES_FLAG -Wmissing-braces)
+append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_WNEWLINE_EOF_FLAG -Wnewline-eof)
+append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_WNO_UNUSED_FUNCTION_FLAG -Wno-unused-function)
+append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_WSHADOW_FLAG -Wshadow)
+append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_WSHORTEN_64_TO_32_FLAG -Wshorten-64-to-32)
+append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_WSIGN_COMPARE_FLAG -Wsign-compare)
+append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_WSIGN_CONVERSION_FLAG -Wsign-conversion)
+append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_WSTRICT_ALIASING_FLAG -Wstrict-aliasing=2)
+append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_WSTRICT_OVERFLOW_FLAG -Wstrict-overflow=4)
+append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_WUNUSED_PARAMETER_FLAG -Wunused-parameter)
+append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_WUNUSED_VARIABLE_FLAG -Wunused-variable)
+append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_WWRITE_STRINGS_FLAG -Wwrite-strings)
 
 if (LIBCXXABI_ENABLE_WERROR)
-  append_if(LIBCXXABI_CXX_WARNING_FLAGS LIBCXXABI_HAS_WERROR_FLAG -Werror)
-  append_if(LIBCXXABI_CXX_WARNING_FLAGS LIBCXXABI_HAS_WX_FLAG -WX)
+  append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_WERROR_FLAG -Werror)
+  append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_WX_FLAG -WX)
 else()
-  append_if(LIBCXXABI_CXX_WARNING_FLAGS LIBCXXABI_HAS_WNO_ERROR_FLAG -Wno-error)
-  append_if(LIBCXXABI_CXX_WARNING_FLAGS LIBCXXABI_HAS_NO_WX_FLAG -WX-)
+  append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_WNO_ERROR_FLAG -Wno-error)
+  append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_NO_WX_FLAG -WX-)
 endif()
 if (LIBCXXABI_ENABLE_PEDANTIC)
-  append_if(LIBCXXABI_CXX_WARNING_FLAGS LIBCXXABI_HAS_PEDANTIC_FLAG -pedantic)
+  append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_PEDANTIC_FLAG -pedantic)
 endif()
 
 # Get feature flags.
 # Exceptions
 # Catches C++ exceptions only and tells the compiler to assume that extern C
 # functions never throw a C++ exception.
-append_if(LIBCXXABI_CXX_FEATURE_FLAGS LIBCXXABI_HAS_FSTRICT_ALIASING_FLAG -fstrict-aliasing)
-append_if(LIBCXXABI_CXX_FEATURE_FLAGS LIBCXXABI_HAS_EHSC_FLAG -EHsc)
+append_if(LIBCXXABI_CXX_FLAGS LIBCXXABI_HAS_FSTRICT_ALIASING_FLAG -fstrict-aliasing)
+append_if(LIBCXXABI_CXX_FLAGS LIBCXXABI_HAS_EHSC_FLAG -EHsc)
 
 # Assert
 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
 if (LIBCXXABI_ENABLE_ASSERTIONS)
   # MSVC doesn't like _DEBUG on release builds. See PR 4379.
   if (NOT MSVC)
-    list(APPEND LIBCXXABI_CXX_FEATURE_FLAGS -D_DEBUG)
+    list(APPEND LIBCXXABI_COMPILE_FLAGS -D_DEBUG)
   endif()
   # On Release builds cmake automatically defines NDEBUG, so we
   # explicitly undefine it:
   if (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
-    list(APPEND LIBCXXABI_CXX_FEATURE_FLAGS -UNDEBUG)
+    list(APPEND LIBCXXABI_COMPILE_FLAGS -UNDEBUG)
   endif()
 else()
   if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
-    list(APPEND LIBCXXABI_CXX_FEATURE_FLAGS -DNDEBUG)
+    list(APPEND LIBCXXABI_COMPILE_FLAGS -DNDEBUG)
   endif()
 endif()
 # Static library
 if (NOT LIBCXXABI_ENABLE_SHARED)
-  list(APPEND LIBCXXABI_CXX_FEATURE_FLAGS -D_LIBCPP_BUILD_STATIC)
+  list(APPEND LIBCXXABI_COMPILE_FLAGS -D_LIBCPP_BUILD_STATIC)
 endif()
 
 # This is the _ONLY_ place where add_definitions is called.
@@ -222,14 +231,10 @@ if (MSVC)
   add_definitions(-D_CRT_SECURE_NO_WARNINGS)
 endif()
 
-string(REPLACE ";" " " LIBCXXABI_CXX_REQUIRED_FLAGS "${LIBCXXABI_CXX_REQUIRED_FLAGS}")
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXXABI_CXX_REQUIRED_FLAGS}")
-
-string(REPLACE ";" " " LIBCXXABI_CXX_WARNING_FLAGS "${LIBCXXABI_CXX_WARNING_FLAGS}")
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXXABI_CXX_WARNING_FLAGS}")
+add_definitions(-D_LIBUNWIND_SUPPORT_DWARF_UNWIND=0)
 
-string(REPLACE ";" " " LIBCXXABI_CXX_FEATURE_FLAGS "${LIBCXXABI_CXX_FEATURE_FLAGS}")
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXXABI_CXX_FEATURE_FLAGS}")
+string(REPLACE ";" " " LIBCXXABI_CXX_FLAGS "${LIBCXXABI_CXX_FLAGS}")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXXABI_CXX_FLAGS}")
 
 #===============================================================================
 # Setup Source Code
index 774ef27..3367850 100644 (file)
@@ -58,31 +58,31 @@ endif()
 target_link_libraries(cxxabi ${libraries})
 
 # Setup flags.
-append_if(compile_flags LIBCXXABI_HAS_FPIC_FLAG -fPIC)
-append_if(link_flags LIBCXXABI_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs)
+append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_FPIC_FLAG -fPIC)
+append_if(LIBCXXABI_LINK_FLAGS LIBCXXABI_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs)
 
 if ( APPLE )
   if ( CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6" )
-    list(APPEND compile_flags "-U__STRICT_ANSI__")
-    list(APPEND link_flags
+    list(APPEND LIBCXXABI_COMPILE_FLAGS "-U__STRICT_ANSI__")
+    list(APPEND LIBCXXABI_LINK_FLAGS
       "-compatibility_version 1"
       "-current_version 1"
       "-install_name /usr/lib/libc++abi.1.dylib"
       "/usr/lib/libSystem.B.dylib")
   else()
-    list(APPEND link_flags
+    list(APPEND LIBCXXABI_LINK_FLAGS
       "-compatibility_version 1"
       "-install_name /usr/lib/libc++abi.1.dylib")
   endif()
 endif()
 
-string(REPLACE ";" " " compile_flags "${compile_flags}")
-string(REPLACE ";" " " link_flags "${link_flags}")
+string(REPLACE ";" " " LIBCXXABI_COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}")
+string(REPLACE ";" " " LIBCXXABI_LINK_FLAGS "${LIBCXXABI_LINK_FLAGS}")
 
 set_target_properties(cxxabi
   PROPERTIES
-    COMPILE_FLAGS "${compile_flags}"
-    LINK_FLAGS    "${link_flags}"
+    COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}"
+    LINK_FLAGS    "${LIBCXXABI_LINK_FLAGS}"
     OUTPUT_NAME   "c++abi"
     VERSION       "1.0"
     SOVERSION     "1"
index ff22e7f..598a081 100644 (file)
@@ -65,33 +65,33 @@ append_if(libraries LIBCXXABI_HAS_PTHREAD_LIB pthread)
 target_link_libraries(unwind ${libraries})
 
 # Setup flags.
-append_if(compile_flags LIBCXXABI_HAS_FPIC_FLAG -fPIC)
-append_if(link_flags LIBCXXABI_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs)
+append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_FPIC_FLAG -fPIC)
+append_if(LIBCXXABI_LINK_FLAGS LIBCXXABI_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs)
 
 set(LIBCXXABI_UNWINDER_NAME "unwind")
 
 if ( APPLE )
   if ( CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6" )
-    list(APPEND compile_flags "-U__STRICT_ANSI__")
-    list(APPEND link_flags
+    list(APPEND LIBCXXABI_COMPILE_FLAGS "-U__STRICT_ANSI__")
+    list(APPEND LIBCXXABI_LINK_FLAGS
       "-compatibility_version 1"
       "-current_version ${LIBCXXABI_VERSION}"
       "-install_name /usr/lib/lib${LIBCXXABI_UNWINDER_NAME}.1.dylib"
       "/usr/lib/libSystem.B.dylib")
   else()
-    list(APPEND link_flags
+    list(APPEND LIBCXXABI_LINK_FLAGS
       "-compatibility_version 1"
       "-install_name /usr/lib/lib${LIBCXXABI_UNWINDER_NAME}.1.dylib")
   endif()
 endif()
 
-string(REPLACE ";" " " compile_flags "${compile_flags}")
-string(REPLACE ";" " " link_flags "${link_flags}")
+string(REPLACE ";" " " LIBCXXABI_COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}")
+string(REPLACE ";" " " LIBCXXABI_LINK_FLAGS "${LIBCXXABI_LINK_FLAGS}")
 
 set_target_properties(unwind
   PROPERTIES
-    COMPILE_FLAGS "${compile_flags}"
-    LINK_FLAGS    "${link_flags}"
+    COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}"
+    LINK_FLAGS    "${LIBCXXABI_LINK_FLAGS}"
     OUTPUT_NAME   "${LIBCXXABI_UNWINDER_NAME}"
     VERSION       "1.0"
     SOVERSION     "1"