Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -302,6 +302,8 @@ option (LLVM_BUILD_EXTERNAL_COMPILER_RT "Build compiler-rt as an external project." OFF) +option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" OFF) + # All options referred to from HandleLLVMOptions have to be specified # BEFORE this include, otherwise options will not be correctly set on # first cmake run Index: tools/CMakeLists.txt =================================================================== --- tools/CMakeLists.txt +++ tools/CMakeLists.txt @@ -74,6 +74,12 @@ ignore_llvm_tool_subdirectory(gold) endif() +if ( LLVM_BUILD_LLVM_DYLIB ) + add_llvm_tool_subdirectory(llvm-shlib) +else( LLVM_BUILD_LLVM_DYLIB ) + ignore_llvm_tool_subdirectory(llvm-shlib) +endif ( LLVM_BUILD_LLVM_DYLIB ) + add_llvm_external_project(clang) if( NOT LLVM_INCLUDE_TOOLS STREQUAL "bootstrap-only" ) Index: tools/llvm-shlib/CMakeLists.txt =================================================================== --- /dev/null +++ tools/llvm-shlib/CMakeLists.txt @@ -0,0 +1,86 @@ +if(NOT DEFINED LLVM_DYLIB_COMPONENTS) + set(LLVM_LINK_COMPONENTS + ${LLVM_TARGETS_TO_BUILD} + Analysis + AsmPrinter + BitWriter + CodeGen + Core + ExecutionEngine + IPA + IPO + IRReader + InstCombine + Instrumentation + Interpreter + Linker + MC + MCJIT + ObjCARCOpts + Object + ScalarOpts + SelectionDAG + Support + Target + TransformUtils + Vectorize + native + ) +else(NOT DEFINED LLVM_DYLIB_COMPONENTS) + set(LLVM_LINK_COMPONENTS ${LLVM_DYLIB_COMPONENTS}) +endif(NOT DEFINED LLVM_DYLIB_COMPONENTS) + +add_definitions( -DLLVM_VERSION_INFO=\"${PACKAGE_VERSION}\" ) + +set(SOURCES + libllvm.cpp + ) + +if(NOT DEFINED LLVM_EXPORTED_SYMBOL_FILE) + + if( WIN32 AND NOT CYGWIN ) + message(FATAL_ERROR "Auto-generation not implemented for Win32 without GNU utils. Please specify LLVM_EXPORTED_SYMBOL_FILE.") + endif( WIN32 AND NOT CYGWIN ) + + # 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 + + set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_BINARY_DIR}/libllvm.exports) + + llvm_map_components_to_libnames(LIB_NAMES ${LLVM_LINK_COMPONENTS}) + + foreach (lib ${LIB_NAMES}) + + set(LIB_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib) + 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 (lib ${LLVM_LINK_COMPONENTS}) + + 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...") + +endif(NOT DEFINED LLVM_EXPORTED_SYMBOL_FILE) + +add_llvm_library(LLVM SHARED ${SOURCES}) + +add_dependencies(LLVM ${LLVM_EXPORTED_SYMBOL_FILE}) + +if (APPLE) + set_property(TARGET LLVM APPEND_STRING PROPERTY + LINK_FLAGS + " -compatibility_version ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR} -current_version ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}") +endif(APPLE) + Index: tools/llvm-shlib/libllvm.cpp =================================================================== --- /dev/null +++ tools/llvm-shlib/libllvm.cpp @@ -0,0 +1,13 @@ +//===-libllvm.cpp - LLVM Shared Library -----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is empty and serves only the purpose of making CMake happy because +// you can't define a target with no sources. +// +//===----------------------------------------------------------------------===//