Skip to content

Commit

Permalink
Rewrite the CMake build to use explicit dependencies between libraries,
Browse files Browse the repository at this point in the history
specified in the same file that the library itself is created. This is
more idiomatic for CMake builds, and also allows us to correctly specify
dependencies that are missed due to bugs in the GenLibDeps perl script,
or change from compiler to compiler. On Linux, this returns CMake to
a place where it can relably rebuild several targets of LLVM.

I have tried not to change the dependencies from the ones in the current
auto-generated file. The only places I've really diverged are in places
where I was seeing link failures, and added a dependency. The goal of
this patch is not to start changing the dependencies, merely to move
them into the correct location, and an explicit form that we can control
and change when necessary.

This also removes a serialization point in the build because we don't
have to scan all the libraries before we begin building various tools.
We no longer have a step of the build that regenerates a file inside the
source tree. A few other associated cleanups fall out of this.

This isn't really finished yet though. After talking to dgregor he urged
switching to a single CMake macro to construct libraries with both
sources and dependencies in the arguments. Migrating from the two macros
to that style will be a follow-up patch.

Also, llvm-config is still generated with GenLibDeps.pl, which means it
still has slightly buggy dependencies. The internal CMake
'llvm-config-like' macro uses the correct explicitly specified
dependencies however. A future patch will switch llvm-config generation
(when using CMake) to be based on these deps as well.

This may well break Windows. I'm getting a machine set up now to dig
into any failures there. If anyone can chime in with problems they see
or ideas of how to solve them for Windows, much appreciated.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136433 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
chandlerc committed Jul 29, 2011
1 parent 00eab6c commit ac03e73
Show file tree
Hide file tree
Showing 87 changed files with 675 additions and 150 deletions.
8 changes: 8 additions & 0 deletions cmake/modules/AddLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ macro(add_llvm_library name)
set_target_properties(${name} PROPERTIES FOLDER "Libraries")
endmacro(add_llvm_library name)

macro(add_llvm_library_dependencies name)
# Save the dependencies of the LLVM library in a variable so that we can
# query it when resolve llvm-config-style component -> library mappings.
set(LLVM_LIB_DEPS_${name} ${ARGN})

# Then add the actual dependencies to the library target.
target_link_libraries(${name} ${ARGN})
endmacro(add_llvm_library_dependencies name)

macro(add_llvm_loadable_module name)
if( NOT LLVM_ON_UNIX OR CYGWIN )
Expand Down
2 changes: 0 additions & 2 deletions cmake/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ install(FILES
${llvm_cmake_builddir}/LLVMConfig.cmake
${llvm_cmake_builddir}/LLVMConfigVersion.cmake
LLVM-Config.cmake
LLVMLibDeps.cmake
DESTINATION share/llvm/cmake)

