This is an archive of the discontinued LLVM Phabricator instance.

CMake: Split static library exports into their own export file
AbandonedPublic

Authored by tstellar on Apr 28 2017, 7:18 PM.

Details

Summary

This is to better support distros which split the static libraries into
their own package.

The current problem is that any project the includes LLVMConfig.cmake
will fail to configure unless the static libraries are installed. This
is because LLVMConfig.cmake includes LLVMExports.cmake, which throws an
error if it can't find files linked to one of the exported targets.

This patch resolves the problem by putting the static library targets
into their own export file, LLVMStaticExports.cmake. This file
is optionally included by LLVMConfig.cmake, so distros can put this
new file in their static library package to make LLVMConfig.cmake
no longer depend on these libraries when they are not installed.

Event Timeline

tstellar created this revision.Apr 28 2017, 7:18 PM
chapuni edited edge metadata.May 1 2017, 5:46 AM

I wonder what is the case that LLVMConfig.cmake is provided but libLLVM*.a(s) are not provided.
I suppose LLVMConfig.cmake endorses libs.

Or, do you want to let LLVMConfig.cmake use a few SHARED and MODULE ?
Then, is LLVMStaticExports.cmake included in the same package as static libs?

I suggest exported targets may be categorized as like "essentials" "optional libs" "optional llvm tools", etc.

include(OPTIONAL) is good idea.

I wonder what is the case that LLVMConfig.cmake is provided but libLLVM*.a(s) are not provided.
I suppose LLVMConfig.cmake endorses libs.

Or, do you want to let LLVMConfig.cmake use a few SHARED and MODULE ?
Then, is LLVMStaticExports.cmake included in the same package as static libs?

Yes, LLVMStaticExports.cmake would be included in the static lib package.

I suggest exported targets may be categorized as like "essentials" "optional libs" "optional llvm tools", etc.

include(OPTIONAL) is good idea.

I see. I still wonder who uses find_package(LLVM) without libs, though. Let me know the case.

cmake/modules/AddLLVM.cmake
591

It isn't enabled in BUILD_SHARED_LIBS.

Then lib*.so(s) are included in LLVMStaticExports.cmake. Is it intended?
I guess it wouldn't affect to most developers, though.

beanz edited edge metadata.May 31 2017, 11:19 AM

I want to echo @chapuni's question. What is the use case where a distribution would install the CMake modules and not install the LLVM component libraries? It doesn't seem to me that there is any reason to install the CMake modules to support find_package without also installing the static archives.

I want to echo @chapuni's question. What is the use case where a distribution would install the CMake modules and not install the LLVM component libraries? It doesn't seem to me that there is any reason to install the CMake modules to support find_package without also installing the static archives.

On Fedora, at least, packaging static libraries is discouraged, and applications usually link against libLLVM.so. Tthe static libraries are split into their own package separate from the shared object. Even with only libLLVM.so installed, find_package(LLVM) is still useful for getting the library / header paths for the LLVM installs. Currently, even if you don't link against static libraries, you still need to install them in order for find_package(LLVM) to work, which is a little confusing for users.

beanz accepted this revision.May 31 2017, 3:20 PM

Ah. Makes sense. Can we maybe change the name from "StaticExports" to "ComponentExports"? As @chapuni pointed out this really applies to the component libraries, which can be static or shared based on configuration (although I keep hoping nobody would ever use BUILD_SHARED_LIBS in a distribution). Otherwise, I think this patch is good.

This revision is now accepted and ready to land.May 31 2017, 3:20 PM
tstellar abandoned this revision.May 27 2020, 2:16 PM

Decided to carry this as a distro specific patch. I don't want to complicate the build system with something that would only have limited use.