Skip to content

Commit

Permalink
CMake: Get rid of LLVMLibDeps.cmake and export the libraries normally.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113632 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Bigcheese committed Sep 10, 2010
1 parent bb811a2 commit 4e9c939
Show file tree
Hide file tree
Showing 62 changed files with 343 additions and 349 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ add_subdirectory(lib/System)

# Everything else depends on Support and System:
set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${LLVM_LIBS} )
set(LLVM_COMMON_LIBS LLVMSupport LLVMSystem)

set(LLVM_TABLEGEN "tblgen" CACHE
STRING "Native TableGen executable. Saves building one when cross-compiling.")
Expand Down Expand Up @@ -362,6 +363,11 @@ add_subdirectory(examples)

add_subdirectory(cmake/modules)

install(EXPORT LLVM
DESTINATION lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm/
FILE LLVMTargets.cmake
)

install(DIRECTORY include/
DESTINATION include
FILES_MATCHING
Expand Down
87 changes: 83 additions & 4 deletions cmake/modules/AddLLVM.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
include(LLVMProcessSources)
include(LLVMConfig)

function(get_system_libs return_var)
# Returns in `return_var' a list of system libraries used by LLVM.
if( NOT MSVC )
if( MINGW )
set(system_libs ${system_libs} imagehlp psapi)
elseif( CMAKE_HOST_UNIX )
if( HAVE_LIBDL )
set(system_libs ${system_libs} ${CMAKE_DL_LIBS})
endif()
if( LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD )
set(system_libs ${system_libs} pthread)
endif()
endif( MINGW )
endif( NOT MSVC )
set(${return_var} ${system_libs} PARENT_SCOPE)
endfunction(get_system_libs)

macro(add_llvm_library name)
llvm_process_sources( ALL_FILES ${ARGN} )
Expand All @@ -9,7 +25,11 @@ macro(add_llvm_library name)
if( LLVM_COMMON_DEPENDS )
add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
endif( LLVM_COMMON_DEPENDS )
if (LLVM_COMMON_LIBS)
target_link_libraries(${name} ${LLVM_COMMON_LIBS})
endif()
install(TARGETS ${name}
EXPORT LLVM
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
# The LLVM Target library shall be built before its sublibraries
Expand Down Expand Up @@ -38,6 +58,7 @@ ${name} ignored.")
endif()

install(TARGETS ${name}
EXPORT LLVM
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
endif()
Expand All @@ -57,16 +78,16 @@ macro(add_llvm_executable name)
target_link_libraries( ${name} ${lib} )
endforeach(lib)
endif( LLVM_USED_LIBS )
if( LLVM_LINK_COMPONENTS )
llvm_config(${name} ${LLVM_LINK_COMPONENTS})
endif( LLVM_LINK_COMPONENTS )
get_system_libs(llvm_system_libs)
if( llvm_system_libs )
target_link_libraries(${name} ${llvm_system_libs})
endif()
if( LLVM_COMMON_DEPENDS )
add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
endif( LLVM_COMMON_DEPENDS )
if (LLVM_COMMON_LIBS)
target_link_libraries(${name} ${LLVM_COMMON_LIBS})
endif()
endmacro(add_llvm_executable name)


Expand Down Expand Up @@ -107,3 +128,61 @@ macro(add_llvm_target target_name)
endif (TABLEGEN_OUTPUT)
set(CURRENT_LLVM_TARGET LLVM${target_name} PARENT_SCOPE)
endmacro(add_llvm_target)

macro(llvm_get_target_libraries return_var)
set( link_components ${ARGN} )
foreach(c ${link_components})
# add codegen, asmprinter, asmparser, disassembler
list(FIND LLVM_TARGETS_TO_BUILD ${c} idx)
if( NOT idx LESS 0 )
list(FIND llvm_libs "LLVM${c}CodeGen" idx)
if( NOT idx LESS 0 )
list(APPEND expanded_components "LLVM${c}CodeGen")
else()
list(FIND llvm_libs "LLVM${c}" idx)
if( NOT idx LESS 0 )
list(APPEND expanded_components "LLVM${c}")
else()
message(FATAL_ERROR "Target ${c} is not in the set of libraries.")
endif()
endif()
list(FIND llvm_libs "LLVM${c}AsmPrinter" asmidx)
if( NOT asmidx LESS 0 )
list(APPEND expanded_components "LLVM${c}AsmPrinter")
endif()
list(FIND llvm_libs "LLVM${c}AsmParser" asmidx)
if( NOT asmidx LESS 0 )
list(APPEND expanded_components "LLVM${c}AsmParser")
endif()
list(FIND llvm_libs "LLVM${c}Info" asmidx)
if( NOT asmidx LESS 0 )
list(APPEND expanded_components "LLVM${c}Info")
endif()
list(FIND llvm_libs "LLVM${c}Disassembler" asmidx)
if( NOT asmidx LESS 0 )
list(APPEND expanded_components "LLVM${c}Disassembler")
endif()
elseif( c STREQUAL "native" )
list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}CodeGen")
elseif( c STREQUAL "nativecodegen" )
list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}CodeGen")
elseif( c STREQUAL "backend" )
# same case as in `native'.
elseif( c STREQUAL "engine" OR c STREQUAL "jit")
# TODO: as we assume we are on X86, this is `jit'.
list(APPEND expanded_components "LLVMJIT")
elseif( c STREQUAL "interpreter" )
list(APPEND expanded_components "LLVMInterpreter")
elseif( c STREQUAL "all" )
list(APPEND expanded_components ${llvm_libs})
else( NOT idx LESS 0 )
list(APPEND expanded_components LLVM${c})
endif( NOT idx LESS 0 )
endforeach(c)
set(${return_var} ${expanded_components})
endmacro(llvm_get_target_libraries)

macro(add_llvm_link_components target_name)
llvm_get_target_libraries(target_libs ${ARGN})
target_link_libraries(${target_name} ${target_libs})
endmacro()
22 changes: 14 additions & 8 deletions cmake/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/share/llvm/cmake")
set(LLVM_CFLAGS "${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
set(LLVM_CXXFLAGS "${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
set(LLVM_CPPFLAGS "${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
llvm_get_target_libraries(LLVM_JIT_LIBS jit)
llvm_get_target_libraries(LLVM_INTERPRETER_LIBS interpreter)
llvm_get_target_libraries(LLVM_NATIVECODEGEN_LIBS nativecodegen)
get_system_libs(LLVM_SYSTEM_LIBS)

configure_file(
LLVM.cmake
${llvm_cmake_builddir}/LLVM.cmake
@ONLY)
LLVMConfig.cmake.in
${LLVM_BINARY_DIR}/cmake/modules/LLVMConfig.cmake
@ONLY
)

install(FILES
${llvm_cmake_builddir}/LLVM.cmake
LLVMConfig.cmake
LLVMLibDeps.cmake
DESTINATION share/llvm/cmake)
${LLVM_BINARY_DIR}/cmake/modules/LLVMConfig.cmake
DESTINATION lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm/
)
165 changes: 0 additions & 165 deletions cmake/modules/LLVMConfig.cmake

This file was deleted.

11 changes: 11 additions & 0 deletions cmake/modules/LLVMConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
include(${SELF_DIR}/LLVMTargets.cmake)
get_filename_component(LLVM_INCLUDE_DIRS "${SELF_DIR}/../../../include" ABSOLUTE)
set(LLVM_CPPFLAGS "@LLVM_CPPFLAGS@")
set(LLVM_CFLAGS "@LLVM_CFLAGS@")
set(LLVM_CXXFLAGS "@LLVM_CXXFLAGS@")
set(LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@")
set(LLVM_JIT_LIBS "@LLVM_JIT_LIBS@")
set(LLVM_INTERPRETER_LIBS "@LLVM_INTERPRETER_LIBS@")
set(LLVM_NATIVECODEGEN_LIBS "@LLVM_NATIVECODEGEN_LIBS@")
set(LLVM_BUILDMODE "@LLVM_BUILDMODE@")
Loading

0 comments on commit 4e9c939

Please sign in to comment.