install(DIRECTORY .
Expand All @@ -27,7 +26,6 @@ install(DIRECTORY .
PATTERN LLVMConfig.cmake EXCLUDE
PATTERN LLVMConfigVersion.cmake EXCLUDE
PATTERN LLVM-Config.cmake EXCLUDE
PATTERN LLVMLibDeps.cmake EXCLUDE
PATTERN FindBison.cmake EXCLUDE
PATTERN GetTargetTriple.cmake EXCLUDE
PATTERN VersionFromVCS.cmake EXCLUDE
Expand Down
28 changes: 1 addition & 27 deletions cmake/modules/LLVM-Config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function(explicit_map_components_to_libraries out_libs)
set(processed)
while( cursor LESS lst_size )
list(GET expanded_components ${cursor} lib)
list(APPEND expanded_components ${MSVC_LIB_DEPS_${lib}})
list(APPEND expanded_components ${LLVM_LIB_DEPS_${lib}})
# Remove duplicates at the front:
list(REVERSE expanded_components)
list(REMOVE_DUPLICATES expanded_components)
Expand All @@ -175,29 +175,3 @@ function(explicit_map_components_to_libraries out_libs)
endforeach(c)
set(${out_libs} ${result} PARENT_SCOPE)
endfunction(explicit_map_components_to_libraries)


# The library dependency data is contained in the file
# LLVMLibDeps.cmake on this directory. It is automatically generated
# by tools/llvm-config/CMakeLists.txt when the build comprises all the
# targets and we are on a environment Posix enough to build the
# llvm-config script. This, in practice, just excludes MSVC.

# When you remove or rename a library from the build, be sure to
# remove its file from lib/ as well, or the GenLibDeps.pl script will
# include it on its analysis!

# The format generated by GenLibDeps.pl

# LLVMARMAsmPrinter.o: LLVMARMCodeGen.o libLLVMAsmPrinter.a libLLVMCodeGen.a libLLVMCore.a libLLVMSupport.a libLLVMTarget.a

# is translated to:

# set(MSVC_LIB_DEPS_LLVMARMAsmPrinter LLVMARMCodeGen LLVMAsmPrinter LLVMCodeGen LLVMCore LLVMSupport LLVMTarget)

# It is necessary to remove the `lib' prefix and the `.a'.

# This 'sed' script should do the trick:
# sed -e s'#\.a##g' -e 's#libLLVM#LLVM#g' -e 's#: # #' -e 's#\(.*\)#set(MSVC_LIB_DEPS_\1)#' ~/llvm/tools/llvm-config/LibDeps.txt

include(LLVMLibDeps)
83 changes: 0 additions & 83 deletions cmake/modules/LLVMLibDeps.cmake

This file was deleted.

6 changes: 6 additions & 0 deletions lib/Analysis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,10 @@ add_llvm_library(LLVMAnalysis
ValueTracking.cpp
)

add_llvm_library_dependencies(LLVMAnalysis
LLVMCore
LLVMSupport
LLVMTarget
)

add_subdirectory(IPA)
6 changes: 6 additions & 0 deletions lib/Analysis/IPA/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ add_llvm_library(LLVMipa
GlobalsModRef.cpp
IPA.cpp
)

add_llvm_library_dependencies(LLVMipa
LLVMAnalysis
LLVMCore
LLVMSupport
)
6 changes: 6 additions & 0 deletions lib/Archive/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ add_llvm_library(LLVMArchive
ArchiveReader.cpp
ArchiveWriter.cpp
)

add_llvm_library_dependencies(LLVMArchive
LLVMBitReader
LLVMCore
LLVMSupport
)
5 changes: 5 additions & 0 deletions lib/AsmParser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ add_llvm_library(LLVMAsmParser
LLParser.cpp
Parser.cpp
)

add_llvm_library_dependencies(LLVMAsmParser
LLVMCore
LLVMSupport
)
5 changes: 5 additions & 0 deletions lib/Bitcode/Reader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ add_llvm_library(LLVMBitReader
BitReader.cpp
BitcodeReader.cpp
)

add_llvm_library_dependencies(LLVMBitReader
LLVMCore
LLVMSupport
)
5 changes: 5 additions & 0 deletions lib/Bitcode/Writer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ add_llvm_library(LLVMBitWriter
BitcodeWriterPass.cpp
ValueEnumerator.cpp
)

add_llvm_library_dependencies(LLVMBitWriter
LLVMCore
LLVMSupport
)
9 changes: 9 additions & 0 deletions lib/CodeGen/AsmPrinter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@ add_llvm_library(LLVMAsmPrinter
Win64Exception.cpp
)

add_llvm_library_dependencies(LLVMAsmPrinter
LLVMAnalysis
LLVMCodeGen
LLVMCore
LLVMMC
LLVMMCParser
LLVMSupport
LLVMTarget
)
10 changes: 10 additions & 0 deletions lib/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,15 @@ add_llvm_library(LLVMCodeGen
VirtRegRewriter.cpp
)

add_llvm_library_dependencies(LLVMCodeGen
LLVMAnalysis
LLVMCore
LLVMMC
LLVMScalarOpts
LLVMSupport
LLVMTarget
LLVMTransformUtils
)

add_subdirectory(SelectionDAG)
add_subdirectory(AsmPrinter)
10 changes: 10 additions & 0 deletions lib/CodeGen/SelectionDAG/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ add_llvm_library(LLVMSelectionDAG
TargetLowering.cpp
TargetSelectionDAGInfo.cpp
)

add_llvm_library_dependencies(LLVMSelectionDAG
LLVMAnalysis
LLVMCodeGen
LLVMCore
LLVMMC
LLVMSupport
LLVMTarget
LLVMTransformUtils
)
7 changes: 7 additions & 0 deletions lib/ExecutionEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ add_llvm_library(LLVMExecutionEngine
TargetSelect.cpp
)

add_llvm_library_dependencies(LLVMExecutionEngine
LLVMCore
LLVMMC
LLVMSupport
LLVMTarget
)

add_subdirectory(Interpreter)
add_subdirectory(JIT)
add_subdirectory(MCJIT)
Expand Down
8 changes: 8 additions & 0 deletions lib/ExecutionEngine/Interpreter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ add_llvm_library(LLVMInterpreter
Interpreter.cpp
)

add_llvm_library_dependencies(LLVMInterpreter
LLVMCodeGen
LLVMCore
LLVMExecutionEngine
LLVMSupport
LLVMTarget
)

if( LLVM_ENABLE_FFI )
target_link_libraries( LLVMInterpreter ${FFI_LIBRARY_PATH} )
endif()
8 changes: 8 additions & 0 deletions lib/ExecutionEngine/JIT/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ add_llvm_library(LLVMJIT
JITMemoryManager.cpp
OProfileJITEventListener.cpp
)

add_llvm_library_dependencies(LLVMJIT
LLVMCore
LLVMExecutionEngine
LLVMRuntimeDyld
LLVMSupport
LLVMTarget
)
8 changes: 8 additions & 0 deletions lib/ExecutionEngine/MCJIT/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@ add_llvm_library(LLVMMCJIT
MCJIT.cpp
Intercept.cpp
)

add_llvm_library_dependencies(LLVMMCJIT
LLVMCore
LLVMExecutionEngine
LLVMRuntimeDyld
LLVMSupport
LLVMTarget
)
5 changes: 5 additions & 0 deletions lib/ExecutionEngine/RuntimeDyld/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ add_llvm_library(LLVMRuntimeDyld
RuntimeDyld.cpp
RuntimeDyldMachO.cpp
)

add_llvm_library_dependencies(LLVMRuntimeDyld
LLVMObject
LLVMSupport
)
8 changes: 8 additions & 0 deletions lib/Linker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ add_llvm_library(LLVMLinker
LinkModules.cpp
Linker.cpp
)

add_llvm_library_dependencies(LLVMLinker
LLVMArchive
LLVMBitReader
LLVMCore
LLVMSupport
LLVMTransformUtils
)
5 changes: 5 additions & 0 deletions lib/MC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,10 @@ add_llvm_library(LLVMMC
MCTargetAsmLexer.cpp
)

add_llvm_library_dependencies(LLVMMC
LLVMObject
LLVMSupport
)

add_subdirectory(MCParser)
add_subdirectory(MCDisassembler)
42 changes: 41 additions & 1 deletion lib/MC/MCDisassembler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,48 @@

add_llvm_library(LLVMMCDisassembler
Disassembler.cpp
EDDisassembler.cpp
EDInst.cpp
EDOperand.cpp
EDToken.cpp
)

add_llvm_library_dependencies(LLVMMCDisassembler
LLVMARMAsmParser
LLVMARMDesc
LLVMARMDisassembler
LLVMARMInfo
LLVMAlphaDesc
LLVMAlphaInfo
LLVMBlackfinDesc
LLVMBlackfinInfo
LLVMCBackendInfo
LLVMCellSPUDesc
LLVMCellSPUInfo
LLVMCppBackendInfo
LLVMMBlazeAsmParser
LLVMMBlazeDesc
LLVMMBlazeDisassembler
LLVMMBlazeInfo
LLVMMC
LLVMMCParser
LLVMMSP430Desc
LLVMMSP430Info
LLVMMipsDesc
LLVMMipsInfo
LLVMPTXDesc
LLVMPTXInfo
LLVMPowerPCDesc
LLVMPowerPCInfo
LLVMSparcDesc
LLVMSparcInfo
LLVMSupport
LLVMSystemZDesc
LLVMSystemZInfo
LLVMTarget
LLVMX86AsmParser
LLVMX86Desc
LLVMX86Disassembler
LLVMX86Info
LLVMXCoreDesc
LLVMXCoreInfo
)
5 changes: 5 additions & 0 deletions lib/MC/MCParser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ add_llvm_library(LLVMMCParser
MCAsmParserExtension.cpp
MCTargetAsmParser.cpp
)

add_llvm_library_dependencies(LLVMMCParser
LLVMMC
LLVMSupport
)
Loading

0 comments on commit ac03e73

Please sign in to comment.