llvm-project/clang/examples/clang-interpreter/CMakeLists.txt

94 lines
3.0 KiB
CMake
Raw Normal View History

set(LLVM_LINK_COMPONENTS
Core
ExecutionEngine
MC
2014-07-25 01:13:09 +08:00
MCJIT
Object
OrcJit
Option
RuntimeDyld
Support
native
)
add_clang_executable(clang-interpreter
main.cpp
)
add_dependencies(clang-interpreter
clang-resource-headers
)
clang_target_link_libraries(clang-interpreter
[CMake] Use PRIVATE in target_link_libraries for executables We currently use target_link_libraries without an explicit scope specifier (INTERFACE, PRIVATE or PUBLIC) when linking executables. Dependencies added in this way apply to both the target and its dependencies, i.e. they become part of the executable's link interface and are transitive. Transitive dependencies generally don't make sense for executables, since you wouldn't normally be linking against an executable. This also causes issues for generating install export files when using LLVM_DISTRIBUTION_COMPONENTS. For example, clang has a lot of LLVM library dependencies, which are currently added as interface dependencies. If clang is in the distribution components but the LLVM libraries it depends on aren't (which is a perfectly legitimate use case if the LLVM libraries are being built static and there are therefore no run-time dependencies on them), CMake will complain about the LLVM libraries not being in export set when attempting to generate the install export file for clang. This is reasonable behavior on CMake's part, and the right thing is for LLVM's build system to explicitly use PRIVATE dependencies for executables. Unfortunately, CMake doesn't allow you to mix and match the keyword and non-keyword target_link_libraries signatures for a single target; i.e., if a single call to target_link_libraries for a particular target uses one of the INTERFACE, PRIVATE, or PUBLIC keywords, all other calls must also be updated to use those keywords. This means we must do this change in a single shot. I also fully expect to have missed some instances; I tested by enabling all the projects in the monorepo (except dragonegg), and configuring both with and without shared libraries, on both Darwin and Linux, but I'm planning to rely on the buildbots for other configurations (since it should be pretty easy to fix those). Even after this change, we still have a lot of target_link_libraries calls that don't specify a scope keyword, mostly for shared libraries. I'm thinking about addressing those in a follow-up, but that's a separate change IMO. Differential Revision: https://reviews.llvm.org/D40823 llvm-svn: 319840
2017-12-06 05:49:56 +08:00
PRIVATE
clangBasic
clangCodeGen
clangDriver
clangFrontend
clangSerialization
)
export_executable_symbols(clang-interpreter)
if (MSVC)
# Is this a CMake bug that even with export_executable_symbols, Windows
# needs to explictly export the type_info vtable
set_property(TARGET clang-interpreter
APPEND_STRING PROPERTY LINK_FLAGS " /EXPORT:??_7type_info@@6B@")
endif()
function(clang_enable_exceptions TARGET)
# Really have to jump through hoops to enable exception handling independent
# of how LLVM is being built.
if (NOT LLVM_REQUIRES_EH AND NOT LLVM_REQUIRES_RTTI)
if (MSVC)
# /EHs to allow throwing from extern "C"
set(excptnExceptions_ON "/D _HAS_EXCEPTIONS=1 /EHs /wd4714")
set(excptnExceptions_OFF "/D _HAS_EXCEPTIONS=0 /EHs-c-")
set(excptnRTTI_ON "/GR")
set(excptnRTTI_OFF "/GR-")
set(excptnEHRTTIRegEx "(/EHs(-c-?)|_HAS_EXCEPTIONS=(0|1))")
else()
set(excptnExceptions_ON "-fexceptions")
set(excptnExceptions_OFF "-fno-exceptions")
set(excptnRTTI_ON "-frtti")
set(excptnRTTI_OFF "-fno-rtti")
set(excptnEHRTTIRegEx "-f(exceptions|no-exceptions)")
endif()
if (LLVM_REQUIRES_EH)
set(excptnExceptions_DFLT ${excptnExceptions_ON})
else()
set(excptnExceptions_DFLT ${excptnExceptions_OFF})
endif()
if (LLVM_REQUIRES_RTTI)
set(excptnRTTI_DFLT ${excptnRTTI_ON})
else()
set(excptnRTTI_DFLT ${excptnRTTI_OFF})
endif()
# Strip the exception & rtti flags from the target
get_property(addedFlags TARGET ${TARGET} PROPERTY COMPILE_FLAGS)
string(REGEX REPLACE ${excptnEHRTTIRegEx} "" editedFlags "${addedFlags}")
string(REPLACE ${excptnRTTI_OFF} "" editedFlags "${editedFlags}")
set_property(TARGET ${TARGET} PROPERTY COMPILE_FLAGS "${editedFlags}")
get_property(addedFlags TARGET ${TARGET} PROPERTY COMPILE_DEFINITIONS)
string(REGEX REPLACE ${excptnEHRTTIRegEx} "" editedFlags "${addedFlags}")
string(REPLACE ${excptnRTTI_OFF} "" editedFlags "${editedFlags}")
set_property(TARGET ${TARGET} PROPERTY COMPILE_DEFINITIONS "${editedFlags}")
# Re-add the exception & rtti flags from LLVM
set_property(SOURCE main.cpp APPEND_STRING PROPERTY COMPILE_FLAGS
" ${excptnExceptions_DFLT} ${excptnRTTI_DFLT} ")
set_property(SOURCE Manager.cpp APPEND_STRING PROPERTY COMPILE_FLAGS
" ${excptnExceptions_DFLT} ${excptnRTTI_DFLT} ")
# Invoke with exceptions & rtti
set_property(SOURCE Invoke.cpp APPEND_STRING PROPERTY COMPILE_FLAGS
" ${excptnExceptions_ON} ${excptnRTTI_ON} ")
endif()
endfunction(clang_enable_exceptions)
clang_enable_exceptions(clang-interpreter)