diff --git a/CMakeLists.txt b/CMakeLists.txt index 13d79eec0..6b0a23e92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,6 +144,16 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) add_library(BlocksRuntime ${PROJECT_SOURCE_DIR}/src/BlocksRuntime/data.c ${PROJECT_SOURCE_DIR}/src/BlocksRuntime/runtime.c) + if(CMAKE_SYSTEM_NAME STREQUAL Windows) + target_sources(BlocksRuntime + PRIVATE + ${PROJECT_SOURCE_DIR}/src/BlocksRuntime/BlocksRuntime.def) + if(NOT BUILD_SHARED_LIBS) + target_compile_definitions(BlocksRuntime + PRIVATE + BlocksRuntime_STATIC) + endif() + endif() set_target_properties(BlocksRuntime PROPERTIES POSITION_INDEPENDENT_CODE TRUE) diff --git a/src/BlocksRuntime/Block.h b/src/BlocksRuntime/Block.h index d0898ff49..32f27f4f9 100644 --- a/src/BlocksRuntime/Block.h +++ b/src/BlocksRuntime/Block.h @@ -11,11 +11,25 @@ #ifndef _Block_H_ #define _Block_H_ +#if defined(_WIN32) +# if defined(BlocksRuntime_STATIC) +# define BLOCK_ABI +# else +# if defined(BlocksRuntime_EXPORTS) +# define BLOCK_ABI __declspec(dllexport) +# else +# define BLOCK_ABI __declspec(dllimport) +# endif +# endif +#else +# define BLOCK_ABI __attribute__((__visibility__("default"))) +#endif + #if !defined(BLOCK_EXPORT) # if defined(__cplusplus) -# define BLOCK_EXPORT extern "C" __attribute__((visibility("default"))) +# define BLOCK_EXPORT extern "C" BLOCK_ABI # else -# define BLOCK_EXPORT extern __attribute__((visibility("default"))) +# define BLOCK_EXPORT extern BLOCK_ABI # endif #endif @@ -38,8 +52,13 @@ BLOCK_EXPORT void _Block_object_assign(void *, const void *, const int); BLOCK_EXPORT void _Block_object_dispose(const void *, const int); // Used by the compiler. Do not use these variables yourself. +#if defined(_WIN32) +extern void * _NSConcreteGlobalBlock[32]; +extern void * _NSConcreteStackBlock[32]; +#else BLOCK_EXPORT void * _NSConcreteGlobalBlock[32]; BLOCK_EXPORT void * _NSConcreteStackBlock[32]; +#endif #if __cplusplus } diff --git a/src/BlocksRuntime/BlocksRuntime.def b/src/BlocksRuntime/BlocksRuntime.def new file mode 100644 index 000000000..a3b1aabeb --- /dev/null +++ b/src/BlocksRuntime/BlocksRuntime.def @@ -0,0 +1,4 @@ +LIBRARY BlocksRuntime +EXPORTS + _NSConcreteGlobalBlock CONSTANT + _NSConcreteStackBlock CONSTANT diff --git a/src/BlocksRuntime/data.c b/src/BlocksRuntime/data.c index 03de71b41..fe4745b04 100644 --- a/src/BlocksRuntime/data.c +++ b/src/BlocksRuntime/data.c @@ -14,11 +14,17 @@ We allocate space and export a symbol to be used as the Class for the on-stack a We keep these in a separate file so that we can include the runtime code in test subprojects but not include the data so that compiled code that sees the data in libSystem doesn't get confused by a second copy. Somehow these don't get unified in a common block. **********************/ -#define BLOCK_EXPORT __attribute__((visibility("default"))) +#include "Block.h" -BLOCK_EXPORT void * _NSConcreteStackBlock[32] = { 0 }; -BLOCK_EXPORT void * _NSConcreteMallocBlock[32] = { 0 }; -BLOCK_EXPORT void * _NSConcreteAutoBlock[32] = { 0 }; -BLOCK_EXPORT void * _NSConcreteFinalizingBlock[32] = { 0 }; -BLOCK_EXPORT void * _NSConcreteGlobalBlock[32] = { 0 }; -BLOCK_EXPORT void * _NSConcreteWeakBlockVariable[32] = { 0 }; +#if defined(_WIN32) +void * _NSConcreteStackBlock[32] = { 0 }; +void * _NSConcreteGlobalBlock[32] = { 0 }; +#else +BLOCK_ABI void * _NSConcreteStackBlock[32] = { 0 }; +BLOCK_ABI void * _NSConcreteGlobalBlock[32] = { 0 }; +#endif + +BLOCK_ABI void * _NSConcreteMallocBlock[32] = { 0 }; +BLOCK_ABI void * _NSConcreteAutoBlock[32] = { 0 }; +BLOCK_ABI void * _NSConcreteFinalizingBlock[32] = { 0 }; +BLOCK_ABI void * _NSConcreteWeakBlockVariable[32] = { 0 };