[AMDGPU] prevent shrinking udiv/urem if either operand is in (SignedMax,UnsignedMax...
[llvm-project.git] / libunwind / src / CMakeLists.txt
blob2e18b109656331e5610510b3b8454efc3d4816f0
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     Unwind-wasm.c
20     )
21 set_source_files_properties(${LIBUNWIND_C_SOURCES}
22                             PROPERTIES
23                               COMPILE_FLAGS "-std=c99")
25 set(LIBUNWIND_ASM_SOURCES
26     UnwindRegistersRestore.S
27     UnwindRegistersSave.S
28     )
30 set(LIBUNWIND_HEADERS
31     AddressSpace.hpp
32     assembly.h
33     CompactUnwinder.hpp
34     cet_unwind.h
35     config.h
36     dwarf2.h
37     DwarfInstructions.hpp
38     DwarfParser.hpp
39     EHHeaderParser.hpp
40     FrameHeaderCache.hpp
41     libunwind_ext.h
42     Registers.hpp
43     RWMutex.hpp
44     Unwind-EHABI.h
45     UnwindCursor.hpp
46     ../include/libunwind.h
47     ../include/unwind.h
48     ../include/unwind_itanium.h
49     ../include/unwind_arm_ehabi.h
50     )
51 if(APPLE)
52   list(APPEND LIBUNWIND_HEADERS
53     ../include/mach-o/compact_unwind_encoding.h
54     )
55 endif()
57 if (MSVC_IDE)
58   # Force them all into the headers dir on MSVC, otherwise they end up at
59   # project scope because they don't have extensions.
60   source_group("Header Files" FILES ${LIBUNWIND_HEADERS})
61 endif()
63 set(LIBUNWIND_SOURCES
64     ${LIBUNWIND_CXX_SOURCES}
65     ${LIBUNWIND_C_SOURCES}
66     ${LIBUNWIND_ASM_SOURCES})
68 # Generate library list.
69 if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
70   add_link_flags_if_supported(-nostdlib++)
71 else()
72   if (LIBUNWIND_USE_COMPILER_RT)
73     add_library_flags("${LIBUNWIND_BUILTINS_LIBRARY}")
74   else()
75     add_library_flags_if(LIBUNWIND_HAS_GCC_S_LIB gcc_s)
76     add_library_flags_if(LIBUNWIND_HAS_GCC_LIB gcc)
77   endif()
78   add_library_flags_if(LIBUNWIND_HAS_C_LIB c)
79 endif()
81 if (NOT APPLE)
82   add_library_flags_if(LIBUNWIND_HAS_DL_LIB dl)
83 endif()
85 if (LIBUNWIND_ENABLE_THREADS AND NOT APPLE)
86     add_library_flags_if(LIBUNWIND_HAS_PTHREAD_LIB pthread)
87 endif()
89 if (LIBUNWIND_ENABLE_THREADS)
90   add_compile_flags_if(LIBUNWIND_WEAK_PTHREAD_LIB -DLIBUNWIND_USE_WEAK_PTHREAD=1)
91 endif()
93 # Setup flags.
94 add_link_flags_if(CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG --unwindlib=none)
96 # MINGW_LIBRARIES is defined in config-ix.cmake
97 add_library_flags_if(MINGW "${MINGW_LIBRARIES}")
99 if (LIBUNWIND_ENABLE_SHARED AND
100     NOT (CXX_SUPPORTS_FNO_EXCEPTIONS_FLAG AND
101          CXX_SUPPORTS_FUNWIND_TABLES_FLAG))
102   message(FATAL_ERROR
103           "Compiler doesn't support generation of unwind tables if exception "
104           "support is disabled.  Building libunwind DSO with runtime dependency "
105           "on C++ ABI library is not supported.")
106 endif()
108 if (HAIKU)
109   add_library_flags_if(LIBUNWIND_HAS_ROOT_LIB root)
111   add_library_flags_if(LIBUNWIND_HAS_BSD_LIB bsd)
112   add_compile_flags_if(LIBUNWIND_HAS_BSD_LIB -D_LIBUNWIND_USE_HAIKU_BSD_LIB=1)
114   add_compile_flags("-D_DEFAULT_SOURCE")
115   add_compile_flags("-DPT_GNU_EH_FRAME=PT_EH_FRAME")
116 endif ()
118 string(REPLACE ";" " " LIBUNWIND_COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}")
119 string(REPLACE ";" " " LIBUNWIND_CXX_FLAGS "${LIBUNWIND_CXX_FLAGS}")
120 string(REPLACE ";" " " LIBUNWIND_C_FLAGS "${LIBUNWIND_C_FLAGS}")
121 string(REPLACE ";" " " LIBUNWIND_LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}")
123 set_property(SOURCE ${LIBUNWIND_CXX_SOURCES}
124              APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_CXX_FLAGS}")
125 set_property(SOURCE ${LIBUNWIND_C_SOURCES}
126              APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_C_FLAGS}")
128 # NOTE: avoid implicit dependencies on C++ runtimes.  libunwind uses C++ for
129 # ease, but does not rely on C++ at runtime.
130 set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
132 include(WarningFlags)
134 # Build the shared library.
135 add_library(unwind_shared_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
136 cxx_add_warning_flags(unwind_shared_objects ${LIBUNWIND_ENABLE_WERROR} ${LIBUNWIND_ENABLE_PEDANTIC})
137 if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
138   target_compile_options(unwind_shared_objects PRIVATE /GR-)
139 else()
140   target_compile_options(unwind_shared_objects PRIVATE -fno-rtti)
141 endif()
142 target_link_libraries(unwind_shared_objects PRIVATE unwind-headers ${LIBUNWIND_LIBRARIES})
143 target_compile_options(unwind_shared_objects PUBLIC "${LIBUNWIND_ADDITIONAL_COMPILE_FLAGS}")
144 target_link_libraries(unwind_shared_objects PUBLIC "${LIBUNWIND_ADDITIONAL_LIBRARIES}")
145 set_target_properties(unwind_shared_objects
146   PROPERTIES
147     CXX_EXTENSIONS OFF
148     CXX_STANDARD 17
149     CXX_STANDARD_REQUIRED ON
150     COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
152 if (CMAKE_POSITION_INDEPENDENT_CODE OR NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
153   set_target_properties(unwind_shared_objects PROPERTIES POSITION_INDEPENDENT_CODE ON) # must set manually because it's an object library
154 endif()
156 add_library(unwind_shared SHARED)
157 target_link_libraries(unwind_shared PUBLIC unwind_shared_objects)
158 set_target_properties(unwind_shared
159   PROPERTIES
160     EXCLUDE_FROM_ALL "$<IF:$<BOOL:${LIBUNWIND_ENABLE_SHARED}>,FALSE,TRUE>"
161     LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
162     LINKER_LANGUAGE C
163     OUTPUT_NAME "${LIBUNWIND_SHARED_OUTPUT_NAME}"
164     VERSION     "${LIBUNWIND_LIBRARY_VERSION}"
165     SOVERSION   "1"
168 if (LIBUNWIND_ENABLE_SHARED)
169   list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_shared")
170 endif()
171 if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
172   list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
173 endif()
175 # Build the static library.
176 add_library(unwind_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
177 cxx_add_warning_flags(unwind_static_objects ${LIBUNWIND_ENABLE_WERROR} ${LIBUNWIND_ENABLE_PEDANTIC})
178 if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
179   target_compile_options(unwind_static_objects PRIVATE /GR-)
180 else()
181   target_compile_options(unwind_static_objects PRIVATE -fno-rtti)
182 endif()
183 target_link_libraries(unwind_static_objects PRIVATE unwind-headers ${LIBUNWIND_LIBRARIES})
184 target_compile_options(unwind_static_objects PUBLIC "${LIBUNWIND_ADDITIONAL_COMPILE_FLAGS}")
185 target_link_libraries(unwind_static_objects PUBLIC "${LIBUNWIND_ADDITIONAL_LIBRARIES}")
186 set_target_properties(unwind_static_objects
187   PROPERTIES
188     CXX_EXTENSIONS OFF
189     CXX_STANDARD 17
190     CXX_STANDARD_REQUIRED ON
191     COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
194 if(LIBUNWIND_HIDE_SYMBOLS)
195   target_add_compile_flags_if_supported(unwind_static_objects PRIVATE -fvisibility=hidden)
196   target_add_compile_flags_if_supported(unwind_static_objects PRIVATE -fvisibility-global-new-delete=force-hidden)
197   if (NOT CXX_SUPPORTS_FVISIBILITY_GLOBAL_NEW_DELETE_EQ_FORCE_HIDDEN_FLAG)
198     target_add_compile_flags_if_supported(unwind_static_objects PRIVATE -fvisibility-global-new-delete-hidden)
199   endif()
200   target_compile_definitions(unwind_static_objects PRIVATE _LIBUNWIND_HIDE_SYMBOLS)
201 endif()
203 add_library(unwind_static STATIC)
204 target_link_libraries(unwind_static PUBLIC unwind_static_objects)
205 set_target_properties(unwind_static
206   PROPERTIES
207     EXCLUDE_FROM_ALL "$<IF:$<BOOL:${LIBUNWIND_ENABLE_STATIC}>,FALSE,TRUE>"
208     LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
209     LINKER_LANGUAGE C
210     OUTPUT_NAME "${LIBUNWIND_STATIC_OUTPUT_NAME}"
213 if (LIBUNWIND_ENABLE_STATIC)
214   list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static")
215 endif()
216 if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
217   list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
218 endif()
220 # Add a meta-target for both libraries.
221 add_custom_target(unwind DEPENDS ${LIBUNWIND_BUILD_TARGETS})
223 if (LIBUNWIND_INSTALL_LIBRARY)
224   install(TARGETS ${LIBUNWIND_INSTALL_TARGETS}
225     LIBRARY DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind
226     ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind
227     RUNTIME DESTINATION ${LIBUNWIND_INSTALL_RUNTIME_DIR} COMPONENT unwind)
228 endif()
230 if (NOT CMAKE_CONFIGURATION_TYPES AND LIBUNWIND_INSTALL_LIBRARY)
231   add_custom_target(install-unwind
232     DEPENDS unwind
233     COMMAND "${CMAKE_COMMAND}"
234             -DCMAKE_INSTALL_COMPONENT=unwind
235             -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
236   add_custom_target(install-unwind-stripped
237     DEPENDS unwind
238     COMMAND "${CMAKE_COMMAND}"
239             -DCMAKE_INSTALL_COMPONENT=unwind
240             -DCMAKE_INSTALL_DO_STRIP=1
241             -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
242   if(LIBUNWIND_INSTALL_HEADERS)
243     add_dependencies(install-unwind install-unwind-headers)
244     add_dependencies(install-unwind-stripped install-unwind-headers-stripped)
245   endif()
246 endif()