Skip to content

Commit f8990fe

Browse files
zhuhan0smeenai
authored andcommitted
[libclang] Install both libclang.a and libclang.so when LIBCLANG_BUILD_STATIC=ON
When LIBCLANG_BUILD_STATIC=ON and LLVM_ENABLE_PIC=ON, PIC version of libclang.a and libclang.so are built as expected. However libclang.a is not installed. Looking at the macro llvm_add_library(), when both SHARED and STATIC are set, it renames the static library to ${name}_static and then adds it to targets. But when add_clang_library() calls install, it only checks if ${name} is in targets. To work around this issue, loop through both ${name} and ${name}_static and install both of them if they're in targets. This is still correct if only shared or static library is built. In those cases, only ${name} is added to targets and cmake install will generate the right install script depending on the library's type. Test Plan: cmake with LIBCLANG_BUILD_STATIC=ON and then ninja install, from master and this diff. Compare the result directory trees. Confirm that only difference is the added libclang.a. Differential Revision: https://reviews.llvm.org/D78534
1 parent 9598778 commit f8990fe

File tree

1 file changed

+32
-30
lines changed

1 file changed

+32
-30
lines changed

clang/cmake/modules/AddClang.cmake

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -99,38 +99,40 @@ macro(add_clang_library name)
9999
endif()
100100
llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
101101

102-
if(TARGET ${name})
103-
target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})
104-
105-
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ARG_INSTALL_WITH_TOOLCHAIN)
106-
set(export_to_clangtargets)
107-
if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
108-
"clang-libraries" IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
109-
NOT LLVM_DISTRIBUTION_COMPONENTS)
110-
set(export_to_clangtargets EXPORT ClangTargets)
111-
set_property(GLOBAL PROPERTY CLANG_HAS_EXPORTS True)
102+
foreach(lib ${name} ${name}_static)
103+
if(TARGET ${lib})
104+
target_link_libraries(${lib} INTERFACE ${LLVM_COMMON_LIBS})
105+
106+
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ARG_INSTALL_WITH_TOOLCHAIN)
107+
set(export_to_clangtargets)
108+
if(${lib} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
109+
"clang-libraries" IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
110+
NOT LLVM_DISTRIBUTION_COMPONENTS)
111+
set(export_to_clangtargets EXPORT ClangTargets)
112+
set_property(GLOBAL PROPERTY CLANG_HAS_EXPORTS True)
113+
endif()
114+
115+
install(TARGETS ${lib}
116+
COMPONENT ${lib}
117+
${export_to_clangtargets}
118+
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
119+
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
120+
RUNTIME DESTINATION bin)
121+
122+
if (NOT LLVM_ENABLE_IDE)
123+
add_llvm_install_targets(install-${lib}
124+
DEPENDS ${lib}
125+
COMPONENT ${lib})
126+
endif()
127+
128+
set_property(GLOBAL APPEND PROPERTY CLANG_LIBS ${lib})
112129
endif()
113-
114-
install(TARGETS ${name}
115-
COMPONENT ${name}
116-
${export_to_clangtargets}
117-
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
118-
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
119-
RUNTIME DESTINATION bin)
120-
121-
if (NOT LLVM_ENABLE_IDE)
122-
add_llvm_install_targets(install-${name}
123-
DEPENDS ${name}
124-
COMPONENT ${name})
125-
endif()
126-
127-
set_property(GLOBAL APPEND PROPERTY CLANG_LIBS ${name})
130+
set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${lib})
131+
else()
132+
# Add empty "phony" target
133+
add_custom_target(${lib})
128134
endif()
129-
set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${name})
130-
else()
131-
# Add empty "phony" target
132-
add_custom_target(${name})
133-
endif()
135+
endforeach()
134136

135137
set_target_properties(${name} PROPERTIES FOLDER "Clang libraries")
136138
set_clang_windows_version_resource_properties(${name})

0 commit comments

Comments
 (0)