Skip to content

Commit 0ea450d

Browse files
committed
CoreFoundation: use modern standards for DLL build
Use the CMake defined `_EXPORT` macro to determine if the symbols should be exported. Rely on `_USRDLL` to indicate if the compilation is meant for static or shared builds and mark the symbols for export or not to prevent the symbols from being re-exported from the consuming library.
1 parent 29d6b92 commit 0ea450d

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ ExternalProject_Add(CoreFoundation
3434
${CMAKE_COMMAND}
3535
CMAKE_ARGS
3636
-DBUILD_SHARED_LIBS=NO
37-
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
3837
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
38+
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
39+
# NOTE(compnerd) ensure that we build it as a DLL as we
40+
# wish to re-export the symbols from Foundation
41+
-DCMAKE_C_FLAGS=-D_USRDLL
3942
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
4043
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
4144
-DCMAKE_INSTALL_LIBDIR=usr/lib

CoreFoundation/Base.subproj/CFBase.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,20 @@
127127
#endif
128128

129129
#if TARGET_OS_WIN32
130-
#if !defined(CF_EXPORT)
131-
#if defined(CF_BUILDING_CF) && defined(__cplusplus)
132-
#define CF_EXPORT extern "C" __declspec(dllexport)
133-
#elif defined(CF_BUILDING_CF) && !defined(__cplusplus)
134-
#define CF_EXPORT extern __declspec(dllexport)
135-
#elif defined(__cplusplus)
136-
#define CF_EXPORT extern "C" __declspec(dllimport)
130+
#if defined(__cplusplus)
131+
#define _CF_EXTERN extern "C"
132+
#else
133+
#define _CF_EXTERN extern
134+
#endif
135+
136+
#if defined(_USRDLL)
137+
#if defined(CoreFoundation_EXPORTS)
138+
#define CF_EXPORT _CF_EXTERN __declspec(dllexport)
137139
#else
138-
#define CF_EXPORT extern __declspec(dllimport)
140+
#define CF_EXPORT _CF_EXTERN __declspec(dllimport)
139141
#endif
142+
#else
143+
#define CF_EXPORT _CF_EXTERN
140144
#endif
141145
#else
142146
#define CF_EXPORT extern

CoreFoundation/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,11 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Windows)
329329
target_compile_definitions(CoreFoundation
330330
PRIVATE
331331
-DDEPLOYMENT_TARGET_WINDOWS)
332+
if(BUILD_SHARED_LIBS)
333+
target_compile_definitions(CoreFoundation
334+
PRIVATE
335+
-D_USRDLL)
336+
endif()
332337
endif()
333338
target_compile_definitions(CoreFoundation
334339
PRIVATE

0 commit comments

Comments
 (0)