This is an archive of the discontinued LLVM Phabricator instance.

[CMake] Use generator expression to get in-tree libc++ path
ClosedPublic

Authored by phosek on Jan 25 2022, 3:36 PM.

Details

Summary

When using the in-tree libc++, we should be using the full path to
ensure that we're using the right library and not accidentally pick up
the system library.

Diff Detail

Event Timeline

phosek created this revision.Jan 25 2022, 3:36 PM
phosek requested review of this revision.Jan 25 2022, 3:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 25 2022, 3:36 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
phosek updated this revision to Diff 403065.Jan 25 2022, 4:12 PM
phosek retitled this revision from [CMake][memprof] Use generator expression to get in-tree libc++ path to [CMake] Use generator expression to get in-tree libc++ path.
abrachet accepted this revision.Jan 26 2022, 9:00 AM
abrachet added inline comments.
compiler-rt/CMakeLists.txt
540

Can $<BOOL:$<TARGET_NAME_IF_EXISTS:${cxx_target}>> ever evaluate false here?

compiler-rt/lib/memprof/tests/CMakeLists.txt
39–40

Stylistically should this instead append to MEMPROF_UNITTEST_LINK_FLAGS? Everywhere else you have added SANITIZER_TEST_CXX_LIBRARIES to their respective *LINK_FLAGS.

This revision is now accepted and ready to land.Jan 26 2022, 9:00 AM

I don't know compiler-rt much, but this looks reasonable.

phosek added inline comments.Jan 26 2022, 10:09 AM
compiler-rt/CMakeLists.txt
540

If the target doesn't exist, $<TARGET_NAME_IF_EXISTS:${cxx_target}> will evaluate to empty string and $<BOOL:$<TARGET_NAME_IF_EXISTS:${cxx_target}>> should evaluate that to false.

compiler-rt/lib/memprof/tests/CMakeLists.txt
39–40

Good question, I think that target_link_libraries is the correct solution because it handles other aspects like visibility (e.g. PRIVATE, PUBLIC). The reason we only use it here is because this is the only test that uses add_executable, all other tests use the generate_compiler_rt_tests function which internally uses add_compiler_rt_test which handles the compilation and linking manually via add_custom_command (this is so that it can use a custom compiler rather than CMAKE_{C,CXX}_COMPILER), see https://github.com/llvm/llvm-project/blob/db0631096e59c71b6f6b034306327b42d9184184/compiler-rt/cmake/Modules/AddCompilerRT.cmake#L497.

What I'm considering as a follow up is to (1) change MemProfUnitTests to also use generate_compiler_rt_tests for consistency with other tests and (2) change add_compiler_rt_test to use add_executable and other common CMake infrastructure.

This revision was landed with ongoing or failed builds.Jan 26 2022, 2:12 PM
This revision was automatically updated to reflect the committed changes.
tambre added a subscriber: tambre.Jan 27 2022, 12:34 AM
tambre added inline comments.
compiler-rt/CMakeLists.txt
542–545

Why the explicit -l? Per the documentation it's considered as a linker flag while without as a plain library name (unless a target or a full path). I'd wager we mean the latter, so would be nice to use that.

phosek added inline comments.Jan 28 2022, 12:14 AM
compiler-rt/CMakeLists.txt
542–545

generate_compiler_rt_tests doesn't use target_link_libraries, it directly invokes the compiler which wouldn't handle plain library name unless it's a full path.