[clang] f8990fe - [libclang] Install both libclang.a and libclang.so when LIBCLANG_BUILD_STATIC=ON
Shoaib Meenai via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 27 13:38:14 PDT 2020
Author: Han Zhu
Date: 2020-04-27T13:37:07-07:00
New Revision: f8990feb125a0f8d3f2892a589bc6fad3c430858
URL: https://github.com/llvm/llvm-project/commit/f8990feb125a0f8d3f2892a589bc6fad3c430858
DIFF: https://github.com/llvm/llvm-project/commit/f8990feb125a0f8d3f2892a589bc6fad3c430858.diff
LOG: [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
Added:
Modified:
clang/cmake/modules/AddClang.cmake
Removed:
################################################################################
diff --git a/clang/cmake/modules/AddClang.cmake b/clang/cmake/modules/AddClang.cmake
index c1bb386de6f7..d68218eed073 100644
--- a/clang/cmake/modules/AddClang.cmake
+++ b/clang/cmake/modules/AddClang.cmake
@@ -99,38 +99,40 @@ macro(add_clang_library name)
endif()
llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
- if(TARGET ${name})
- target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})
-
- if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ARG_INSTALL_WITH_TOOLCHAIN)
- set(export_to_clangtargets)
- if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
- "clang-libraries" IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
- NOT LLVM_DISTRIBUTION_COMPONENTS)
- set(export_to_clangtargets EXPORT ClangTargets)
- set_property(GLOBAL PROPERTY CLANG_HAS_EXPORTS True)
+ foreach(lib ${name} ${name}_static)
+ if(TARGET ${lib})
+ target_link_libraries(${lib} INTERFACE ${LLVM_COMMON_LIBS})
+
+ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ARG_INSTALL_WITH_TOOLCHAIN)
+ set(export_to_clangtargets)
+ if(${lib} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
+ "clang-libraries" IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
+ NOT LLVM_DISTRIBUTION_COMPONENTS)
+ set(export_to_clangtargets EXPORT ClangTargets)
+ set_property(GLOBAL PROPERTY CLANG_HAS_EXPORTS True)
+ endif()
+
+ install(TARGETS ${lib}
+ COMPONENT ${lib}
+ ${export_to_clangtargets}
+ LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
+ ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
+ RUNTIME DESTINATION bin)
+
+ if (NOT LLVM_ENABLE_IDE)
+ add_llvm_install_targets(install-${lib}
+ DEPENDS ${lib}
+ COMPONENT ${lib})
+ endif()
+
+ set_property(GLOBAL APPEND PROPERTY CLANG_LIBS ${lib})
endif()
-
- install(TARGETS ${name}
- COMPONENT ${name}
- ${export_to_clangtargets}
- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
- RUNTIME DESTINATION bin)
-
- if (NOT LLVM_ENABLE_IDE)
- add_llvm_install_targets(install-${name}
- DEPENDS ${name}
- COMPONENT ${name})
- endif()
-
- set_property(GLOBAL APPEND PROPERTY CLANG_LIBS ${name})
+ set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${lib})
+ else()
+ # Add empty "phony" target
+ add_custom_target(${lib})
endif()
- set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${name})
- else()
- # Add empty "phony" target
- add_custom_target(${name})
- endif()
+ endforeach()
set_target_properties(${name} PROPERTIES FOLDER "Clang libraries")
set_clang_windows_version_resource_properties(${name})
More information about the cfe-commits
mailing list