mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 20:39:47 +00:00
[CMake] Get rid of LLVM_DYLIB_EXPORT_ALL, and make it the default, add libLLVM-C on darwin to cover the C API needs.
Summary: We've had a lot of discussion in the past about the meaningful and useful default behaviors for the llvm-shlib tool. The original implementation was heavily geared toward Apple's use, and I think that was wrong. This patch seeks to correct that. I've removed the LLVM_DYLIB_EXPORT_ALL variable and made libLLVM export everything by default. I've also added a new target that is only built on Darwin for libLLVM-C as a library that re-exports the LLVM-C API. This library is not built on Linux because ELF doesn't support re-export libraries in the same way MachO does. Reviewers: chapuni, resistor, bogner, axw Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D13842 llvm-svn: 251411
This commit is contained in:
parent
2110df5fda
commit
d3dd2855e4
@ -374,8 +374,12 @@ if(NOT DEFINED LLVM_DYLIB_COMPONENTS)
|
||||
"Semicolon-separated list of components to include in libLLVM, or \"all\".")
|
||||
endif()
|
||||
option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF)
|
||||
option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_LINK_LLVM_DYLIB})
|
||||
option(LLVM_DYLIB_EXPORT_ALL "Export all symbols from libLLVM.dylib (default is C API only" ${LLVM_LINK_LLVM_DYLIB})
|
||||
option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin Only)" OFF)
|
||||
set(LLVM_BUILD_LLVM_DYLIB_default OFF)
|
||||
if(LLVM_LINK_LLVM_DYLIB OR LLVM_BUILD_LLVM_C_DYLIB)
|
||||
set(LLVM_BUILD_LLVM_DYLIB_default ON)
|
||||
endif()
|
||||
option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default})
|
||||
set(LLVM_DISABLE_LLVM_DYLIB_ATEXIT_DEFAULT ON)
|
||||
if (LLVM_LINK_LLVM_DYLIB)
|
||||
set(LLVM_DISABLE_LLVM_DYLIB_ATEXIT_DEFAULT OFF)
|
||||
|
@ -11,8 +11,8 @@ set(SOURCES
|
||||
llvm_map_components_to_libnames(LIB_NAMES ${LLVM_DYLIB_COMPONENTS})
|
||||
|
||||
if(LLVM_LINK_LLVM_DYLIB)
|
||||
if(NOT LLVM_DYLIB_EXPORT_ALL)
|
||||
message(FATAL_ERROR "LLVM_DYLIB_EXPORT_ALL must be ON when LLVM_LINK_LLVM_DYLIB is ON")
|
||||
if(LLVM_DYLIB_EXPORTED_SYMBOL_FILE)
|
||||
message(WARNING "Using LLVM_LINK_LLVM_DYLIB with LLVM_DYLIB_EXPORTED_SYMBOL_FILE may not work. Use at your own risk.")
|
||||
endif()
|
||||
|
||||
# libLLVM.so should not have any dependencies on any other LLVM
|
||||
@ -33,41 +33,7 @@ if(LLVM_LINK_LLVM_DYLIB)
|
||||
set(LIB_NAMES ${FILTERED_LIB_NAMES})
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED LLVM_DYLIB_EXPORTED_SYMBOL_FILE)
|
||||
# To get the export list for a single llvm library:
|
||||
# nm ${LIB_PATH} | awk "/T _LLVM/ { print $3 }" | sort -u | sed -e "s/^_//g" > ${LIB_PATH}.exports
|
||||
|
||||
if (NOT LLVM_DYLIB_EXPORT_ALL)
|
||||
if( WIN32 AND NOT CYGWIN )
|
||||
message(FATAL_ERROR "Auto-generation not implemented for Win32 without GNU utils. Please specify LLVM_EXPORTED_SYMBOL_FILE.")
|
||||
endif()
|
||||
|
||||
set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_BINARY_DIR}/libllvm.exports)
|
||||
|
||||
foreach (lib ${LIB_NAMES})
|
||||
set(LIB_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
|
||||
set(LIB_NAME ${LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${lib})
|
||||
set(LIB_PATH ${LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
|
||||
set(LIB_EXPORTS_PATH ${LIB_NAME}.exports)
|
||||
list(APPEND LLVM_DYLIB_REQUIRED_EXPORTS ${LIB_EXPORTS_PATH})
|
||||
|
||||
|
||||
add_custom_command(OUTPUT ${LIB_EXPORTS_PATH}
|
||||
COMMAND nm ${LIB_PATH} | awk "/T _LLVM/ || /T LLVM/ { print $3 }" | sort -u | sed -e "s/^_//g" > ${LIB_EXPORTS_PATH}
|
||||
WORKING_DIRECTORY ${LIB_DIR}
|
||||
DEPENDS ${lib}
|
||||
COMMENT "Generating Export list for ${lib}..."
|
||||
VERBATIM )
|
||||
endforeach ()
|
||||
|
||||
add_custom_command(OUTPUT ${LLVM_EXPORTED_SYMBOL_FILE}
|
||||
COMMAND cat ${LLVM_DYLIB_REQUIRED_EXPORTS} > ${LLVM_EXPORTED_SYMBOL_FILE}
|
||||
WORKING_DIRECTORY ${LIB_DIR}
|
||||
DEPENDS ${LLVM_DYLIB_REQUIRED_EXPORTS}
|
||||
COMMENT "Generating combined export list...")
|
||||
add_custom_target(libLLVMExports DEPENDS ${LLVM_EXPORTED_SYMBOL_FILE})
|
||||
endif()
|
||||
else()
|
||||
if(LLVM_DYLIB_EXPORTED_SYMBOL_FILE)
|
||||
set(LLVM_EXPORTED_SYMBOL_FILE ${LLVM_DYLIB_EXPORTED_SYMBOL_FILE})
|
||||
add_custom_target(libLLVMExports DEPENDS ${LLVM_EXPORTED_SYMBOL_FILE})
|
||||
endif()
|
||||
@ -84,13 +50,48 @@ endif()
|
||||
|
||||
target_link_libraries(LLVM PRIVATE ${LIB_NAMES})
|
||||
|
||||
if(TARGET libLLVMExports)
|
||||
add_dependencies(LLVM libLLVMExports)
|
||||
endif()
|
||||
|
||||
if (APPLE)
|
||||
set_property(TARGET LLVM APPEND_STRING PROPERTY
|
||||
LINK_FLAGS
|
||||
" -compatibility_version 1 -current_version ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}")
|
||||
endif()
|
||||
|
||||
if(TARGET libLLVMExports)
|
||||
add_dependencies(LLVM libLLVMExports)
|
||||
endif()
|
||||
|
||||
if(LLVM_BUILD_LLVM_C_DYLIB)
|
||||
# To get the export list for a single llvm library:
|
||||
# nm ${LIB_PATH} | awk "/T _LLVM/ { print $3 }" | sort -u | sed -e "s/^_//g" > ${LIB_PATH}.exports
|
||||
|
||||
if(NOT APPLE)
|
||||
message(FATAL_ERROR "Generating libLLVM-c is only supported on Darwin")
|
||||
endif()
|
||||
|
||||
set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_BINARY_DIR}/libllvm-c.exports)
|
||||
|
||||
set(LIB_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
|
||||
set(LIB_NAME ${LIB_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}LLVM)
|
||||
set(LIB_PATH ${LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX})
|
||||
set(LIB_EXPORTS_PATH ${LIB_NAME}.exports)
|
||||
list(APPEND LLVM_DYLIB_REQUIRED_EXPORTS ${LIB_EXPORTS_PATH})
|
||||
|
||||
add_custom_command(OUTPUT ${LLVM_EXPORTED_SYMBOL_FILE}
|
||||
COMMAND nm ${LIB_PATH} | awk "/T _LLVM/ || /T LLVM/ { print $3 }" | sort -u | sed -e "s/^_//g" > ${LLVM_EXPORTED_SYMBOL_FILE}
|
||||
WORKING_DIRECTORY ${LIB_DIR}
|
||||
DEPENDS LLVM
|
||||
COMMENT "Generating Export list for LLVM..."
|
||||
VERBATIM )
|
||||
|
||||
add_custom_target(libLLVMCExports DEPENDS ${LLVM_EXPORTED_SYMBOL_FILE})
|
||||
|
||||
add_llvm_library(LLVM-C SHARED ${SOURCES})
|
||||
|
||||
target_link_libraries(LLVM-C PUBLIC LLVM)
|
||||
add_dependencies(LLVM-C libLLVMCExports)
|
||||
|
||||
set_property(TARGET LLVM-C APPEND_STRING PROPERTY
|
||||
LINK_FLAGS
|
||||
" -compatibility_version 1 -current_version ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH} -Wl,-reexport_library ${LIB_PATH}")
|
||||
endif()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user