[PATCH] D12209: [libcxx] Remove installation rules on Darwin when it would overwrite the system installation.
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 20 13:22:52 PDT 2015
EricWF created this revision.
EricWF added reviewers: mclow.lists, beanz, jroelofs.
EricWF added a subscriber: cfe-commits.
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`.
http://reviews.llvm.org/D12209
Files:
CMakeLists.txt
cmake/Modules/HandleLibCXXABI.cmake
lib/CMakeLists.txt
Index: lib/CMakeLists.txt
===================================================================
--- lib/CMakeLists.txt
+++ lib/CMakeLists.txt
@@ -133,15 +133,18 @@
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()
Index: cmake/Modules/HandleLibCXXABI.cmake
===================================================================
--- cmake/Modules/HandleLibCXXABI.cmake
+++ cmake/Modules/HandleLibCXXABI.cmake
@@ -41,11 +41,13 @@
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()
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -55,6 +55,7 @@
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 ---------------------------------------------------------
@@ -94,6 +95,23 @@
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
#===============================================================================
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12209.32727.patch
Type: text/x-patch
Size: 4015 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150820/47d2b8be/attachment-0001.bin>
More information about the cfe-commits
mailing list