aaronpuchert updated this revision to Diff 222302. aaronpuchert marked 4 inline comments as done. aaronpuchert added a comment.
Handle static libraries correctly. Dependencies of executables are obviously always PRIVATE, but for library targets we have to turn PRIVATE or PUBLIC dependencies into INTERFACE dependencies. This is basically also what add_llvm_library's LINK_LIBS does. I tested this by configuring a couple of build profiles and inspecting build.ninja. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D67321/new/ https://reviews.llvm.org/D67321 Files: clang/cmake/modules/AddClang.cmake clang/tools/c-index-test/CMakeLists.txt clang/tools/libclang/CMakeLists.txt Index: clang/tools/libclang/CMakeLists.txt =================================================================== --- clang/tools/libclang/CMakeLists.txt +++ clang/tools/libclang/CMakeLists.txt @@ -34,7 +34,7 @@ ../../include/clang-c/Index.h ) -set(LIBS +set(CLANG_LIB_DEPS clangAST clangBasic clangDriver @@ -44,11 +44,10 @@ clangSema clangSerialization clangTooling - LLVMSupport ) if (CLANG_ENABLE_ARCMT) - list(APPEND LIBS clangARCMigrate) + list(APPEND CLANG_LIB_DEPS clangARCMigrate) endif () if (TARGET clangTidyPlugin) @@ -113,6 +112,11 @@ Support ) +clang_target_link_libraries(libclang + PRIVATE + ${CLANG_LIB_DEPS} + ) + if(ENABLE_SHARED) if(WIN32) set_target_properties(libclang Index: clang/tools/c-index-test/CMakeLists.txt =================================================================== --- clang/tools/c-index-test/CMakeLists.txt +++ clang/tools/c-index-test/CMakeLists.txt @@ -25,6 +25,9 @@ target_link_libraries(c-index-test PRIVATE libclang + ) + clang_target_link_libraries(c-index-test + PRIVATE clangAST clangBasic clangCodeGen Index: clang/cmake/modules/AddClang.cmake =================================================================== --- clang/cmake/modules/AddClang.cmake +++ clang/cmake/modules/AddClang.cmake @@ -173,11 +173,25 @@ llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) endmacro() +# Link with a Clang component library, or clang-cpp if CLANG_LINK_CLANG_DYLIB +# is set. If target is a static library, PUBLIC and PRIVATE dependencies are +# treated as INTERFACE dependencies, so this can replace LINK_LIBS. function(clang_target_link_libraries target type) + get_target_property(TARGET_TYPE ${target} TYPE) + if(${TARGET_TYPE} EQUAL "STATIC_LIBRARY") + set(type INTERFACE) + endif() if (CLANG_LINK_CLANG_DYLIB) target_link_libraries(${target} ${type} clang-cpp) else() target_link_libraries(${target} ${type} ${ARGN}) endif() + if (TARGET "${target}_static") + if (CLANG_LINK_CLANG_DYLIB) + target_link_libraries(${target} INTERFACE clang-cpp) + else() + target_link_libraries(${target} INTERFACE ${ARGN}) + endif() + endif() endfunction()
Index: clang/tools/libclang/CMakeLists.txt =================================================================== --- clang/tools/libclang/CMakeLists.txt +++ clang/tools/libclang/CMakeLists.txt @@ -34,7 +34,7 @@ ../../include/clang-c/Index.h ) -set(LIBS +set(CLANG_LIB_DEPS clangAST clangBasic clangDriver @@ -44,11 +44,10 @@ clangSema clangSerialization clangTooling - LLVMSupport ) if (CLANG_ENABLE_ARCMT) - list(APPEND LIBS clangARCMigrate) + list(APPEND CLANG_LIB_DEPS clangARCMigrate) endif () if (TARGET clangTidyPlugin) @@ -113,6 +112,11 @@ Support ) +clang_target_link_libraries(libclang + PRIVATE + ${CLANG_LIB_DEPS} + ) + if(ENABLE_SHARED) if(WIN32) set_target_properties(libclang Index: clang/tools/c-index-test/CMakeLists.txt =================================================================== --- clang/tools/c-index-test/CMakeLists.txt +++ clang/tools/c-index-test/CMakeLists.txt @@ -25,6 +25,9 @@ target_link_libraries(c-index-test PRIVATE libclang + ) + clang_target_link_libraries(c-index-test + PRIVATE clangAST clangBasic clangCodeGen Index: clang/cmake/modules/AddClang.cmake =================================================================== --- clang/cmake/modules/AddClang.cmake +++ clang/cmake/modules/AddClang.cmake @@ -173,11 +173,25 @@ llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) endmacro() +# Link with a Clang component library, or clang-cpp if CLANG_LINK_CLANG_DYLIB +# is set. If target is a static library, PUBLIC and PRIVATE dependencies are +# treated as INTERFACE dependencies, so this can replace LINK_LIBS. function(clang_target_link_libraries target type) + get_target_property(TARGET_TYPE ${target} TYPE) + if(${TARGET_TYPE} EQUAL "STATIC_LIBRARY") + set(type INTERFACE) + endif() if (CLANG_LINK_CLANG_DYLIB) target_link_libraries(${target} ${type} clang-cpp) else() target_link_libraries(${target} ${type} ${ARGN}) endif() + if (TARGET "${target}_static") + if (CLANG_LINK_CLANG_DYLIB) + target_link_libraries(${target} INTERFACE clang-cpp) + else() + target_link_libraries(${target} INTERFACE ${ARGN}) + endif() + endif() endfunction()
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits