Skip to content

Commit 51016b4

Browse files
authored
Merge pull request #80 from SLM-Audio/syl/moha-strip-symbols
Symbol stripping support
2 parents d288c2a + e17a581 commit 51016b4

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ you specify the AU format, a few more arguments become neccessary - the argument
102102
MANUFACTURER_CODE "Brat" # REQUIRED FOR AU, UNUSED OTHERWISE - Your unique 4 character manufacturer code.
103103
SUBTYPE_CODE "Bpi1" # REQUIRED FOR AU, UNUSED OTHERWISE - A 4 character identifier for your plugin.
104104
AU_TYPE "aufx" # REQUIRED FOR AU, UNUSED OTHERWISE - The AU plugin type for your plugin. [2]
105+
106+
STRIP TRUE # OPTIONAL, DEFAULTS TO FALSE - On macOS, if provided, will add a post-build symbol strip step to your plugin
107+
# targets, and compile with -fvisibility=hidden. Does nothing on Windows.
108+
SIGN_ID "Developer ID Application: ...." # OPTIONAL - On macOS, if provided, will be used to sign plugin targets
105109
)
106110
```
107111

cmake/mostly_harmless.cmake

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
11

2+
function(mostly_harmless_enable_stripping_static_lib target location name)
3+
if(APPLE)
4+
target_compile_options(${target} PUBLIC $<$<CONFIG:Release>:-fvisibility=hidden>)
5+
set(target_file ${location}/lib${name}_SharedCode.a)
6+
add_custom_command(
7+
TARGET ${target}
8+
COMMAND "$<$<CONFIG:Release>:strip;-x;${target_file}>"
9+
VERBATIM
10+
POST_BUILD
11+
COMMAND_EXPAND_LISTS
12+
)
13+
endif()
14+
endfunction()
15+
16+
function(mostly_harmless_enable_stripping target name extension)
17+
if(APPLE)
18+
target_compile_options(${target} PUBLIC $<$<CONFIG:Release>:-fvisibility=hidden>)
19+
set(target_file ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${name}.${extension}/Contents/MacOS/${name})
20+
add_custom_command(
21+
TARGET ${target}
22+
COMMAND "$<$<CONFIG:Release>:strip;-x;${target_file}>"
23+
VERBATIM
24+
POST_BUILD
25+
COMMAND_EXPAND_LISTS
26+
)
27+
endif()
28+
endfunction()
29+
230
function(mostly_harmless_add_binary_data pluginTarget)
331
set(ARGS
432
TARGET_NAME
@@ -63,6 +91,7 @@ function(mostly_harmless_add_plugin targetName)
6391
SUBTYPE_CODE # REQUIRED IF AU
6492
AU_TYPE # REQUIRED IF AU
6593

94+
STRIP # OPTIONAL, DEFAULT FALSE - if true, will strip symbols in release builds
6695
SIGN_ID # OPTIONAL, if provided, will codesign
6796
)
6897

@@ -141,6 +170,10 @@ function(mostly_harmless_add_plugin targetName)
141170
if (NOT DEFINED PLUGIN_FEATURES)
142171
message(FATAL_ERROR "At least one feature is required")
143172
endif ()
173+
if(NOT DEFINED PLUGIN_STRIP)
174+
set(PLUGIN_STRIP FALSE)
175+
endif()
176+
144177
configure_file(
145178
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/mostlyharmless_Descriptor.cpp
146179
${CMAKE_CURRENT_BINARY_DIR}/mostlyharmless_Descriptor.cpp
@@ -149,6 +182,9 @@ function(mostly_harmless_add_plugin targetName)
149182
target_sources(${PLUGIN_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/mostlyharmless_Descriptor.cpp)
150183
target_link_libraries(${PLUGIN_NAME} PUBLIC MostlyHarmless)
151184
set_target_properties(${PLUGIN_NAME} PROPERTIES OUTPUT_NAME ${PLUGIN_NAME}_SharedCode)
185+
if(${PLUGIN_STRIP})
186+
mostly_harmless_enable_stripping_static_lib(${PLUGIN_NAME} ${CMAKE_CURRENT_BINARY_DIR} ${PLUGIN_NAME})
187+
endif()
152188

153189
list(FIND PLUGIN_FORMATS "CLAP" INDEX)
154190
if (${INDEX} GREATER -1)
@@ -166,6 +202,9 @@ function(mostly_harmless_add_plugin targetName)
166202
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PLUGIN_VERSION}
167203
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/mostly_harmless.plist.in
168204
)
205+
if(${PLUGIN_STRIP})
206+
mostly_harmless_enable_stripping(${PLUGIN_NAME}_CLAP ${PLUGIN_NAME} "clap")
207+
endif()
169208
if (NOT ${PLUGIN_SIGN_ID} STREQUAL "")
170209
mostly_harmless_sign_target(${PLUGIN_NAME}_CLAP ${PLUGIN_NAME} ${PLUGIN_SIGN_ID})
171210
endif ()
@@ -199,6 +238,9 @@ function(mostly_harmless_add_plugin targetName)
199238
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PLUGIN_VERSION}
200239
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/mostly_harmless.plist.in
201240
)
241+
if(${PLUGIN_STRIP})
242+
mostly_harmless_enable_stripping(${PLUGIN_NAME}_VST3 ${PLUGIN_NAME} "vst3")
243+
endif()
202244
if (NOT ${PLUGIN_SIGN_ID} STREQUAL "")
203245
mostly_harmless_sign_target(${PLUGIN_NAME}_VST3 ${PLUGIN_NAME} ${PLUGIN_SIGN_ID})
204246
endif ()
@@ -244,6 +286,9 @@ function(mostly_harmless_add_plugin targetName)
244286
SUBTYPE_CODE ${PLUGIN_SUBTYPE_CODE}
245287
INSTRUMENT_TYPE ${PLUGIN_AU_TYPE}
246288
)
289+
if(${PLUGIN_STRIP})
290+
mostly_harmless_enable_stripping(${PLUGIN_NAME}_AU ${PLUGIN_NAME} "component")
291+
endif()
247292
if (NOT ${PLUGIN_SIGN_ID} STREQUAL "")
248293
mostly_harmless_sign_target(${PLUGIN_NAME}_AU ${PLUGIN_NAME} ${PLUGIN_SIGN_ID})
249294
endif ()

0 commit comments

Comments
 (0)