Broken CMake EXPORT set with external LLVM
- [x] Checked for duplicates
Describe the bug
When trying to build with --builtin_llvm=OFF --builtin_clang=OFF --builtin_cling=ON, CMake reports an error
[ 52s] -- Enabled support for: builtin_cling builtin_openui5 dataframe davix exceptions fftw3 gdml gnuinstall http imt mathmore mlp minuit2 mysql opengl pgsql roofit rpath runtime_cxxmodules shared soversion sqlite ssl tmva tmva-cpu spectrum x11 xml xrootd
[ 52s] -- Configuring done
[ 53s] CMake Error: install(EXPORT "ROOTExports" ...) includes target "Cling" which requires target "clingInterpreter" that is not in any export set.
[ 53s] CMake Error: install(EXPORT "ROOTExports" ...) includes target "Cling" which requires target "clingMetaProcessor" that is not in any export set.
[ 53s] CMake Error: install(EXPORT "ROOTExports" ...) includes target "Cling" which requires target "clingUtils" that is not in any export set.
[ 54s] -- Generating done
Expected behavior
CMake call succeeds
To Reproduce
The problem is caused by the SHARED libCling (TARGET Cling) specyfing the 3 OBJECT libraries from above as PUBLIC link libraries:
https://github.com/root-project/root/blob/69002fa23d19ad50ff8dd6c7678a6343748ba3fd/core/metacling/src/CMakeLists.txt#L107-L112
https://github.com/root-project/root/blob/69002fa23d19ad50ff8dd6c7678a6343748ba3fd/cmake/modules/RootMacros.cmake#L889
CLING_LIBRARIES is clingInterpreter;clingMetaProcessor;clingUtils.
OBJECT libraries which are just used as convenience libraries and are not installed should by specified as PRIVATE link libraries.
A minimal reproducer is given below, with PRIVATE it works fine, with PUBLIC cmake -B _builddir -S . fails.
project(exportTest)
cmake_minimum_required(VERSION 3.1)
add_library(objLib OBJECT)
target_sources(objLib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/objA.cxx)
add_library(shLib SHARED)
target_sources(shLib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/libA.cxx)
target_link_libraries(shLib PUBLIC objLib) # <-- fails
#target_link_libraries(shLib PRIVATE objLib) # <-- OK
add_executable(main)
target_sources(main PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/main.cxx)
target_link_libraries(main PUBLIC shLib)
install(TARGETS main shLib EXPORT exportTest)
install(EXPORT exportTest DESTINATION lib/exportTest)
(libA.cxx and objA.cxx are empty files. main.cxx just contains an empty main function: int main(int, char**) { return 0;})
Setup
- ROOT version: 6.26.06
- openSUSE Leap 15.4, SLE15SP4