Skip to content

Commit 585610f

Browse files
committed
core/compiler: add shared/static linkage definitions
- BR_BUILD_SHARED - defined to 1 if building shared - BR_BUILD_STATIC - defined to 1 if building static - BR_EXPORTS - defined to 1 if exporting - BR_API_EXPORT - defined to BR_DLL_EXPORT if shared - BR_API_IMPORT - defined to BR_DLL_IMPORT if static - BR_API - defined to one of BR_DLL_{EXPORT,IMPORT} depending on BR_EXPORTS.
1 parent a86ee66 commit 585610f

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

core/CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ set(BRENDER_OBJECTS)
2020

2121
foreach (target ${BRENDER_TARGETS})
2222
add_subdirectory(${target})
23+
target_compile_definitions(${target} PRIVATE -DBR_EXPORTS=1)
2324
list(APPEND BRENDER_OBJECTS "$<TARGET_OBJECTS:${target}>")
2425
endforeach ()
2526

@@ -33,6 +34,15 @@ endforeach ()
3334
##
3435
add_library(brender)
3536

37+
get_target_property(target_type brender TYPE)
38+
if(target_type STREQUAL SHARED_LIBRARY)
39+
target_compile_definitions(brender-inc INTERFACE -DBR_BUILD_STATIC=0)
40+
target_compile_definitions(brender-inc INTERFACE -DBR_BUILD_SHARED=1)
41+
else()
42+
target_compile_definitions(brender-inc INTERFACE -DBR_BUILD_STATIC=1)
43+
target_compile_definitions(brender-inc INTERFACE -DBR_BUILD_SHARED=0)
44+
endif()
45+
3646
##
3747
# Link all the subtargets privately so our consumers don't inherit their
3848
# includes, which pulls in DDI.

core/inc/compiler.h

+41
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,28 @@
99
#ifndef _COMPILER_H_
1010
#define _COMPILER_H_
1111

12+
/*
13+
* Defined to 1 if built as a shared library.
14+
*/
15+
#if !defined(BR_BUILD_SHARED)
16+
#define BR_BUILD_SHARED 0
17+
#endif
18+
19+
/*
20+
* Defined to 1 if built as a static library.
21+
*/
22+
#if !defined(BR_BUILD_STATIC)
23+
#define BR_BUILD_STATIC 0
24+
#endif
25+
26+
#if(!BR_BUILD_SHARED && !BR_BUILD_STATIC) || (BR_BUILD_SHARED && BR_BUILD_STATIC)
27+
#error Invalid linkage configuration
28+
#endif
29+
30+
#if !defined(BR_EXPORTS)
31+
#define BR_EXPORTS 0
32+
#endif
33+
1234
#if defined(__H2INC__)
1335
typedef signed char int8_t;
1436
typedef signed short int16_t;
@@ -218,6 +240,25 @@ typedef float br_float;
218240

219241
#define BR_STR(s) #s
220242

243+
/*
244+
* Handle static/shared library stuff.
245+
*/
246+
#if BR_BUILD_SHARED
247+
#define BR_API_EXPORT BR_DLL_EXPORT
248+
#define BR_API_IMPORT BR_DLL_IMPORT
249+
#endif
250+
251+
#if BR_BUILD_STATIC
252+
#define BR_API_EXPORT
253+
#define BR_API_IMPORT
254+
#endif
255+
256+
#if BR_EXPORTS
257+
#define BR_API BR_API_EXPORT
258+
#else
259+
#define BR_API BR_API_IMPORT
260+
#endif
261+
221262
#if defined(__H2INC__)
222263
/*
223264
* Avoid some tokens that masm chokes on

0 commit comments

Comments
 (0)