[NFC][RemoveDIs] Prefer iterators over inst-pointers in InstCombine
[llvm-project.git] / libunwind / src / CMakeLists.txt
bloba9bf29a8b394a4c81f00ae1ee7e81408cb48d079
1 # Get sources
3 set(LIBUNWIND_CXX_SOURCES
4     libunwind.cpp
5     Unwind-EHABI.cpp
6     Unwind-seh.cpp
7     )
9 if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
10   list(APPEND LIBUNWIND_CXX_SOURCES
11     Unwind_AIXExtras.cpp
12     )
13 endif()
15 set(LIBUNWIND_C_SOURCES
16     UnwindLevel1.c
17     UnwindLevel1-gcc-ext.c
18     Unwind-sjlj.c
19     )
20 set_source_files_properties(${LIBUNWIND_C_SOURCES}
21                             PROPERTIES
22                               COMPILE_FLAGS "-std=c99")
24 set(LIBUNWIND_ASM_SOURCES
25     UnwindRegistersRestore.S
26     UnwindRegistersSave.S
27     )
29 set(LIBUNWIND_HEADERS
30     AddressSpace.hpp
31     assembly.h
32     CompactUnwinder.hpp
33     cet_unwind.h
34     config.h
35     dwarf2.h
36     DwarfInstructions.hpp
37     DwarfParser.hpp
38     EHHeaderParser.hpp
39     FrameHeaderCache.hpp
40     libunwind_ext.h
41     Registers.hpp
42     RWMutex.hpp
43     Unwind-EHABI.h
44     UnwindCursor.hpp
45     ../include/libunwind.h
46     ../include/unwind.h
47     ../include/unwind_itanium.h
48     ../include/unwind_arm_ehabi.h
49     )
50 if(APPLE)
51   list(APPEND LIBUNWIND_HEADERS
52     ../include/mach-o/compact_unwind_encoding.h
53     )
54 endif()
56 if (MSVC_IDE)
57   # Force them all into the headers dir on MSVC, otherwise they end up at
58   # project scope because they don't have extensions.
59   source_group("Header Files" FILES ${LIBUNWIND_HEADERS})
60 endif()
62 set(LIBUNWIND_SOURCES
63     ${LIBUNWIND_CXX_SOURCES}
64     ${LIBUNWIND_C_SOURCES}
65     ${LIBUNWIND_ASM_SOURCES})
67 # Generate library list.
68 add_library_flags_if(LIBUNWIND_HAS_C_LIB c)
69 if (LIBUNWIND_USE_COMPILER_RT)
70   add_library_flags("${LIBUNWIND_BUILTINS_LIBRARY}")
71 else()
72   add_library_flags_if(LIBUNWIND_HAS_GCC_S_LIB gcc_s)
73   add_library_flags_if(LIBUNWIND_HAS_GCC_LIB gcc)
74 endif()
75 add_library_flags_if(LIBUNWIND_HAS_DL_LIB dl)
76 if (LIBUNWIND_ENABLE_THREADS)
77   add_library_flags_if(LIBUNWIND_HAS_PTHREAD_LIB pthread)
78   add_compile_flags_if(LIBUNWIND_WEAK_PTHREAD_LIB -DLIBUNWIND_USE_WEAK_PTHREAD=1)
79 endif()
81 # Setup flags.
82 add_link_flags_if(CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG --unwindlib=none)
84 # MINGW_LIBRARIES is defined in config-ix.cmake
85 add_library_flags_if(MINGW "${MINGW_LIBRARIES}")
87 if (LIBUNWIND_ENABLE_SHARED AND
88     NOT (CXX_SUPPORTS_FNO_EXCEPTIONS_FLAG AND
89          CXX_SUPPORTS_FUNWIND_TABLES_FLAG))
90   message(FATAL_ERROR
91           "Compiler doesn't support generation of unwind tables if exception "
92           "support is disabled.  Building libunwind DSO with runtime dependency "
93           "on C++ ABI library is not supported.")
94 endif()
96 if (APPLE)
97   add_compile_flags("-U__STRICT_ANSI__")
98   add_link_flags("-compatibility_version 1" "-install_name /usr/lib/libunwind.1.dylib")
100   if (CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6")
101     add_link_flags("-current_version ${LIBUNWIND_VERSION}" "/usr/lib/libSystem.B.dylib")
102   endif ()
103 endif ()
105 if (HAIKU)
106   add_library_flags_if(LIBUNWIND_HAS_ROOT_LIB root)
108   add_library_flags_if(LIBUNWIND_HAS_BSD_LIB bsd)
109   add_compile_flags_if(LIBUNWIND_HAS_BSD_LIB -D_LIBUNWIND_USE_HAIKU_BSD_LIB=1)
111   add_compile_flags("-D_DEFAULT_SOURCE")
112   add_compile_flags("-DPT_GNU_EH_FRAME=PT_EH_FRAME")
113 endif ()
115 string(REPLACE ";" " " LIBUNWIND_COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}")
116 string(REPLACE ";" " " LIBUNWIND_CXX_FLAGS "${LIBUNWIND_CXX_FLAGS}")
117 string(REPLACE ";" " " LIBUNWIND_C_FLAGS "${LIBUNWIND_C_FLAGS}")
118 string(REPLACE ";" " " LIBUNWIND_LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}")
120 set_property(SOURCE ${LIBUNWIND_CXX_SOURCES}
121              APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_CXX_FLAGS}")
122 set_property(SOURCE ${LIBUNWIND_C_SOURCES}
123              APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_C_FLAGS}")
125 # NOTE: avoid implicit dependencies on C++ runtimes.  libunwind uses C++ for
126 # ease, but does not rely on C++ at runtime.
127 set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
129 include(WarningFlags)
131 # Build the shared library.
132 add_library(unwind_shared_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
133 cxx_add_warning_flags(unwind_shared_objects ${LIBUNWIND_ENABLE_WERROR} ${LIBUNWIND_ENABLE_PEDANTIC})
134 if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
135   target_compile_options(unwind_shared_objects PRIVATE /GR-)
136 else()
137   target_compile_options(unwind_shared_objects PRIVATE -fno-rtti)
138 endif()
139 target_link_libraries(unwind_shared_objects PRIVATE unwind-headers ${LIBUNWIND_LIBRARIES})
140 target_compile_options(unwind_shared_objects PUBLIC "${LIBUNWIND_ADDITIONAL_COMPILE_FLAGS}")
141 target_link_libraries(unwind_shared_objects PUBLIC "${LIBUNWIND_ADDITIONAL_LIBRARIES}")
142 set_target_properties(unwind_shared_objects
143   PROPERTIES
144     CXX_EXTENSIONS OFF
145     CXX_STANDARD 11
146     CXX_STANDARD_REQUIRED ON
147     COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
149 if (CMAKE_POSITION_INDEPENDENT_CODE OR NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
150   set_target_properties(unwind_shared_objects PROPERTIES POSITION_INDEPENDENT_CODE ON) # must set manually because it's an object library
151 endif()
153 if (LIBUNWIND_ENABLE_SHARED)
154   add_library(unwind_shared SHARED)
155   target_link_libraries(unwind_shared PUBLIC unwind_shared_objects)
156   set_target_properties(unwind_shared
157     PROPERTIES
158       LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
159       LINKER_LANGUAGE C
160       OUTPUT_NAME "${LIBUNWIND_SHARED_OUTPUT_NAME}"
161       VERSION "1.0"
162       SOVERSION "1"
163   )
165   list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_shared")
166   if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
167     list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
168   endif()
169 endif()
171 # Build the static library.
172 add_library(unwind_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
173 cxx_add_warning_flags(unwind_static_objects ${LIBUNWIND_ENABLE_WERROR} ${LIBUNWIND_ENABLE_PEDANTIC})
174 if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
175   target_compile_options(unwind_static_objects PRIVATE /GR-)
176 else()
177   target_compile_options(unwind_static_objects PRIVATE -fno-rtti)
178 endif()
179 target_link_libraries(unwind_static_objects PRIVATE unwind-headers ${LIBUNWIND_LIBRARIES})
180 target_compile_options(unwind_static_objects PUBLIC "${LIBUNWIND_ADDITIONAL_COMPILE_FLAGS}")
181 target_link_libraries(unwind_static_objects PUBLIC "${LIBUNWIND_ADDITIONAL_LIBRARIES}")
182 set_target_properties(unwind_static_objects
183   PROPERTIES
184     CXX_EXTENSIONS OFF
185     CXX_STANDARD 11
186     CXX_STANDARD_REQUIRED ON
187     COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
190 if(LIBUNWIND_HIDE_SYMBOLS)
191   target_add_compile_flags_if_supported(unwind_static_objects PRIVATE -fvisibility=hidden)
192   target_add_compile_flags_if_supported(unwind_static_objects PRIVATE -fvisibility-global-new-delete-hidden)
193   target_compile_definitions(unwind_static_objects PRIVATE _LIBUNWIND_HIDE_SYMBOLS)
194 endif()
196 if (LIBUNWIND_ENABLE_STATIC)
197   add_library(unwind_static STATIC)
198   target_link_libraries(unwind_static PUBLIC unwind_static_objects)
199   set_target_properties(unwind_static
200     PROPERTIES
201       LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
202       LINKER_LANGUAGE C
203       OUTPUT_NAME "${LIBUNWIND_STATIC_OUTPUT_NAME}"
204   )
206   list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static")
207   if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
208     list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
209   endif()
210 endif()
212 # Add a meta-target for both libraries.
213 add_custom_target(unwind DEPENDS ${LIBUNWIND_BUILD_TARGETS})
215 if (LIBUNWIND_INSTALL_LIBRARY)
216   install(TARGETS ${LIBUNWIND_INSTALL_TARGETS}
217     LIBRARY DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind
218     ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind
219     RUNTIME DESTINATION ${LIBUNWIND_INSTALL_RUNTIME_DIR} COMPONENT unwind)
220 endif()
222 if (NOT CMAKE_CONFIGURATION_TYPES AND LIBUNWIND_INSTALL_LIBRARY)
223   add_custom_target(install-unwind
224     DEPENDS unwind
225     COMMAND "${CMAKE_COMMAND}"
226             -DCMAKE_INSTALL_COMPONENT=unwind
227             -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
228   add_custom_target(install-unwind-stripped
229     DEPENDS unwind
230     COMMAND "${CMAKE_COMMAND}"
231             -DCMAKE_INSTALL_COMPONENT=unwind
232             -DCMAKE_INSTALL_DO_STRIP=1
233             -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
234   if(LIBUNWIND_INSTALL_HEADERS)
235     add_dependencies(install-unwind install-unwind-headers)
236     add_dependencies(install-unwind-stripped install-unwind-headers-stripped)
237   endif()
238 endif()