Expect DLL builds on Windows by default and require a custom __config for static
builds. On Windows the __declspec(dllimport) and __declspec(dllexport) attributes require linking to a DLL, not a static library. Previously these annotations were disabled by default unless _LIBCPP_DLL was defined. However the DLL configuration is probably the more common one, so it should be supported by default. This patch enables import/export attributes by default and adds a _LIBCPP_DISABLE_DLL_IMPORT_EXPORT macro which can be used to disable this behavior. If libc++ is built as a static library on Windows then a custom __config header will be generated that predefines this macro. This patch is based off work by Shoaib Meenai. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@282449 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -330,6 +330,8 @@ endif()
|
|||||||
# headers
|
# headers
|
||||||
add_compile_flags_if_supported(-nostdinc++)
|
add_compile_flags_if_supported(-nostdinc++)
|
||||||
|
|
||||||
|
# Let the library headers know they are currently being used to build the
|
||||||
|
# library.
|
||||||
add_definitions(-D_LIBCPP_BUILDING_LIBRARY)
|
add_definitions(-D_LIBCPP_BUILDING_LIBRARY)
|
||||||
|
|
||||||
# Warning flags ===============================================================
|
# Warning flags ===============================================================
|
||||||
@@ -455,6 +457,14 @@ config_define_if(LIBCXX_HAS_PTHREAD_API _LIBCPP_HAS_THREAD_API_PTHREAD)
|
|||||||
config_define_if(LIBCXX_HAS_EXTERNAL_THREAD_API _LIBCPP_HAS_THREAD_API_EXTERNAL)
|
config_define_if(LIBCXX_HAS_EXTERNAL_THREAD_API _LIBCPP_HAS_THREAD_API_EXTERNAL)
|
||||||
config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC)
|
config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC)
|
||||||
|
|
||||||
|
# By default libc++ on Windows expects to use a shared library, which requires
|
||||||
|
# the headers to use DLL import/export semantics. However when building a
|
||||||
|
# static library only we modify the headers to disable DLL import/export.
|
||||||
|
if (DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED)
|
||||||
|
message(STATUS "Generating custom __config for non-DLL Windows build")
|
||||||
|
config_define(ON _LIBCPP_DISABLE_DLL_IMPORT_EXPORT)
|
||||||
|
endif()
|
||||||
|
|
||||||
if (LIBCXX_NEEDS_SITE_CONFIG)
|
if (LIBCXX_NEEDS_SITE_CONFIG)
|
||||||
configure_file(
|
configure_file(
|
||||||
include/__config_site.in
|
include/__config_site.in
|
||||||
|
|||||||
@@ -519,20 +519,20 @@ namespace std {
|
|||||||
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
// only really useful for a DLL. _LIBCPP_DLL should be a compiler builtin define ideally...
|
#if defined(_LIBCPP_DISABLE_DLL_IMPORT_EXPORT)
|
||||||
#if defined(_LIBCPP_DLL) && defined(cxx_EXPORTS)
|
|
||||||
# define _LIBCPP_DLL_VIS __declspec(dllexport)
|
|
||||||
# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
|
|
||||||
# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
|
|
||||||
#elif defined(_LIBCPP_DLL)
|
|
||||||
# define _LIBCPP_DLL_VIS __declspec(dllimport)
|
|
||||||
# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
|
|
||||||
# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
|
|
||||||
#else
|
|
||||||
# define _LIBCPP_DLL_VIS
|
# define _LIBCPP_DLL_VIS
|
||||||
# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
|
# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
|
||||||
# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
|
# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
|
||||||
|
#elif defined(_LIBCPP_BUILDING_LIBRARY)
|
||||||
|
# define _LIBCPP_DLL_VIS __declspec(dllexport)
|
||||||
|
# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
|
||||||
|
# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
|
||||||
|
#else
|
||||||
|
# define _LIBCPP_DLL_VIS __declspec(dllimport)
|
||||||
|
# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
|
||||||
|
# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define _LIBCPP_TYPE_VIS _LIBCPP_DLL_VIS
|
#define _LIBCPP_TYPE_VIS _LIBCPP_DLL_VIS
|
||||||
#define _LIBCPP_FUNC_VIS _LIBCPP_DLL_VIS
|
#define _LIBCPP_FUNC_VIS _LIBCPP_DLL_VIS
|
||||||
#define _LIBCPP_EXCEPTION_ABI _LIBCPP_DLL_VIS
|
#define _LIBCPP_EXCEPTION_ABI _LIBCPP_DLL_VIS
|
||||||
|
|||||||
@@ -21,5 +21,6 @@
|
|||||||
#cmakedefine _LIBCPP_HAS_MUSL_LIBC
|
#cmakedefine _LIBCPP_HAS_MUSL_LIBC
|
||||||
#cmakedefine _LIBCPP_HAS_THREAD_API_PTHREAD
|
#cmakedefine _LIBCPP_HAS_THREAD_API_PTHREAD
|
||||||
#cmakedefine _LIBCPP_HAS_THREAD_API_EXTERNAL
|
#cmakedefine _LIBCPP_HAS_THREAD_API_EXTERNAL
|
||||||
|
#cmakedefine _LIBCPP_DISABLE_DLL_IMPORT_EXPORT
|
||||||
|
|
||||||
#endif // _LIBCPP_CONFIG_SITE
|
#endif // _LIBCPP_CONFIG_SITE
|
||||||
|
|||||||
Reference in New Issue
Block a user