Skip to content

Commit

Permalink
[libcxx] Remove installation rules on Darwin when it would overwrite …
Browse files Browse the repository at this point in the history
…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

llvm-svn: 246070
  • Loading branch information
EricWF committed Aug 26, 2015
1 parent 4b30e56 commit d77135f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
18 changes: 18 additions & 0 deletions libcxx/CMakeLists.txt
Expand Up @@ -56,6 +56,7 @@ option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS
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 ---------------------------------------------------------
Expand Down Expand Up @@ -95,6 +96,23 @@ option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF)
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
#===============================================================================
Expand Down
12 changes: 7 additions & 5 deletions libcxx/cmake/Modules/HandleLibCXXABI.cmake
Expand Up @@ -41,11 +41,13 @@ macro(setup_abi_lib abidefines abilib abifiles abidirs)
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()
Expand Down
23 changes: 13 additions & 10 deletions libcxx/lib/CMakeLists.txt
Expand Up @@ -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()

0 comments on commit d77135f

Please sign in to comment.