This is an archive of the discontinued LLVM Phabricator instance.

[runtimes] Build static libraries in try_compile
AbandonedPublic

Authored by ldionne on Jul 23 2020, 9:21 AM.

Details

Reviewers
smeenai
phosek
Group Reviewers
Restricted Project
Restricted Project
Summary

Trying to build executables in try_compile leads to issues because we
might not be able to link executables for the target we're trying to
build the runtimes for. For example, when trying to build libc++ as a
static archive for some embedded targets, it might not make sense to
try and link a conventional executable for that target inside try_compile.

Diff Detail

Event Timeline

ldionne created this revision.Jul 23 2020, 9:21 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 23 2020, 9:21 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
Herald added a reviewer: Restricted Project. · View Herald Transcript

For many tests, it makes sense to just do the static library test - that is if they are limited to something that is compile time only. For link time tests, this doesn't work (e.g. testing if librt is needed). Perhaps we should make this conditional on NOT BUILD_SHARED_LIBS? This would be the default behaviour with LLVM, but still would let you opt out were you to build a shared library.

ldionne abandoned this revision.Oct 5 2021, 11:33 AM

For many tests, it makes sense to just do the static library test - that is if they are limited to something that is compile time only. For link time tests, this doesn't work (e.g. testing if librt is needed). Perhaps we should make this conditional on NOT BUILD_SHARED_LIBS? This would be the default behaviour with LLVM, but still would let you opt out were you to build a shared library.

FYI I've been looking into this recently and the direction I'm thinking about is providing custom functions for checking flags, for example runtime_check_c_compiler_flag, runtime_check_cxx_compiler_flag and runtime_check_linker_compiler_flag, where only the first two would set CMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY but the last one would need a different solution like using -nostarfiles -nodefaultlibs together with a custom source file.