Index: libcxx/CMakeLists.txt =================================================================== --- libcxx/CMakeLists.txt +++ libcxx/CMakeLists.txt @@ -866,6 +866,19 @@ config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) endif() +if (WIN32 AND LIBCXX_ENABLE_STATIC_ABI_LIBRARY) + if (LIBCXX_ENABLE_SHARED AND LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY) + # If linking libcxxabi statically into a shared libcxx, change declarations + # as if we are part of the libcxxabi, to make declarations dllexport + # instead of dllimport. + add_definitions(-D_LIBCXXABI_BUILDING_LIBRARY) + elseif(LIBCXX_ENABLE_STATIC AND LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY) + # If linking libcxxabi statically into a static libcxx, skip the dllimport + # attributes on symbols we refer to from libcxxabi. + add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS) + endif() +endif() + # Setup all common build flags ================================================= function(cxx_add_common_build_flags target) cxx_add_basic_build_flags(${target}) Index: libcxxabi/CMakeLists.txt =================================================================== --- libcxxabi/CMakeLists.txt +++ libcxxabi/CMakeLists.txt @@ -281,7 +281,18 @@ # Disable DLL annotations on Windows for static builds. if (WIN32 AND LIBCXXABI_ENABLE_STATIC AND NOT LIBCXXABI_ENABLE_SHARED) - add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS) + if (LIBCXX_ENABLE_SHARED AND LIBCXX_ENABLE_STATIC_ABI_LIBRARY) + # Building libcxxabi statically, but intending for it to be statically + # linked into a shared libcxx; keep dllexport enabled within libcxxabi, + # and treat libcxx imports in the same way as if we were building libcxx + # itself (make them dllexport instead of dllimport). + # Define to the empty string (if just defined as -DFOO, it defines it to + # the value 1) as we have a number of "#define _LIBCPP_BUILDING_LIBRARY" + # in certain source files. + add_definitions(-D_LIBCPP_BUILDING_LIBRARY=) + else() + add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS) + endif() endif() add_compile_flags_if_supported(-Werror=return-type)