Skip to content

[runtimes] Append -nostd*++ flags only if necessary #151930

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 1 commit into
base: main
Choose a base branch
from
Open
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
26 changes: 19 additions & 7 deletions runtimes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,25 @@ endif()
# Check for -nostdlib++ first; if there's no C++ standard library yet,
# all check_cxx_compiler_flag commands will fail until we add -nostdlib++
# (or -nodefaultlibs).
llvm_check_compiler_linker_flag(CXX "-nostdlib++" CXX_SUPPORTS_NOSTDLIBXX_FLAG)
if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
endif()
check_cxx_compiler_flag(-nostdinc++ CXX_SUPPORTS_NOSTDINCXX_FLAG)
if (CXX_SUPPORTS_NOSTDINCXX_FLAG)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdinc++")

# TODO: this is incorrect, as these variables are passed to the C compiler.
# Until a proper solution is found, append them only if necessary to avoid
# some of the resulting breakage.
# See https://github.com/llvm/llvm-project/issues/90332
check_cxx_source_compiles("int main() {return 0;}" CXX_LINKS_WITHOUT_NOSTD)
if (NOT CXX_LINKS_WITHOUT_NOSTD)
llvm_check_compiler_linker_flag(CXX "-nostdlib++" CXX_SUPPORTS_NOSTDLIBXX_FLAG)
if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
endif()
check_cxx_compiler_flag(-nostdinc++ CXX_SUPPORTS_NOSTDINCXX_FLAG)
if (CXX_SUPPORTS_NOSTDINCXX_FLAG)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdinc++")
endif()
check_cxx_source_compiles("int main() {return 0;}" CXX_LINKS_WITH_NOSTD)
if (NOT CXX_LINKS_WITH_NOSTD)
message(FATAL_ERROR "C++ compiler fails to link C++ programs, check CMake logs")
endif()
endif()

# Avoid checking whether the compiler is working.
Expand Down
Loading