Skip to content

Remember LLVM_ENABLE_LIBCXX setting in installed configuration #139712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion llvm/cmake/modules/HandleLLVMStdlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# if the user has requested it.

include(DetermineGCCCompatible)
include(CheckIncludeFiles)

if(NOT DEFINED LLVM_STDLIB_HANDLED)
set(LLVM_STDLIB_HANDLED ON)
Expand All @@ -19,7 +20,17 @@ if(NOT DEFINED LLVM_STDLIB_HANDLED)
if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
check_cxx_compiler_flag("-stdlib=libc++" CXX_COMPILER_SUPPORTS_STDLIB)
check_linker_flag(CXX "-stdlib=libc++" CXX_LINKER_SUPPORTS_STDLIB)
if(CXX_COMPILER_SUPPORTS_STDLIB AND CXX_LINKER_SUPPORTS_STDLIB)

# Check whether C++ include files are available
# runtimes/CMakeLists.txt adds -nostdlib++ and -nostdinc++ to
# CMAKE_REQUIRED_FLAGS, which are incompatible with -stdlib=libc++; use
# a fresh CMAKE_REQUIRED_FLAGS environment.
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -stdlib=libc++")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this is processed in the runtimes cmake sub-command, CMAKE_REQUIRED_FLAGS contains -nostdinc++. You could fix this with:

string(REPLACE "-nostdinc++" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")

Which makes the PR work for me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saw your updated PR; I think we do need to still inherit CMAKE_REQUIRED_FLAGS, for cases where the path to the c++ lib is being added as a flag etc. We just need to specifically remove -nostdinc++.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, never mind, that's not how CMAKE_REQUIRED_FLAGS works :). It will still be populated with CMAKE_CXX_FLAGS here. I think what you have now is fine.

check_include_files("chrono" CXX_COMPILER_SUPPORTS_STDLIB_CHRONO LANGUAGE CXX)
cmake_pop_check_state()

if(CXX_COMPILER_SUPPORTS_STDLIB AND CXX_LINKER_SUPPORTS_STDLIB AND CXX_COMPILER_SUPPORTS_STDLIB_CHRONO)
append("-stdlib=libc++"
CMAKE_CXX_FLAGS CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS
CMAKE_MODULE_LINKER_FLAGS)
Expand Down
2 changes: 2 additions & 0 deletions llvm/cmake/modules/LLVMConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ endif()

set(LLVM_ENABLE_RTTI @LLVM_ENABLE_RTTI@)

set(LLVM_ENABLE_LIBCXX @LLVM_ENABLE_LIBCXX@)

set(LLVM_ENABLE_LIBEDIT @HAVE_LIBEDIT@)
if(LLVM_ENABLE_LIBEDIT)
find_package(LibEdit)
Expand Down