This is an archive of the discontinued LLVM Phabricator instance.

[CMake][libcxx] Use check_c_compiler_flag to check for nodefaultlibs
ClosedPublic

Authored by phosek on Apr 3 2017, 6:49 PM.

Details

Reviewers
EricWF
beanz
Summary

We're using -nodefaultlibs to avoid the dependency on C++ library when using check_cxx_compiler_flag, and as such we cannot use check_cxx_compiler_flag to check the availability of -nodefaultlibs itself, because check_cxx_compile_flags adds the flag to COMPILE_DEFINITIONS when calling try_compile and this variable is only considered for compilation but not for linking where -nodefaultlibs actually makes a difference.

Diff Detail

Repository
rL LLVM

Event Timeline

phosek created this revision.Apr 3 2017, 6:49 PM
EricWF edited edge metadata.Apr 3 2017, 6:57 PM

Why not? The executable should still link and run without requiring the C++ standard library, just as it links and runs without requiring the C standard library.

phosek added a comment.Apr 3 2017, 7:16 PM

The problem is that check_cxx_compile_flags adds the flag to COMPILE_DEFINITIONSwhen calling try_compile and that variable is only considered for compilation but not for linking where -nodefaultlibs actually makes a difference (I should probably add this into the description).

phosek edited the summary of this revision. (Show Details)Apr 3 2017, 7:32 PM
EricWF accepted this revision.Apr 3 2017, 7:34 PM

Is there any CMake documentation which documents this particular behavior?

Otherwise LGTM.

This revision is now accepted and ready to land.Apr 3 2017, 7:34 PM
phosek added a comment.Apr 3 2017, 7:45 PM

https://cmake.org/cmake/help/latest/module/CheckCXXCompilerFlag.html says that "This internally calls the check_cxx_source_compiles macro and sets CMAKE_REQUIRED_DEFINITIONS to <flag>" and https://github.com/Kitware/CMake/blob/master/Modules/CheckCXXSourceCompiles.cmake#L67 shows that this is being passed to try_compile as COMPILE_DEFINITIONS, this is the best I could find.

phosek closed this revision.Apr 7 2017, 12:24 PM