Home | History | Annotate | Download | only in src
      1 # Get sources
      2 set(LIBCXXABI_SOURCES
      3   abort_message.cpp
      4   cxa_aux_runtime.cpp
      5   cxa_default_handlers.cpp
      6   cxa_demangle.cpp
      7   cxa_exception.cpp
      8   cxa_exception_storage.cpp
      9   cxa_guard.cpp
     10   cxa_handlers.cpp
     11   cxa_new_delete.cpp
     12   cxa_personality.cpp
     13   cxa_unexpected.cpp
     14   cxa_vector.cpp
     15   cxa_virtual.cpp
     16   exception.cpp
     17   private_typeinfo.cpp
     18   stdexcept.cpp
     19   typeinfo.cpp
     20 )
     21 
     22 if (UNIX AND NOT (APPLE OR CYGWIN))
     23   list(APPEND LIBCXXABI_SOURCES cxa_thread_atexit.cpp)
     24 endif()
     25 
     26 set(LIBCXXABI_HEADERS ../include/cxxabi.h)
     27 
     28 # Add all the headers to the project for IDEs.
     29 if (MSVC_IDE OR XCODE)
     30   # Force them all into the headers dir on MSVC, otherwise they end up at
     31   # project scope because they don't have extensions.
     32   if (MSVC_IDE)
     33     source_group("Header Files" FILES ${LIBCXXABI_HEADERS})
     34   endif()
     35 endif()
     36 
     37 include_directories("${LIBCXXABI_LIBCXX_INCLUDES}")
     38 
     39 if (LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL)
     40   add_definitions(-DHAVE___CXA_THREAD_ATEXIT_IMPL)
     41 endif()
     42 
     43 # Generate library list.
     44 set(libraries ${LIBCXXABI_CXX_ABI_LIBRARIES})
     45 append_if(libraries LIBCXXABI_HAS_C_LIB c)
     46 if (LIBCXXABI_ENABLE_THREADS)
     47   append_if(libraries LIBCXXABI_HAS_PTHREAD_LIB pthread)
     48 endif()
     49 
     50 if (LIBCXXABI_USE_LLVM_UNWINDER)
     51   list(APPEND libraries unwind)
     52 else()
     53   append_if(libraries LIBCXXABI_HAS_GCC_EH_LIB gcc_eh)
     54 endif()
     55 
     56 # Setup flags.
     57 append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_FPIC_FLAG -fPIC)
     58 append_if(LIBCXXABI_LINK_FLAGS LIBCXXABI_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs)
     59 
     60 set(LIBCXXABI_SHARED_LINK_FLAGS)
     61 
     62 if ( APPLE )
     63   if ( CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6" )
     64     list(APPEND LIBCXXABI_COMPILE_FLAGS "-U__STRICT_ANSI__")
     65     list(APPEND LIBCXXABI_SHARED_LINK_FLAGS
     66       "-compatibility_version 1"
     67       "-current_version 1"
     68       "-install_name /usr/lib/libc++abi.1.dylib")
     69     list(APPEND LIBCXXABI_LINK_FLAGS
     70         "/usr/lib/libSystem.B.dylib")
     71   else()
     72     list(APPEND LIBCXXABI_SHARED_LINK_FLAGS
     73       "-compatibility_version 1"
     74       "-install_name /usr/lib/libc++abi.1.dylib")
     75   endif()
     76 endif()
     77 
     78 string(REPLACE ";" " " LIBCXXABI_COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}")
     79 string(REPLACE ";" " " LIBCXXABI_LINK_FLAGS "${LIBCXXABI_LINK_FLAGS}")
     80 string(REPLACE ";" " " LIBCXXABI_SHARED_LINK_FLAGS "${LIBCXXABI_SHARED_LINK_FLAGS}")
     81 
     82 # Add a object library that contains the compiled source files.
     83 add_library(cxxabi_objects OBJECT ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
     84 
     85 set_target_properties(cxxabi_objects
     86   PROPERTIES
     87     COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}"
     88   )
     89 
     90 set(LIBCXXABI_TARGETS)
     91 
     92 # Build the shared library.
     93 if (LIBCXXABI_ENABLE_SHARED)
     94   add_library(cxxabi_shared SHARED $<TARGET_OBJECTS:cxxabi_objects>)
     95   target_link_libraries(cxxabi_shared ${libraries})
     96   set_target_properties(cxxabi_shared
     97     PROPERTIES
     98       LINK_FLAGS    "${LIBCXXABI_LINK_FLAGS} ${LIBCXXABI_SHARED_LINK_FLAGS}"
     99       OUTPUT_NAME   "c++abi"
    100       VERSION       "1.0"
    101       SOVERSION     "1"
    102     )
    103   list(APPEND LIBCXXABI_TARGETS "cxxabi_shared")
    104 endif()
    105 
    106 # Build the static library.
    107 if (LIBCXXABI_ENABLE_STATIC)
    108   add_library(cxxabi_static STATIC $<TARGET_OBJECTS:cxxabi_objects>)
    109   target_link_libraries(cxxabi_static ${libraries})
    110   set_target_properties(cxxabi_static
    111     PROPERTIES
    112       LINK_FLAGS    "${LIBCXXABI_LINK_FLAGS}"
    113       OUTPUT_NAME   "c++abi"
    114   )
    115   list(APPEND LIBCXXABI_TARGETS "cxxabi_static")
    116 endif()
    117 
    118 # Add a meta-target for both libraries.
    119 add_custom_target(cxxabi DEPENDS ${LIBCXXABI_TARGETS})
    120 
    121 install(TARGETS ${LIBCXXABI_TARGETS}
    122   LIBRARY DESTINATION lib${LIBCXXABI_LIBDIR_SUFFIX}
    123   ARCHIVE DESTINATION lib${LIBCXXABI_LIBDIR_SUFFIX}
    124   )
    125