Home | History | Annotate | Download | only in src
      1 # Get sources
      2 
      3 set(LIBUNWIND_CXX_SOURCES
      4     libunwind.cpp
      5     Unwind-EHABI.cpp
      6     Unwind-seh.cpp)
      7 unwind_append_if(LIBUNWIND_CXX_SOURCES APPLE Unwind_AppleExtras.cpp)
      8 
      9 set(LIBUNWIND_C_SOURCES
     10     UnwindLevel1.c
     11     UnwindLevel1-gcc-ext.c
     12     Unwind-sjlj.c)
     13 set_source_files_properties(${LIBUNWIND_C_SOURCES}
     14                             PROPERTIES
     15                               COMPILE_FLAGS "-std=c99")
     16 
     17 set(LIBUNWIND_ASM_SOURCES
     18     UnwindRegistersRestore.S
     19     UnwindRegistersSave.S)
     20 set_source_files_properties(${LIBUNWIND_ASM_SOURCES}
     21                             PROPERTIES
     22                               LANGUAGE C)
     23 
     24 set(LIBUNWIND_HEADERS
     25     AddressSpace.hpp
     26     assembly.h
     27     CompactUnwinder.hpp
     28     config.h
     29     dwarf2.h
     30     DwarfInstructions.hpp
     31     DwarfParser.hpp
     32     libunwind_ext.h
     33     Registers.hpp
     34     RWMutex.hpp
     35     UnwindCursor.hpp
     36     ${CMAKE_CURRENT_SOURCE_DIR}/../include/libunwind.h
     37     ${CMAKE_CURRENT_SOURCE_DIR}/../include/unwind.h)
     38 
     39 unwind_append_if(LIBUNWIND_HEADERS APPLE
     40           "${CMAKE_CURRENT_SOURCE_DIR}/../include/mach-o/compact_unwind_encoding.h")
     41 
     42 if (MSVC_IDE)
     43   # Force them all into the headers dir on MSVC, otherwise they end up at
     44   # project scope because they don't have extensions.
     45   source_group("Header Files" FILES ${LIBUNWIND_HEADERS})
     46 endif()
     47 
     48 set(LIBUNWIND_SOURCES
     49     ${LIBUNWIND_CXX_SOURCES}
     50     ${LIBUNWIND_C_SOURCES}
     51     ${LIBUNWIND_ASM_SOURCES})
     52 
     53 # Generate library list.
     54 set(libraries)
     55 unwind_append_if(libraries LIBUNWIND_HAS_C_LIB c)
     56 if (LIBUNWIND_USE_COMPILER_RT)
     57   list(APPEND libraries "${LIBUNWIND_BUILTINS_LIBRARY}")
     58 else()
     59   unwind_append_if(libraries LIBUNWIND_HAS_GCC_S_LIB gcc_s)
     60   unwind_append_if(libraries LIBUNWIND_HAS_GCC_LIB gcc)
     61 endif()
     62 unwind_append_if(libraries LIBUNWIND_HAS_DL_LIB dl)
     63 if (LIBUNWIND_ENABLE_THREADS)
     64   unwind_append_if(libraries LIBUNWIND_HAS_PTHREAD_LIB pthread)
     65 endif()
     66 
     67 # Setup flags.
     68 unwind_append_if(LIBUNWIND_CXX_FLAGS LIBUNWIND_HAS_NO_RTTI_FLAG -fno-rtti)
     69 
     70 unwind_append_if(LIBUNWIND_LINK_FLAGS LIBUNWIND_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs)
     71 
     72 # MINGW_LIBRARIES is defined in config-ix.cmake
     73 unwind_append_if(libraries MINGW "${MINGW_LIBRARIES}")
     74 
     75 if (LIBUNWIND_HAS_NO_EXCEPTIONS_FLAG AND LIBUNWIND_HAS_FUNWIND_TABLES)
     76   list(APPEND LIBUNWIND_COMPILE_FLAGS -fno-exceptions)
     77   list(APPEND LIBUNWIND_COMPILE_FLAGS -funwind-tables)
     78 elseif (LIBUNWIND_ENABLE_SHARED)
     79   message(FATAL_ERROR
     80           "Compiler doesn't support generation of unwind tables if exception "
     81           "support is disabled.  Building libunwind DSO with runtime dependency "
     82           "on C++ ABI library is not supported.")
     83 endif()
     84 
     85 if (APPLE)
     86   list(APPEND LIBUNWIND_COMPILE_FLAGS "-U__STRICT_ANSI__")
     87   list(APPEND LIBUNWIND_LINK_FLAGS
     88        "-compatibility_version 1"
     89        "-install_name /usr/lib/libunwind.1.dylib")
     90 
     91   if (CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6")
     92     list(APPEND LIBUNWIND_LINK_FLAGS
     93          "-current_version ${LIBUNWIND_VERSION}"
     94          "/usr/lib/libSystem.B.dylib")
     95   endif ()
     96 endif ()
     97 
     98 string(REPLACE ";" " " LIBUNWIND_COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}")
     99 string(REPLACE ";" " " LIBUNWIND_CXX_FLAGS "${LIBUNWIND_CXX_FLAGS}")
    100 string(REPLACE ";" " " LIBUNWIND_C_FLAGS "${LIBUNWIND_C_FLAGS}")
    101 string(REPLACE ";" " " LIBUNWIND_LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}")
    102 
    103 set_property(SOURCE ${LIBUNWIND_CXX_SOURCES}
    104              APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_CXX_FLAGS}")
    105 set_property(SOURCE ${LIBUNWIND_C_SOURCES}
    106              APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_C_FLAGS}")
    107 
    108 macro(unwind_object_library name)
    109   cmake_parse_arguments(ARGS "" "" "DEFINES;FLAGS" ${ARGN})
    110 
    111 # Add a object library that contains the compiled source files.
    112   add_library(${name} OBJECT ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
    113 
    114   if(ARGS_DEFINES)
    115     target_compile_definitions(${name} PRIVATE ${ARGS_DEFINES})
    116   endif()
    117 
    118   set_target_properties(${name}
    119                         PROPERTIES
    120                           COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
    121                           POSITION_INDEPENDENT_CODE ON)
    122 
    123   if(ARGS_FLAGS)
    124     target_compile_options(${name} PRIVATE ${ARGS_FLAGS})
    125   endif()
    126 endmacro()
    127 
    128 if(LIBUNWIND_HERMETIC_STATIC_LIBRARY)
    129   append_flags_if_supported(UNWIND_STATIC_OBJECTS_FLAGS -fvisibility=hidden)
    130   append_flags_if_supported(UNWIND_STATIC_OBJECTS_FLAGS -fvisibility-global-new-delete-hidden)
    131   unwind_object_library(unwind_static_objects
    132     DEFINES _LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS
    133     FLAGS ${UNWIND_STATIC_OBJECTS_FLAGS})
    134   unwind_object_library(unwind_shared_objects)
    135   set(unwind_static_sources $<TARGET_OBJECTS:unwind_static_objects>)
    136   set(unwind_shared_sources $<TARGET_OBJECTS:unwind_shared_objects>)
    137 else()
    138   unwind_object_library(unwind_objects)
    139   set(unwind_static_sources $<TARGET_OBJECTS:unwind_objects>)
    140   set(unwind_shared_sources $<TARGET_OBJECTS:unwind_objects>)
    141 endif()
    142 
    143 # Build the shared library.
    144 if (LIBUNWIND_ENABLE_SHARED)
    145   add_library(unwind_shared SHARED ${unwind_shared_sources})
    146   if(COMMAND llvm_setup_rpath)
    147     llvm_setup_rpath(unwind_shared)
    148   endif()
    149   target_link_libraries(unwind_shared PRIVATE ${libraries})
    150   set_target_properties(unwind_shared
    151                         PROPERTIES
    152                           LINK_FLAGS    "${LIBUNWIND_LINK_FLAGS}"
    153                           OUTPUT_NAME   "unwind"
    154                           VERSION       "1.0"
    155                           SOVERSION     "1")
    156   list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_shared")
    157   if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
    158     list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
    159   endif()
    160 endif()
    161 
    162 # Build the static library.
    163 if (LIBUNWIND_ENABLE_STATIC)
    164   add_library(unwind_static STATIC ${unwind_static_sources})
    165   target_link_libraries(unwind_static PRIVATE ${libraries})
    166   set_target_properties(unwind_static
    167                         PROPERTIES
    168                           LINK_FLAGS    "${LIBUNWIND_LINK_FLAGS}"
    169                           OUTPUT_NAME   "unwind")
    170   list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static")
    171   if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
    172     list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
    173   endif()
    174 endif()
    175 
    176 # Add a meta-target for both libraries.
    177 add_custom_target(unwind DEPENDS ${LIBUNWIND_BUILD_TARGETS})
    178 
    179 if (LIBUNWIND_INSTALL_LIBRARY)
    180   install(TARGETS ${LIBUNWIND_INSTALL_TARGETS}
    181     LIBRARY DESTINATION ${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind
    182     ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind)
    183 endif()
    184 
    185 if (NOT CMAKE_CONFIGURATION_TYPES AND LIBUNWIND_INSTALL_LIBRARY)
    186   add_custom_target(install-unwind
    187     DEPENDS unwind
    188     COMMAND "${CMAKE_COMMAND}"
    189             -DCMAKE_INSTALL_COMPONENT=unwind
    190             -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
    191   add_custom_target(install-unwind-stripped
    192     DEPENDS unwind
    193     COMMAND "${CMAKE_COMMAND}"
    194             -DCMAKE_INSTALL_COMPONENT=unwind
    195             -DCMAKE_INSTALL_DO_STRIP=1
    196             -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
    197 endif()
    198