[clang] 0c9230d - Reland [libclang] Install both libclang.a and libclang.so when LIBCLANG_BUILD_STATIC=ON
Shoaib Meenai via cfe-commits
cfe-commits at lists.llvm.org
Wed May 6 19:34:23 PDT 2020
Author: Han Zhu
Date: 2020-05-06T19:33:58-07:00
New Revision: 0c9230dad1692bc3d8f1ce2dddae413a115f2532
URL: https://github.com/llvm/llvm-project/commit/0c9230dad1692bc3d8f1ce2dddae413a115f2532
DIFF: https://github.com/llvm/llvm-project/commit/0c9230dad1692bc3d8f1ce2dddae413a115f2532.diff
LOG: Reland [libclang] Install both libclang.a and libclang.so when LIBCLANG_BUILD_STATIC=ON
f8990feb125a enabled installing PIC version of both libclang.a and
libclang.so when LIBCLANG_BUILD_STATIC is ON. But it broke the no-PIC
build when LLVM_ENABLE_PIC=OFF with the following error:
```
CMake Error at
/b/s/w/ir/cache/builder/src/third_party/llvm/clang/tools/libclang/CMakeLists.txt:123
(target_compile_definitions):
target_compile_definitions called with non-compilable target type
```
This is because as the code loops through ${name} and ${name}_static, it
introduced a side effect, which is adding an empty libclang_static to
targets. Later target_compile_definitions is called on libclang_static.
That function requires that target must have been created by a command
such as add_executable() or add_library(), so it crashed.
The solution is to not naively loop through both libclang and
libclang_static, but only the ones that are actually added by
llvm_add_library(). Here's the library build type to library target name
mapping:
| SHARED only | libclang |
| STATIC only | libclang |
| SHARED and STATIC | libclang and libclang_static |
So only when SHARED and STATIC are both set should we loop through two
targets. Explicitly parse the STATIC argument and set the list
accordingly.
Reviewed By: smeenai
Differential Revision: https://reviews.llvm.org/D79059
Added:
Modified:
clang/cmake/modules/AddClang.cmake
Removed:
################################################################################
diff --git a/clang/cmake/modules/AddClang.cmake b/clang/cmake/modules/AddClang.cmake
index c1bb386de6f7..704278a0e93b 100644
--- a/clang/cmake/modules/AddClang.cmake
+++ b/clang/cmake/modules/AddClang.cmake
@@ -45,7 +45,7 @@ endmacro()
macro(add_clang_library name)
cmake_parse_arguments(ARG
- "SHARED;INSTALL_WITH_TOOLCHAIN"
+ "SHARED;STATIC;INSTALL_WITH_TOOLCHAIN"
""
"ADDITIONAL_HEADERS"
${ARGN})
@@ -81,7 +81,10 @@ macro(add_clang_library name)
${ARG_ADDITIONAL_HEADERS} # It may contain unparsed unknown args.
)
endif()
- if(ARG_SHARED)
+
+ if(ARG_SHARED AND ARG_STATIC)
+ set(LIBTYPE SHARED STATIC)
+ elseif(ARG_SHARED)
set(LIBTYPE SHARED)
else()
# llvm_add_library ignores BUILD_SHARED_LIBS if STATIC is explicitly set,
@@ -99,38 +102,45 @@ 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)
- endif()
+ set(libs ${name})
+ if(ARG_SHARED AND ARG_STATIC)
+ list(APPEND libs ${name}_static)
+ 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})
+ foreach(lib ${libs})
+ 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()
-
- 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