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