Skip to content

Commit

Permalink
CMakeLists: Yet another iteration on getting dynamic linking right
Browse files Browse the repository at this point in the history
This partially reverts commit c38b3be
and replaces it with a more explicit approach.

There are really two key underlying issues:

- lgc is treated partially as an LLVM component library but isn't linked
  into libLLVM-${version}.so. This is as it should be.
- llvm_map_components_to_libnames is really designed to be used together
  with the add_llvm_{executable,library} macros which we don't use
  consistently. These take care of choosing between dynamic vs. static
  linking for LLVM. We do this manually for llpc in this change.
  • Loading branch information
nhaehnle committed Jul 20, 2022
1 parent c48c305 commit 379eeee
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 63 deletions.
17 changes: 10 additions & 7 deletions lgc/tool/lgc/CMakeLists.txt
Expand Up @@ -24,20 +24,23 @@
#######################################################################################################################

### LGC Standalone Compiler ############################################################################################
add_llvm_tool(lgc
lgc.cpp
)

llvm_map_components_to_libnames(llvm_libs
lgc
set(LLVM_LINK_COMPONENTS
Core
AMDGPUAsmParser
AMDGPUCodeGen
AMDGPUDisassembler
AsmParser
Support
)
target_link_libraries(lgc PUBLIC ${llvm_libs})

add_llvm_tool(lgc
lgc.cpp
)

# lgc is linked in separately to account for both static and dynamic library
# builds.
llvm_map_components_to_libnames(extra_llvm_libs lgc)
target_link_libraries(lgc PRIVATE ${extra_llvm_libs})

target_compile_definitions(lgc PRIVATE ${TARGET_ARCHITECTURE_ENDIANESS}ENDIAN_CPU)

Expand Down
15 changes: 9 additions & 6 deletions lgc/tool/lgcdis/CMakeLists.txt
Expand Up @@ -24,16 +24,19 @@
#######################################################################################################################

### LGC disassembler tool ############################################################################################
set(LLVM_LINK_COMPONENTS
AMDGPUDisassembler
Support
)

add_llvm_tool(lgcdis
lgcdis.cpp
)

llvm_map_components_to_libnames(llvm_libs
lgcdis
AMDGPUDisassembler
Support
)
target_link_libraries(lgcdis PUBLIC ${llvm_libs})
# lgcdis is linked in separately to account for both static and dynamic library
# builds.
llvm_map_components_to_libnames(extra_llvm_libs lgcdis)
target_link_libraries(lgcdis PRIVATE ${extra_llvm_libs})

target_include_directories(lgcdis
PRIVATE
Expand Down
85 changes: 35 additions & 50 deletions llpc/CMakeLists.txt
Expand Up @@ -88,32 +88,41 @@ if(ICD_BUILD_LLPC)
# Export the LLVM build path so that it's available in XGL.
set(XGL_LLVM_BUILD_PATH ${XGL_LLVM_BUILD_PATH} PARENT_SCOPE)

llvm_map_components_to_libnames(llvm_libs
lgc
AMDGPUAsmParser
AMDGPUCodeGen
AMDGPUDisassembler
AMDGPUInfo
Analysis
BinaryFormat
Core
Coroutines
LTO
ipo
BitReader
BitWriter
CodeGen
InstCombine
IRReader
Linker
MC
Passes
ScalarOpts
Support
Target
TransformUtils
)
target_link_libraries(llpc PUBLIC ${llvm_libs})
if (LLVM_LINK_LLVM_DYLIB)
# Link dynamically against libLLVM-${version}.so
target_link_libraries(llpc PUBLIC LLVM)
else()
# Link statically against the required component libraries
llvm_map_components_to_libnames(llvm_libs
AMDGPUAsmParser
AMDGPUCodeGen
AMDGPUDisassembler
AMDGPUInfo
Analysis
BinaryFormat
Core
Coroutines
LTO
ipo
BitReader
BitWriter
CodeGen
InstCombine
IRReader
Linker
MC
Passes
ScalarOpts
Support
Target
TransformUtils
)
target_link_libraries(llpc PUBLIC ${llvm_libs})
endif()

# Always link statically against libLLVMlgc
llvm_map_components_to_libnames(extra_llvm_libs lgc)
target_link_libraries(llpc PUBLIC ${extra_llvm_libs})
endif()

### Compiler Options ###################################################################################################
Expand Down Expand Up @@ -325,33 +334,9 @@ target_include_directories(llpc_standalone_compiler PUBLIC
${LLVM_INCLUDE_DIRS}
)

llvm_map_components_to_libnames(llvm_libs
lgc
aggressiveinstcombine
amdgpuasmparser
amdgpucodegen
amdgpudisassembler
amdgpuinfo
analysis
asmparser
bitreader
bitwriter
codegen
coroutines
ipo
irreader
linker
LTO
mc
passes
support
target
transformutils
)
target_link_libraries(llpc_standalone_compiler PUBLIC
cwpack
llpc
${llvm_libs}
metrohash
spvgen_static
vfx
Expand Down

0 comments on commit 379eeee

Please sign in to comment.