11cmake_minimum_required (VERSION  2.8.12.2)
22
3+ if (CMAKE_SYSTEM_NAME  STREQUAL  Darwin)
4+   # On OSX, we use the libunwind that's part of the OS 
5+   set (CLR_USE_SYSTEM_LIBUNWIND 1)
6+ endif (CMAKE_SYSTEM_NAME  STREQUAL  Darwin)
7+ 
38include_directories (SYSTEM  /usr/local/include )
4- include_directories (libunwind/include )
59
610add_compile_options (-fPIC)
711
8- if (NOT  CMAKE_SYSTEM_NAME  STREQUAL  Darwin)
12+ if (NOT  CLR_USE_SYSTEM_LIBUNWIND)
13+   include_directories (libunwind/include )
914  add_subdirectory (libunwind)
10- endif (NOT  CMAKE_SYSTEM_NAME   STREQUAL  Darwin )
15+ endif (NOT  CLR_USE_SYSTEM_LIBUNWIND )
1116
1217include (configure.cmake)
1318
@@ -240,10 +245,9 @@ set(SOURCES
240245  thread/tls.cpp
241246)
242247
243- if (NOT  CMAKE_SYSTEM_NAME  STREQUAL  Darwin)
244-   # On OSX, we use the libunwind that's part of the OS 
248+ if (NOT  CLR_USE_SYSTEM_LIBUNWIND)
245249  set (LIBUNWIND_OBJECTS $<TARGET_OBJECTS:libunwind>)
246- endif (NOT  CMAKE_SYSTEM_NAME   STREQUAL  Darwin )
250+ endif (NOT  CLR_USE_SYSTEM_LIBUNWIND )
247251
248252add_library (coreclrpal
249253  STATIC 
@@ -267,10 +271,14 @@ if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
267271endif (CMAKE_SYSTEM_NAME  STREQUAL  Darwin)
268272
269273if (CMAKE_SYSTEM_NAME  STREQUAL  FreeBSD)
274+   if (CLR_USE_SYSTEM_LIBUNWIND)
275+     find_library (UNWIND unwind)
276+   endif ()
270277  find_library (INTL intl)
271278  target_link_libraries (coreclrpal
272279    pthread
273280    rt
281+     ${UNWIND} 
274282    ${INTL} 
275283  )
276284endif (CMAKE_SYSTEM_NAME  STREQUAL  FreeBSD)
@@ -303,7 +311,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL Linux)
303311      ${LZMA} )
304312  endif ()
305313
306- 
307314  if (CLR_MAKE_PLATFORM_ANDROID)
308315    find_library (ANDROID_SUPPORT NAMES  android-support)
309316    find_library (ANDROID_GLOB NAMES  android-glob)
@@ -326,20 +333,56 @@ if(CMAKE_SYSTEM_NAME STREQUAL Linux)
326333    dl
327334  )
328335
329- 
330336  if (NOT  INTL STREQUAL  INTL-NOTFOUND )
331337    target_link_libraries (coreclrpal ${INTL} )
332338  endif (NOT  INTL STREQUAL  INTL-NOTFOUND )
333339
340+   if (CLR_USE_SYSTEM_LIBUNWIND)
341+     if (PAL_CMAKE_PLATFORM_ARCH_ARM)
342+       find_library (UNWIND_ARCH NAMES  unwind-arm)
343+     endif ()
344+ 
345+     if (PAL_CMAKE_PLATFORM_ARCH_ARM64)
346+       find_library (UNWIND_ARCH NAMES  unwind-aarch64)
347+     endif ()
348+ 
349+     if (PAL_CMAKE_PLATFORM_ARCH_AMD64)
350+       find_library (UNWIND_ARCH NAMES  unwind-x86_64)
351+     endif ()
352+ 
353+     if (NOT  UNWIND_ARCH STREQUAL  UNWIND_ARCH-NOTFOUND )
354+       target_link_libraries (coreclrpal ${UNWIND_ARCH} )
355+     endif ()
356+ 
357+     find_library (UNWIND_GENERIC NAMES  unwind-generic)
358+ 
359+     if (NOT  UNWIND_GENERIC STREQUAL  UNWIND_GENERIC-NOTFOUND )
360+       target_link_libraries (coreclrpal ${UNWIND_GENERIC} )
361+     endif ()
362+ 
363+     find_library (UNWIND NAMES  unwind)
364+ 
365+     if (UNWIND STREQUAL  UNWIND-NOTFOUND )
366+       message (FATAL_ERROR "Cannot find libunwind. Try installing libunwind8-dev or libunwind-devel." )
367+     endif ()
368+ 
369+     target_link_libraries (coreclrpal ${UNWIND} )
370+ 
371+   endif (CLR_USE_SYSTEM_LIBUNWIND)
372+ 
334373endif (CMAKE_SYSTEM_NAME  STREQUAL  Linux)
335374
336375if (CMAKE_SYSTEM_NAME  STREQUAL  NetBSD)
376+   if  (CLR_USE_SYSTEM_LIBUNWIND)
377+     find_library (UNWIND unwind)
378+   endif ()
337379  add_definitions (-D_KMEMUSER)
338380  find_library (INTL intl)
339381  find_library (KVM kvm)
340382  target_link_libraries (coreclrpal
341383    pthread
342384    rt
385+     ${UNWIND} 
343386    ${INTL} 
344387    ${KVM} 
345388  )
0 commit comments