Skip to content

Commit 91cb4ce

Browse files
committed
use MI_ prefix for all options to better support subdirectory cmake, issue #3
1 parent 30b8624 commit 91cb4ce

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

CMakeLists.txt

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ project(libmimalloc C)
33
include("cmake/mimalloc-config-version.cmake")
44
set(CMAKE_C_STANDARD 11)
55

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)
1212

1313
set(mi_install_dir "lib/mimalloc-${mi_version}")
1414

@@ -38,42 +38,42 @@ else()
3838
endif()
3939

4040
if("${CMAKE_BINARY_DIR}" MATCHES ".*(S|s)ecure$")
41-
set(SECURE "ON")
41+
set(MI_SECURE "ON")
4242
endif()
4343

4444
# 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)")
4747
if(APPLE)
48-
if(INTERPOSE MATCHES "ON")
48+
if(MI_INTERPOSE MATCHES "ON")
4949
# 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)")
5151
list(APPEND mi_defines MI_INTERPOSE)
5252
else()
5353
# 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)")
5555
list(APPEND mi_sources src/alloc-override-osx.c)
5656
endif()
5757
endif()
5858
endif()
5959

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)")
6262
list(APPEND mi_defines MI_SECURE=2)
6363
endif()
6464

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)")
6767
list(APPEND mi_cflags -save-temps)
6868
endif()
6969

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)")
7272
list(APPEND mi_defines MI_DEBUG=3) # full invariant checking
7373
endif()
7474

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)")
7777
set_source_files_properties(${mi_sources} PROPERTIES LANGUAGE CXX )
7878
endif()
7979

@@ -89,7 +89,7 @@ if(NOT(CMAKE_BUILD_TYPE MATCHES "Release|RelWithDebInfo"))
8989
string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type)
9090
set(mi_basename "mimalloc-${build_type}")
9191
else()
92-
if(SECURE MATCHES "ON")
92+
if(MI_SECURE MATCHES "ON")
9393
set(mi_basename "mimalloc-secure")
9494
else()
9595
set(mi_basename "mimalloc")
@@ -110,7 +110,7 @@ endif()
110110
add_library(mimalloc SHARED ${mi_sources})
111111
set_target_properties(mimalloc PROPERTIES VERSION ${mi_version} NO_SONAME "YES" OUTPUT_NAME ${mi_basename} )
112112
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")
114114
target_compile_definitions(mimalloc PRIVATE MI_MALLOC_OVERRIDE)
115115
endif()
116116
target_compile_options(mimalloc PRIVATE ${mi_cflags})
@@ -120,18 +120,16 @@ target_link_libraries(mimalloc PUBLIC ${mi_libraries})
120120
# static library
121121
add_library(mimalloc-static STATIC ${mi_sources})
122122
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.
126125
string(REPLACE "mimalloc" "mimalloc-static" mi_output_name ${mi_basename})
127126
set_target_properties(mimalloc-static PROPERTIES OUTPUT_NAME ${mi_output_name})
128127
else()
129128
set_target_properties(mimalloc-static PROPERTIES OUTPUT_NAME ${mi_basename})
130129
endif()
131130
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)
135133
target_compile_definitions(mimalloc-static PRIVATE MI_MALLOC_OVERRIDE)
136134
endif()
137135
target_compile_options(mimalloc-static PRIVATE ${mi_cflags})
@@ -150,9 +148,8 @@ install(FILES "$<TARGET_FILE:mimalloc>" DESTINATION lib) # duplicate the .so in
150148
# single object file for more predictable static overriding
151149
add_library(mimalloc-obj OBJECT src/static.c)
152150
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)
156153
target_compile_definitions(mimalloc-obj PRIVATE MI_MALLOC_OVERRIDE)
157154
endif()
158155
target_compile_options(mimalloc-obj PRIVATE ${mi_cflags})

0 commit comments

Comments
 (0)