@@ -44,7 +44,6 @@ endif()
44
44
# Options
45
45
if (OVERRIDE MATCHES "ON" )
46
46
message (STATUS "Override standard malloc (OVERRIDE=ON)" )
47
- list (APPEND mi_defines MI_MALLOC_OVERRIDE)
48
47
if (APPLE )
49
48
if (INTERPOSE MATCHES "ON" )
50
49
# use interpose on macOS
@@ -111,14 +110,30 @@ endif()
111
110
add_library (mimalloc SHARED ${mi_sources} )
112
111
set_target_properties (mimalloc PROPERTIES VERSION ${mi_version} NO_SONAME "YES" OUTPUT_NAME ${mi_basename} )
113
112
target_compile_definitions (mimalloc PRIVATE ${mi_defines} MI_SHARED_LIB MI_SHARED_LIB_EXPORT)
113
+ if (OVERRIDE MATCHES "ON" )
114
+ target_compile_definitions (mimalloc PRIVATE MI_MALLOC_OVERRIDE)
115
+ endif ()
114
116
target_compile_options (mimalloc PRIVATE ${mi_cflags} )
115
117
target_include_directories (mimalloc PRIVATE include PUBLIC $<INSTALL_INTERFACE:${mi_install_dir} /include >)
116
118
target_link_libraries (mimalloc PUBLIC ${mi_libraries} )
117
119
118
120
# static library
119
121
add_library (mimalloc-static STATIC ${mi_sources} )
120
- set_target_properties (mimalloc-static PROPERTIES OUTPUT_NAME ${mi_basename} )
122
+ if (WIN32 )
123
+ # When building both static and shared libraries on Windows,
124
+ # a static library should use a different output name to
125
+ # avoid the conflict with the import library of a shared one.
126
+ string (REPLACE "mimalloc" "mimalloc-static" mi_output_name ${mi_basename} )
127
+ set_target_properties (mimalloc-static PROPERTIES OUTPUT_NAME ${mi_output_name} )
128
+ else ()
129
+ set_target_properties (mimalloc-static PROPERTIES OUTPUT_NAME ${mi_basename} )
130
+ endif ()
121
131
target_compile_definitions (mimalloc-static PRIVATE ${mi_defines} MI_STATIC_LIB)
132
+ if (NOT WIN32 AND OVERRIDE MATCHES "ON" )
133
+ # It is only possible to override malloc on Windows when building as a DLL.
134
+ # (src/alloc-override.c)
135
+ target_compile_definitions (mimalloc-static PRIVATE MI_MALLOC_OVERRIDE)
136
+ endif ()
122
137
target_compile_options (mimalloc-static PRIVATE ${mi_cflags} )
123
138
target_include_directories (mimalloc-static PRIVATE include PUBLIC $<INSTALL_INTERFACE:${mi_install_dir} /include >)
124
139
target_link_libraries (mimalloc-static PUBLIC ${mi_libraries} )
@@ -134,7 +149,12 @@ install(FILES "$<TARGET_FILE:mimalloc>" DESTINATION lib) # duplicate the .so in
134
149
135
150
# single object file for more predictable static overriding
136
151
add_library (mimalloc-obj OBJECT src/static .c)
137
- target_compile_definitions (mimalloc-obj PRIVATE ${mi_defines} MI_MALLOC_OVERRIDE)
152
+ target_compile_definitions (mimalloc-obj PRIVATE ${mi_defines} )
153
+ if (NOT WIN32 AND OVERRIDE MATCHES "ON" )
154
+ # It is only possible to override malloc on Windows when building as a DLL.
155
+ # (src/alloc-override.c)
156
+ target_compile_definitions (mimalloc-obj PRIVATE MI_MALLOC_OVERRIDE)
157
+ endif ()
138
158
target_compile_options (mimalloc-obj PRIVATE ${mi_cflags} )
139
159
target_include_directories (mimalloc-obj PRIVATE include PUBLIC $<INSTALL_INTERFACE:include >)
140
160
0 commit comments