[libcxx] r246070 - [libcxx] Remove installation rules on Darwin when it would overwrite the system installation.

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 26 13:18:21 PDT 2015


Author: ericwf
Date: Wed Aug 26 15:18:21 2015
New Revision: 246070

URL: http://llvm.org/viewvc/llvm-project?rev=246070&view=rev
Log:
[libcxx] Remove installation rules on Darwin when it would overwrite the system installation.

Summary:
On Mac OS X overwriting `/usr/lib/libc++.dylib` can cause your computer to fail to boot. This patch tries to make it harder to do that accidentally. 

If `CMAKE_SYSTEM_NAME` is `Darwin` and `CMAKE_INSTALL_PREFIX` is `/usr` don't generate installation rules unless the user explicitly provides `LIBCXX_OVERRIDE_DARWIN_INSTALL=ON`. Note that `CMAKE_INSTALL_PREFIX` is always absolute so we don't need to worry about things like `/usr/../usr`.

Reviewers: mclow.lists, beanz, jroelofs

Subscribers: cfe-commits

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

Modified:
    libcxx/trunk/CMakeLists.txt
    libcxx/trunk/cmake/Modules/HandleLibCXXABI.cmake
    libcxx/trunk/lib/CMakeLists.txt

Modified: libcxx/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/CMakeLists.txt?rev=246070&r1=246069&r2=246070&view=diff
==============================================================================
--- libcxx/trunk/CMakeLists.txt (original)
+++ libcxx/trunk/CMakeLists.txt Wed Aug 26 15:18:21 2015
@@ -56,6 +56,7 @@ option(LIBCXX_INCLUDE_DOCS "Build the li
 set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
     "Define suffix of library directory name (32/64)")
 option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON)
+option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON)
 option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON)
 
 # ABI Library options ---------------------------------------------------------
@@ -95,6 +96,23 @@ option(LIBCXX_GENERATE_COVERAGE "Enable
 set(LIBCXX_COVERAGE_LIBRARY "" CACHE STRING
     "The Profile-rt library used to build with code coverage")
 
+# Don't allow a user to accidentally overwrite the system libc++ installation on Darwin.
+# If the user specifies -DCMAKE_INSTALL_PREFIX=/usr the install rules for libc++
+# will not be generated and a warning will be issued.
+option(LIBCXX_OVERRIDE_DARWIN_INSTALL "Enable overwriting darwins libc++ installation." OFF)
+mark_as_advanced(LIBCXX_OVERRIDE_DARWIN_INSTALL) # Don't show this option by default.
+
+if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT LIBCXX_OVERRIDE_DARWIN_INSTALL)
+  if ("${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr")
+    message(WARNING "Disabling libc++ install rules because installation would "
+                    "overwrite the systems installation. Configure with "
+                    "-DLIBCXX_OVERRIDE_DARWIN_INSTALL=ON to suppress this behaviour.")
+    mark_as_advanced(CLEAR LIBCXX_OVERRIDE_DARWIN_INSTALL) # Show the override option.
+    set(LIBCXX_INSTALL_HEADERS OFF)
+    set(LIBCXX_INSTALL_LIBRARY OFF)
+  endif()
+endif()
+
 #===============================================================================
 # Check option configurations
 #===============================================================================

Modified: libcxx/trunk/cmake/Modules/HandleLibCXXABI.cmake
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/cmake/Modules/HandleLibCXXABI.cmake?rev=246070&r1=246069&r2=246070&view=diff
==============================================================================
--- libcxx/trunk/cmake/Modules/HandleLibCXXABI.cmake (original)
+++ libcxx/trunk/cmake/Modules/HandleLibCXXABI.cmake Wed Aug 26 15:18:21 2015
@@ -41,11 +41,13 @@ macro(setup_abi_lib abidefines abilib ab
         file(COPY "${incpath}/${fpath}"
           DESTINATION "${CMAKE_BINARY_DIR}/include/${dstdir}"
           )
-        install(FILES "${CMAKE_BINARY_DIR}/include/${fpath}"
-          DESTINATION include/c++/v1/${dstdir}
-          COMPONENT libcxx
-          PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
-          )
+        if (LIBCXX_INSTALL_HEADERS)
+          install(FILES "${CMAKE_BINARY_DIR}/include/${fpath}"
+            DESTINATION include/c++/v1/${dstdir}
+            COMPONENT libcxx
+            PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
+            )
+        endif()
         list(APPEND abilib_headers "${CMAKE_BINARY_DIR}/include/${fpath}")
       endif()
     endforeach()

Modified: libcxx/trunk/lib/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/lib/CMakeLists.txt?rev=246070&r1=246069&r2=246070&view=diff
==============================================================================
--- libcxx/trunk/lib/CMakeLists.txt (original)
+++ libcxx/trunk/lib/CMakeLists.txt Wed Aug 26 15:18:21 2015
@@ -133,15 +133,18 @@ set_target_properties(cxx
     SOVERSION     "1"
   )
 
-install(TARGETS cxx
-  LIBRARY DESTINATION lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT libcxx
-  ARCHIVE DESTINATION lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT libcxx
-  )
+if (LIBCXX_INSTALL_LIBRARY)
+  install(TARGETS cxx
+    LIBRARY DESTINATION lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT libcxx
+    ARCHIVE DESTINATION lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT libcxx
+    )
+endif()
 
-if (NOT CMAKE_CONFIGURATION_TYPES)
-  add_custom_target(install-libcxx
-                    DEPENDS cxx
-                    COMMAND "${CMAKE_COMMAND}"
-                    -DCMAKE_INSTALL_COMPONENT=libcxx
-                    -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
+if (NOT CMAKE_CONFIGURATION_TYPES AND (LIBCXX_INSTALL_LIBRARY OR
+                                       LIBCXX_INSTALL_HEADERS))
+    add_custom_target(install-libcxx
+                      DEPENDS cxx
+                      COMMAND "${CMAKE_COMMAND}"
+                      -DCMAKE_INSTALL_COMPONENT=libcxx
+                      -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
 endif()




More information about the cfe-commits mailing list