@@ -3,12 +3,12 @@ project(libmimalloc C)
3
3
include ("cmake/mimalloc-config-version.cmake" )
4
4
set (CMAKE_C_STANDARD 11)
5
5
6
- option (OVERRIDE "OVERRIDE " ON )
7
- option (INTERPOSE "INTERPOSE " ON )
8
- option (SEE_ASM "SEE_ASM " OFF )
9
- option (CHECK_FULL "CHECK_FULL " OFF )
10
- option (USE_CXX "USE_CXX " OFF )
11
- option (SECURE "SECURE " OFF )
6
+ option (MI_OVERRIDE "Override the standard malloc interface " ON )
7
+ option (MI_INTERPOSE "Use interpose to override standard malloc on macOS " ON )
8
+ option (MI_SEE_ASM "Generate assembly files " OFF )
9
+ option (MI_CHECK_FULL "Use full internal invariant checking in DEBUG mode " OFF )
10
+ option (MI_USE_CXX "Use the C++ compiler to compile the library " OFF )
11
+ option (MI_SECURE "Use security mitigations (like guard pages and randomization) " OFF )
12
12
13
13
set (mi_install_dir "lib/mimalloc-${mi_version} " )
14
14
@@ -38,42 +38,42 @@ else()
38
38
endif ()
39
39
40
40
if ("${CMAKE_BINARY_DIR} " MATCHES ".*(S|s)ecure$" )
41
- set (SECURE "ON" )
41
+ set (MI_SECURE "ON" )
42
42
endif ()
43
43
44
44
# Options
45
- if (OVERRIDE MATCHES "ON" )
46
- message (STATUS "Override standard malloc (OVERRIDE =ON)" )
45
+ if (MI_OVERRIDE MATCHES "ON" )
46
+ message (STATUS "Override standard malloc (MI_OVERRIDE =ON)" )
47
47
if (APPLE )
48
- if (INTERPOSE MATCHES "ON" )
48
+ if (MI_INTERPOSE MATCHES "ON" )
49
49
# use interpose on macOS
50
- message (STATUS " Use interpose to override malloc (INTERPOSE =ON)" )
50
+ message (STATUS " Use interpose to override malloc (MI_INTERPOSE =ON)" )
51
51
list (APPEND mi_defines MI_INTERPOSE)
52
52
else ()
53
53
# use zone's on macOS
54
- message (STATUS " Use zone's to override malloc (INTERPOSE =OFF)" )
54
+ message (STATUS " Use zone's to override malloc (MI_INTERPOSE =OFF)" )
55
55
list (APPEND mi_sources src/alloc-override-osx.c)
56
56
endif ()
57
57
endif ()
58
58
endif ()
59
59
60
- if (SECURE MATCHES "ON" )
61
- message (STATUS "Set secure build (SECURE =ON)" )
60
+ if (MI_SECURE MATCHES "ON" )
61
+ message (STATUS "Set secure build (MI_SECURE =ON)" )
62
62
list (APPEND mi_defines MI_SECURE=2)
63
63
endif ()
64
64
65
- if (SEE_ASM MATCHES "ON" )
66
- message (STATUS "Generate assembly listings (SEE_ASM =ON)" )
65
+ if (MI_SEE_ASM MATCHES "ON" )
66
+ message (STATUS "Generate assembly listings (MI_SEE_ASM =ON)" )
67
67
list (APPEND mi_cflags -save-temps)
68
68
endif ()
69
69
70
- if (CHECK_FULL MATCHES "ON" )
71
- message (STATUS "Set debug level to full invariant checking (CHECK_FULL =ON)" )
70
+ if (MI_CHECK_FULL MATCHES "ON" )
71
+ message (STATUS "Set debug level to full invariant checking (MI_CHECK_FULL =ON)" )
72
72
list (APPEND mi_defines MI_DEBUG=3) # full invariant checking
73
73
endif ()
74
74
75
- if (USE_CXX MATCHES "ON" )
76
- message (STATUS "Use the C++ compiler to compile (USE_CXX =ON)" )
75
+ if (MI_USE_CXX MATCHES "ON" )
76
+ message (STATUS "Use the C++ compiler to compile (MI_USE_CXX =ON)" )
77
77
set_source_files_properties (${mi_sources} PROPERTIES LANGUAGE CXX )
78
78
endif ()
79
79
@@ -89,7 +89,7 @@ if(NOT(CMAKE_BUILD_TYPE MATCHES "Release|RelWithDebInfo"))
89
89
string (TOLOWER "${CMAKE_BUILD_TYPE} " build_type )
90
90
set (mi_basename "mimalloc-${build_type} " )
91
91
else ()
92
- if (SECURE MATCHES "ON" )
92
+ if (MI_SECURE MATCHES "ON" )
93
93
set (mi_basename "mimalloc-secure" )
94
94
else ()
95
95
set (mi_basename "mimalloc" )
@@ -110,7 +110,7 @@ endif()
110
110
add_library (mimalloc SHARED ${mi_sources} )
111
111
set_target_properties (mimalloc PROPERTIES VERSION ${mi_version} NO_SONAME "YES" OUTPUT_NAME ${mi_basename} )
112
112
target_compile_definitions (mimalloc PRIVATE ${mi_defines} MI_SHARED_LIB MI_SHARED_LIB_EXPORT)
113
- if (OVERRIDE MATCHES "ON" )
113
+ if (MI_OVERRIDE MATCHES "ON" )
114
114
target_compile_definitions (mimalloc PRIVATE MI_MALLOC_OVERRIDE)
115
115
endif ()
116
116
target_compile_options (mimalloc PRIVATE ${mi_cflags} )
@@ -120,18 +120,16 @@ target_link_libraries(mimalloc PUBLIC ${mi_libraries})
120
120
# static library
121
121
add_library (mimalloc-static STATIC ${mi_sources} )
122
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.
123
+ # When building both static and shared libraries on Windows, a static library should use a
124
+ # different output name to avoid the conflict with the import library of a shared one.
126
125
string (REPLACE "mimalloc" "mimalloc-static" mi_output_name ${mi_basename} )
127
126
set_target_properties (mimalloc-static PROPERTIES OUTPUT_NAME ${mi_output_name} )
128
127
else ()
129
128
set_target_properties (mimalloc-static PROPERTIES OUTPUT_NAME ${mi_basename} )
130
129
endif ()
131
130
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)
131
+ if (NOT WIN32 AND MI_OVERRIDE MATCHES "ON" )
132
+ # It is only possible to override malloc on Windows when building as a DLL. (src/alloc-override.c)
135
133
target_compile_definitions (mimalloc-static PRIVATE MI_MALLOC_OVERRIDE)
136
134
endif ()
137
135
target_compile_options (mimalloc-static PRIVATE ${mi_cflags} )
@@ -150,9 +148,8 @@ install(FILES "$<TARGET_FILE:mimalloc>" DESTINATION lib) # duplicate the .so in
150
148
# single object file for more predictable static overriding
151
149
add_library (mimalloc-obj OBJECT src/static .c)
152
150
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)
151
+ if (NOT WIN32 AND MI_OVERRIDE MATCHES "ON" )
152
+ # It is only possible to override malloc on Windows when building as a DLL. (src/alloc-override.c)
156
153
target_compile_definitions (mimalloc-obj PRIVATE MI_MALLOC_OVERRIDE)
157
154
endif ()
158
155
target_compile_options (mimalloc-obj PRIVATE ${mi_cflags} )
0 commit comments