@@ -154,6 +154,27 @@ else()
154
154
if (AWK STREQUAL "AWK-NOTFOUND" )
155
155
message (FATAL_ERROR "AWK not found" )
156
156
endif ()
157
+
158
+ if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
159
+
160
+ # Ensure that dsymutil and strip is present
161
+ find_program (DSYMUTIL dsymutil)
162
+ if (DSYMUTIL STREQUAL "DSYMUTIL-NOTFOUND" )
163
+ message (FATAL_ERROR "dsymutil not found" )
164
+ endif ()
165
+ find_program (STRIP strip)
166
+ if (STRIP STREQUAL "STRIP-NOTFOUND" )
167
+ message (FATAL_ERROR "strip not found" )
168
+ endif ()
169
+
170
+ else (CMAKE_SYSTEM_NAME STREQUAL Darwin)
171
+
172
+ # Ensure that objcopy is present
173
+ find_program (OBJCOPY objcopy)
174
+ if (OBJCOPY STREQUAL "OBJCOPY-NOTFOUND" )
175
+ message (FATAL_ERROR "objcopy not found" )
176
+ endif ()
177
+ endif (CMAKE_SYSTEM_NAME STREQUAL Darwin)
157
178
endif (WIN32 )
158
179
159
180
# Build a list of compiler definitions by putting -D in front of each define.
@@ -242,6 +263,69 @@ function(add_precompiled_header header cppFile targetSources)
242
263
endif (MSVC )
243
264
endfunction ()
244
265
266
+ function (strip_symbols targetName outputFilename)
267
+ if (CLR_CMAKE_PLATFORM_UNIX)
268
+ if (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE)
269
+
270
+ # On the older version of cmake (2.8.12) used on Ubuntu 14.04 the TARGET_FILE
271
+ # generator expression doesn't work correctly returning the wrong path and on
272
+ # the newer cmake versions the LOCATION property isn't supported anymore.
273
+ if (CMAKE_VERSION VERSION_EQUAL 3.0 OR CMAKE_VERSION VERSION_GREATER 3.0)
274
+ set (strip_source_file $<TARGET_FILE:${targetName} >)
275
+ else ()
276
+ get_property (strip_source_file TARGET ${targetName} PROPERTY LOCATION )
277
+ endif ()
278
+
279
+ if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
280
+ set (strip_destination_file ${strip_source_file} .dwarf)
281
+
282
+ add_custom_command (
283
+ TARGET ${targetName}
284
+ POST_BUILD
285
+ VERBATIM
286
+ COMMAND ${DSYMUTIL} --flat --minimize ${strip_source_file}
287
+ COMMAND ${STRIP} -u -r ${strip_source_file}
288
+ COMMENT Stripping symbols from ${strip_source_file} into file ${strip_destination_file}
289
+ )
290
+ else (CMAKE_SYSTEM_NAME STREQUAL Darwin)
291
+ set (strip_destination_file ${strip_source_file} .dbg)
292
+
293
+ add_custom_command (
294
+ TARGET ${targetName}
295
+ POST_BUILD
296
+ VERBATIM
297
+ COMMAND ${OBJCOPY} --only-keep-debug ${strip_source_file} ${strip_destination_file}
298
+ COMMAND ${OBJCOPY} --strip-unneeded ${strip_source_file}
299
+ COMMAND ${OBJCOPY} --add-gnu-debuglink=${strip_destination_file} ${strip_source_file}
300
+ COMMENT Stripping symbols from ${strip_source_file} into file ${strip_destination_file}
301
+ )
302
+ endif (CMAKE_SYSTEM_NAME STREQUAL Darwin)
303
+
304
+ set (${outputFilename} ${strip_destination_file} PARENT_SCOPE)
305
+ endif (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE)
306
+ endif (CLR_CMAKE_PLATFORM_UNIX)
307
+ endfunction ()
308
+
309
+ function (install_clr targetName)
310
+ strip_symbols(${targetName} strip_destination_file)
311
+
312
+ # On the older version of cmake (2.8.12) used on Ubuntu 14.04 the TARGET_FILE
313
+ # generator expression doesn't work correctly returning the wrong path and on
314
+ # the newer cmake versions the LOCATION property isn't supported anymore.
315
+ if (CMAKE_VERSION VERSION_EQUAL 3.0 OR CMAKE_VERSION VERSION_GREATER 3.0)
316
+ set (install_source_file $<TARGET_FILE:${targetName} >)
317
+ else ()
318
+ get_property (install_source_file TARGET ${targetName} PROPERTY LOCATION )
319
+ endif ()
320
+
321
+ install (PROGRAMS ${install_source_file} DESTINATION .)
322
+ if (WIN32 )
323
+ install (FILES ${CMAKE_CURRENT_BINARY_DIR} /$<CONFIG>/${targetName} .pdb DESTINATION PDB)
324
+ else ()
325
+ install (FILES ${strip_destination_file} DESTINATION .)
326
+ endif ()
327
+ endfunction ()
328
+
245
329
# Includes
246
330
247
331
if (CMAKE_CONFIGURATION_TYPES ) # multi-configuration generator?
0 commit comments