CMakeLists.txt 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. # Get sources
  2. set(LIBUNWIND_CXX_SOURCES
  3. libunwind.cpp
  4. Unwind-EHABI.cpp
  5. Unwind-seh.cpp
  6. )
  7. if(APPLE)
  8. list(APPEND LIBUNWIND_CXX_SOURCES
  9. Unwind_AppleExtras.cpp
  10. )
  11. endif()
  12. set(LIBUNWIND_C_SOURCES
  13. UnwindLevel1.c
  14. UnwindLevel1-gcc-ext.c
  15. Unwind-sjlj.c
  16. )
  17. set_source_files_properties(${LIBUNWIND_C_SOURCES}
  18. PROPERTIES
  19. COMPILE_FLAGS "-std=c99")
  20. set(LIBUNWIND_ASM_SOURCES
  21. UnwindRegistersRestore.S
  22. UnwindRegistersSave.S
  23. )
  24. # See add_asm_sources() in compiler-rt for explanation of this workaround.
  25. if((APPLE AND CMAKE_VERSION VERSION_LESS 3.19) OR (MINGW AND CMAKE_VERSION VERSION_LESS 3.17))
  26. set_source_files_properties(${LIBUNWIND_ASM_SOURCES} PROPERTIES LANGUAGE C)
  27. endif()
  28. set(LIBUNWIND_HEADERS
  29. AddressSpace.hpp
  30. assembly.h
  31. CompactUnwinder.hpp
  32. config.h
  33. dwarf2.h
  34. DwarfInstructions.hpp
  35. DwarfParser.hpp
  36. EHHeaderParser.hpp
  37. FrameHeaderCache.hpp
  38. libunwind_ext.h
  39. Registers.hpp
  40. RWMutex.hpp
  41. Unwind-EHABI.h
  42. UnwindCursor.hpp
  43. ../include/libunwind.h
  44. ../include/unwind.h
  45. )
  46. if(APPLE)
  47. list(APPEND LIBUNWIND_HEADERS
  48. ../include/mach-o/compact_unwind_encoding.h
  49. )
  50. endif()
  51. if (MSVC_IDE)
  52. # Force them all into the headers dir on MSVC, otherwise they end up at
  53. # project scope because they don't have extensions.
  54. source_group("Header Files" FILES ${LIBUNWIND_HEADERS})
  55. endif()
  56. set(LIBUNWIND_SOURCES
  57. ${LIBUNWIND_CXX_SOURCES}
  58. ${LIBUNWIND_C_SOURCES}
  59. ${LIBUNWIND_ASM_SOURCES})
  60. # Generate library list.
  61. add_library_flags_if(LIBUNWIND_HAS_C_LIB c)
  62. if (LIBUNWIND_USE_COMPILER_RT)
  63. add_library_flags("${LIBUNWIND_BUILTINS_LIBRARY}")
  64. else()
  65. add_library_flags_if(LIBUNWIND_HAS_GCC_S_LIB gcc_s)
  66. add_library_flags_if(LIBUNWIND_HAS_GCC_LIB gcc)
  67. endif()
  68. add_library_flags_if(LIBUNWIND_HAS_DL_LIB dl)
  69. if (LIBUNWIND_ENABLE_THREADS)
  70. add_library_flags_if(LIBUNWIND_HAS_PTHREAD_LIB pthread)
  71. add_compile_flags_if(LIBUNWIND_WEAK_PTHREAD_LIB -DLIBUNWIND_USE_WEAK_PTHREAD=1)
  72. endif()
  73. # Setup flags.
  74. if (LIBUNWIND_SUPPORTS_NOSTDLIBXX_FLAG)
  75. add_link_flags_if_supported(-nostdlib++)
  76. else()
  77. add_link_flags_if_supported(-nodefaultlibs)
  78. endif()
  79. # MINGW_LIBRARIES is defined in config-ix.cmake
  80. add_library_flags_if(MINGW "${MINGW_LIBRARIES}")
  81. if (LIBUNWIND_ENABLE_SHARED AND
  82. NOT (LIBUNWIND_SUPPORTS_FNO_EXCEPTIONS_FLAG AND
  83. LIBUNWIND_SUPPORTS_FUNWIND_TABLES_FLAG))
  84. message(FATAL_ERROR
  85. "Compiler doesn't support generation of unwind tables if exception "
  86. "support is disabled. Building libunwind DSO with runtime dependency "
  87. "on C++ ABI library is not supported.")
  88. endif()
  89. if (APPLE)
  90. add_compile_flags("-U__STRICT_ANSI__")
  91. add_link_flags("-compatibility_version 1" "-install_name /usr/lib/libunwind.1.dylib")
  92. if (CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6")
  93. add_link_flags("-current_version ${LIBUNWIND_VERSION}" "/usr/lib/libSystem.B.dylib")
  94. endif ()
  95. endif ()
  96. string(REPLACE ";" " " LIBUNWIND_COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}")
  97. string(REPLACE ";" " " LIBUNWIND_CXX_FLAGS "${LIBUNWIND_CXX_FLAGS}")
  98. string(REPLACE ";" " " LIBUNWIND_C_FLAGS "${LIBUNWIND_C_FLAGS}")
  99. string(REPLACE ";" " " LIBUNWIND_LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}")
  100. set_property(SOURCE ${LIBUNWIND_CXX_SOURCES}
  101. APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_CXX_FLAGS}")
  102. set_property(SOURCE ${LIBUNWIND_C_SOURCES}
  103. APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_C_FLAGS}")
  104. # NOTE: avoid implicit dependencies on C++ runtimes. libunwind uses C++ for
  105. # ease, but does not rely on C++ at runtime.
  106. set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
  107. # Build the shared library.
  108. if (LIBUNWIND_ENABLE_SHARED)
  109. add_library(unwind_shared SHARED ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
  110. if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
  111. target_compile_options(unwind_shared PRIVATE /GR-)
  112. else()
  113. target_compile_options(unwind_shared PRIVATE -fno-rtti)
  114. endif()
  115. target_link_libraries(unwind_shared PRIVATE ${LIBUNWIND_LIBRARIES})
  116. set_target_properties(unwind_shared PROPERTIES
  117. CXX_EXTENSIONS OFF
  118. CXX_STANDARD 11
  119. CXX_STANDARD_REQUIRED ON
  120. COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
  121. LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
  122. LINKER_LANGUAGE C
  123. OUTPUT_NAME "unwind"
  124. VERSION "1.0"
  125. SOVERSION "1")
  126. list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_shared")
  127. if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
  128. list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
  129. endif()
  130. endif()
  131. # Build the static library.
  132. if (LIBUNWIND_ENABLE_STATIC)
  133. add_library(unwind_static STATIC ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
  134. if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
  135. target_compile_options(unwind_static PRIVATE /GR-)
  136. else()
  137. target_compile_options(unwind_static PRIVATE -fno-rtti)
  138. endif()
  139. target_link_libraries(unwind_static PRIVATE ${LIBUNWIND_LIBRARIES})
  140. set_target_properties(unwind_static PROPERTIES
  141. CXX_EXTENSIONS OFF
  142. CXX_STANDARD 11
  143. CXX_STANDARD_REQUIRED ON
  144. COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
  145. LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
  146. LINKER_LANGUAGE C
  147. OUTPUT_NAME "unwind")
  148. if(LIBUNWIND_HIDE_SYMBOLS)
  149. append_flags_if_supported(UNWIND_STATIC_LIBRARY_FLAGS -fvisibility=hidden)
  150. append_flags_if_supported(UNWIND_STATIC_LIBRARY_FLAGS -fvisibility-global-new-delete-hidden)
  151. target_compile_options(unwind_static PRIVATE ${UNWIND_STATIC_LIBRARY_FLAGS})
  152. target_compile_definitions(unwind_static PRIVATE _LIBUNWIND_HIDE_SYMBOLS)
  153. endif()
  154. list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static")
  155. if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
  156. list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
  157. endif()
  158. endif()
  159. # Add a meta-target for both libraries.
  160. add_custom_target(unwind DEPENDS ${LIBUNWIND_BUILD_TARGETS})
  161. if (LIBUNWIND_INSTALL_LIBRARY)
  162. install(TARGETS ${LIBUNWIND_INSTALL_TARGETS}
  163. LIBRARY DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind
  164. ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind
  165. RUNTIME DESTINATION bin COMPONENT unwind)
  166. endif()
  167. if (NOT CMAKE_CONFIGURATION_TYPES AND LIBUNWIND_INSTALL_LIBRARY)
  168. add_custom_target(install-unwind
  169. DEPENDS unwind
  170. COMMAND "${CMAKE_COMMAND}"
  171. -DCMAKE_INSTALL_COMPONENT=unwind
  172. -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
  173. add_custom_target(install-unwind-stripped
  174. DEPENDS unwind
  175. COMMAND "${CMAKE_COMMAND}"
  176. -DCMAKE_INSTALL_COMPONENT=unwind
  177. -DCMAKE_INSTALL_DO_STRIP=1
  178. -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
  179. endif()