@@ -171,84 +171,64 @@ file(GLOB_RECURSE all_sources CONFIGURE_DEPENDS
171
171
"${mongo-c-driver_SOURCE_DIR}/src/common/*.c"
172
172
)
173
173
174
- # The default object library for all libbson translation units:
175
- add_library (bson_obj OBJECT EXCLUDE_FROM_ALL ${all_sources} )
176
-
177
- # The libbson object libraries that we will build
178
- set (bson_obj_libs bson_obj)
179
-
180
- if (ENABLE_PIC OR WIN32 )
181
- # User wants (or platform requires) static libs to use PIC code. Since we
182
- # already need PIC for the dynamic library, we can consolidate things and
183
- # use a single object library for both the static and the shared library.
184
- # No duplicate compilations necessary!
185
- set_property (TARGET bson_obj PROPERTY POSITION_INDEPENDENT_CODE TRUE )
186
- # The bson_obj_pic is just an alias of the base library:
187
- add_library (bson_obj_pic ALIAS bson_obj)
188
- else ()
189
- # User does not want PIC in the static library. In that case, we just need a second object
190
- # library that has PIC enabled so it can be used in creating the dynamic library.
191
- add_library (bson_obj_pic OBJECT EXCLUDE_FROM_ALL ${all_sources} )
192
- set_property (TARGET bson_obj_pic PROPERTY POSITION_INDEPENDENT_CODE TRUE )
193
- list (APPEND bson_obj_libs bson_obj_pic)
194
- endif ()
195
-
196
- # Set target properties for the object libraries.
197
- mongo_target_requirements(
198
- ${bson_obj_libs}
199
- LINK_LIBRARIES
200
- PUBLIC
201
- _libbson_build_interface
202
- COMPILE_DEFINITIONS
203
- PRIVATE
204
- # Tell headers that they are part of compilation:
205
- BSON_COMPILATION
206
- # Enable NaN parsing in jsonsl
207
- JSONSL_PARSE_NAN
208
- # Set the name mangling scheme for the common libraries
209
- MCOMMON_NAME_PREFIX=_bson_mcommon
210
- COMPILE_OPTIONS
211
- PRIVATE
212
- # Macro constant INFINITY triggers constant arithmetic overflow warnings in
213
- # VS 2013, but VS 2013 doesn't support inline warning suppression.
214
- # Remove once support for VS 2013 is dropped.
215
- $<$<AND :$<C_COMPILER_ID:MSVC >,$<VERSION_LESS :${MSVC_VERSION} ,1900>>:/wd4756>
216
- )
217
-
218
174
# List of the primary BSON library targets that we are building
219
175
set (bson_libs)
220
176
221
177
if (ENABLE_STATIC)
222
- add_library (bson_static STATIC )
223
- target_link_libraries (bson_static PRIVATE $<BUILD_INTERFACE:bson_obj>)
178
+ add_library (bson_static STATIC ${all_sources} )
224
179
list (APPEND bson_libs bson_static)
180
+ # Define `BSON_STATIC` when building to suppress the annotation __declspec(dllexport).
181
+ # This prevents consumers of bson_static from exporting the symbols.
182
+ target_compile_definitions (bson_static PRIVATE BSON_STATIC)
225
183
# When consumers link against bson_static, suppress the annotation __declspec(dllimport),
226
184
# since those symbols will be available immediately at the link step:
227
185
target_compile_definitions (bson_static INTERFACE BSON_STATIC)
186
+
187
+ if (ENABLE_PIC)
188
+ # User wants static libs to use PIC code.
189
+ set_property (TARGET bson_static PROPERTY POSITION_INDEPENDENT_CODE TRUE )
190
+ endif ()
228
191
endif ()
229
192
230
193
if (ENABLE_SHARED)
231
- add_library (bson_shared SHARED)
194
+ add_library (bson_shared SHARED ${all_sources} )
232
195
if (WIN32 )
233
196
# Add resource-definition script for Windows shared library (.dll).
234
197
configure_file (libbson.rc.in libbson.rc)
235
198
target_sources (bson_shared PRIVATE ${CMAKE_CURRENT_BINARY_DIR} /libbson.rc)
236
199
endif ()
237
- target_link_libraries (bson_shared PRIVATE $<BUILD_INTERFACE:bson_obj_pic>)
238
200
list (APPEND bson_libs bson_shared)
239
201
endif ()
240
202
241
203
if (NOT bson_libs)
242
204
message (FATAL_ERROR "Neither bson_shared nor bson_static is going to be built. Did you mean to enable at least one of them?" )
243
205
endif ()
244
206
207
+ # Set target properties for the libraries.
245
208
mongo_target_requirements(
246
- ${bson_libs} LINK_LIBRARIES PUBLIC
247
- # Build-local requirements:
248
- $<BUILD_INTERFACE:_libbson_build_interface>
249
- # Include in the install interface explicitly:
250
- mongo::detail::c_platform
209
+ ${bson_libs}
210
+ LINK_LIBRARIES
211
+ PUBLIC
212
+ # Build-local requirements:
213
+ $<BUILD_INTERFACE:_libbson_build_interface>
214
+ # Include in the install interface explicitly:
215
+ mongo::detail::c_platform
216
+ COMPILE_DEFINITIONS
217
+ PRIVATE
218
+ # Tell headers that they are part of compilation:
219
+ BSON_COMPILATION
220
+ # Enable NaN parsing in jsonsl
221
+ JSONSL_PARSE_NAN
222
+ # Set the name mangling scheme for the common libraries
223
+ MCOMMON_NAME_PREFIX=_bson_mcommon
224
+ COMPILE_OPTIONS
225
+ PRIVATE
226
+ # Macro constant INFINITY triggers constant arithmetic overflow warnings in
227
+ # VS 2013, but VS 2013 doesn't support inline warning suppression.
228
+ # Remove once support for VS 2013 is dropped.
229
+ $<$<AND :$<C_COMPILER_ID:MSVC >,$<VERSION_LESS :${MSVC_VERSION} ,1900>>:/wd4756>
251
230
)
231
+
252
232
set_target_properties (${bson_libs} PROPERTIES
253
233
VERSION "0.0.0"
254
234
SOVERSION "0"
0 commit comments