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