1 set(LLVM_LINK_COMPONENTS
6 set(BUILDVARIABLES_SRCPATH ${CMAKE_CURRENT_SOURCE_DIR}/BuildVariables.inc.in)
7 set(BUILDVARIABLES_OBJPATH ${CMAKE_CURRENT_BINARY_DIR}/BuildVariables.inc)
9 # Add the llvm-config tool.
10 add_llvm_tool(llvm-config
12 # This utility doesn't use much of LLVM, so linking a shared library for the
13 # entire thing is overkill. Avoiding that especially saves on build time when cross
14 # compiling LLVM and building both cross and native `llvm-config`s. We don't
15 # want to build an entire native libLLVM.so in addition to the cross one just
16 # for the native `llvm-config`!
17 DISABLE_LLVM_LINK_LLVM_DYLIB
20 # Compute the substitution values for various items.
21 get_property(SUPPORT_SYSTEM_LIBS TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS)
22 get_property(WINDOWSMANIFEST_SYSTEM_LIBS TARGET LLVMWindowsManifest PROPERTY LLVM_SYSTEM_LIBS)
24 foreach(l ${SUPPORT_SYSTEM_LIBS} ${WINDOWSMANIFEST_SYSTEM_LIBS})
27 set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}")
29 set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}.lib")
33 # If it's an option, pass it without changes.
34 set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}")
36 # Otherwise assume it's a library name we need to link with.
38 set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}")
40 set(SYSTEM_LIBS ${SYSTEM_LIBS} "-l${l}")
46 string(REPLACE ";" " " SYSTEM_LIBS "${SYSTEM_LIBS}")
48 # Fetch target specific compile options, e.g. RTTI option
49 get_property(COMPILE_FLAGS TARGET llvm-config PROPERTY COMPILE_FLAGS)
51 # NOTE: We don't want to start extracting any random C/CXX flags that the
52 # user may add that could affect the ABI. We only want to extract flags
53 # that have been added by the LLVM build system.
54 string(REGEX MATCH "-stdlib=[^ ]+" LLVM_CXX_STDLIB_FLAG ${CMAKE_CXX_FLAGS})
55 string(REGEX MATCH "-std=[^ ]+" LLVM_C_STD_FLAG ${CMAKE_C_FLAGS})
57 # Use configure_file to create BuildVariables.inc.
58 set(LLVM_SRC_ROOT ${LLVM_MAIN_SRC_DIR})
59 set(LLVM_OBJ_ROOT ${LLVM_BINARY_DIR})
60 set(LLVM_CPPFLAGS "${LLVM_DEFINITIONS}")
61 set(LLVM_CFLAGS "${LLVM_C_STD_FLAG} ${LLVM_DEFINITIONS}")
62 # The language standard potentially affects the ABI/API of LLVM, so we want
63 # to make sure it is reported by llvm-config.
64 set(LLVM_CXXFLAGS "${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION} ${LLVM_CXX_STDLIB_FLAG} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}")
65 set(LLVM_BUILD_SYSTEM cmake)
66 set(LLVM_HAS_RTTI ${LLVM_CONFIG_HAS_RTTI})
67 set(LLVM_DYLIB_VERSION "${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX}")
69 # Use the C++ link flags, since they should be a superset of C link flags.
70 set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}")
71 set(LLVM_BUILDMODE ${CMAKE_BUILD_TYPE})
72 set(LLVM_SYSTEM_LIBS ${SYSTEM_LIBS})
73 string(REPLACE ";" " " LLVM_TARGETS_BUILT "${LLVM_TARGETS_TO_BUILD}")
74 llvm_canonicalize_cmake_booleans(
79 llvm_expand_pseudo_components(LLVM_DYLIB_COMPONENTS_expanded "${LLVM_DYLIB_COMPONENTS}")
80 configure_file(${BUILDVARIABLES_SRCPATH} ${BUILDVARIABLES_OBJPATH} @ONLY)
82 # Set build-time environment(s).
83 add_compile_definitions(CMAKE_CFG_INTDIR="${CMAKE_CFG_INTDIR}")
85 if(LLVM_ENABLE_MODULES)
86 target_compile_options(llvm-config PUBLIC
87 "-fmodules-ignore-macro=CMAKE_CFG_INTDIR"
91 # Add the dependency on the generation step.
92 add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.cpp ${BUILDVARIABLES_OBJPATH})
94 if(CMAKE_CROSSCOMPILING)
95 if (LLVM_NATIVE_TOOL_DIR AND NOT LLVM_CONFIG_PATH)
96 if (EXISTS "${LLVM_NATIVE_TOOL_DIR}/llvm-config${LLVM_HOST_EXECUTABLE_SUFFIX}")
97 set(LLVM_CONFIG_PATH "${LLVM_NATIVE_TOOL_DIR}/llvm-config${LLVM_HOST_EXECUTABLE_SUFFIX}")
101 if (NOT LLVM_CONFIG_PATH)
102 build_native_tool(llvm-config LLVM_CONFIG_PATH)
103 set(LLVM_CONFIG_PATH "${LLVM_CONFIG_PATH}" CACHE STRING "")
105 add_custom_target(NativeLLVMConfig DEPENDS ${LLVM_CONFIG_PATH})
106 add_dependencies(llvm-config NativeLLVMConfig)