diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt --- a/clang/CMakeLists.txt +++ b/clang/CMakeLists.txt @@ -447,6 +447,9 @@ option(CLANG_ENABLE_ARCMT "Build ARCMT." ON) option(CLANG_ENABLE_STATIC_ANALYZER "Build static analyzer." ON) +option(CLANG_ENABLE_SHARED_LIBRARIES "Build libclang* as shared libraries." ON) +option(CLANG_ENABLE_STATIC_LIBRARIES "Build libclang* as static libraries." ON) + option(CLANG_ENABLE_PROTO_FUZZER "Build Clang protobuf fuzzer." OFF) if(NOT CLANG_ENABLE_STATIC_ANALYZER AND CLANG_ENABLE_ARCMT) diff --git a/clang/cmake/modules/AddClang.cmake b/clang/cmake/modules/AddClang.cmake --- a/clang/cmake/modules/AddClang.cmake +++ b/clang/cmake/modules/AddClang.cmake @@ -44,8 +44,8 @@ macro(add_clang_library name) cmake_parse_arguments(ARG - "SHARED" - "" + "SHARED;STATIC" + "OUTPUT_NAME" "ADDITIONAL_HEADERS" ${ARGN}) set(srcs) @@ -80,10 +80,20 @@ ${ARG_ADDITIONAL_HEADERS} # It may contain unparsed unknown args. ) endif() - if(ARG_SHARED) + if(ARG_SHARED OR CLANG_ENABLE_SHARED_LIBRARIES) set(ARG_ENABLE_SHARED SHARED) endif() - llvm_add_library(${name} ${ARG_ENABLE_SHARED} ${ARG_UNPARSED_ARGUMENTS} ${srcs}) + if(ARG_STATIC OR CLANG_ENABLE_STATIC_LIBRARIES) + set(ARG_ENABLE_STATIC STATIC) + endif() + if(ARG_OUTPUT_NAME) + set(NAME_OUTPUT OUTPUT_NAME ${ARG_OUTPUT_NAME}) + elseif(ARG_SHARED AND ARG_STATIC) + set(NAME_OUTPUT OUTPUT_NAME ${name}) + else() + set(NAME_OUTPUT) + endif() + llvm_add_library(${name} ${NAME_OUTPUT} ${ARG_ENABLE_SHARED} ${ARG_ENABLE_STATIC} ${ARG_UNPARSED_ARGUMENTS} ${srcs}) if(TARGET ${name}) target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS}) diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -442,20 +442,20 @@ endif() if(ARG_SHARED AND ARG_STATIC) - # static - set(name_static "${name}_static") + # Do shared first + set(name_shared "${name}_shared") if(ARG_OUTPUT_NAME) set(output_name OUTPUT_NAME "${ARG_OUTPUT_NAME}") endif() # DEPENDS has been appended to LLVM_COMMON_LIBS. - llvm_add_library(${name_static} STATIC + llvm_add_library(${name_shared} SHARED ${output_name} OBJLIBS ${ALL_FILES} # objlib LINK_LIBS ${ARG_LINK_LIBS} LINK_COMPONENTS ${ARG_LINK_COMPONENTS} ) - # FIXME: Add name_static to anywhere in TARGET ${name}'s PROPERTY. - set(ARG_STATIC) + # FIXME: Add name_shared to anywhere in TARGET ${name}'s PROPERTY. + set(ARG_SHARED) endif() if(ARG_MODULE)