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
11 # Compute the substitution values for various items.
12 get_property(SUPPORT_SYSTEM_LIBS TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS)
13 get_property(WINDOWSMANIFEST_SYSTEM_LIBS TARGET LLVMWindowsManifest PROPERTY LLVM_SYSTEM_LIBS)
14 foreach(l ${SUPPORT_SYSTEM_LIBS} ${WINDOWSMANIFEST_SYSTEM_LIBS})
16 set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}.lib")
19 # If it's an option, pass it without changes.
20 set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}")
22 # Otherwise assume it's a library name we need to link with.
23 set(SYSTEM_LIBS ${SYSTEM_LIBS} "-l${l}")
27 string(REPLACE ";" " " SYSTEM_LIBS "${SYSTEM_LIBS}")
29 # Fetch target specific compile options, e.g. RTTI option
30 get_property(COMPILE_FLAGS TARGET llvm-config PROPERTY COMPILE_FLAGS)
32 # The language standard potentially affects the ABI/API of LLVM, so we want
33 # to make sure it is reported by llvm-config.
34 # NOTE: We don't want to start extracting any random C/CXX flags that the
35 # user may add that could affect the ABI. We only want to extract flags
36 # that have been added by the LLVM build system.
37 string(REGEX MATCH "-std=[^ ]\+" LLVM_CXX_STD_FLAG ${CMAKE_CXX_FLAGS})
38 string(REGEX MATCH "-stdlib=[^ ]\+" LLVM_CXX_STDLIB_FLAG ${CMAKE_CXX_FLAGS})
39 string(REGEX MATCH "-std=[^ ]\+" LLVM_C_STD_FLAG ${CMAKE_C_FLAGS})
41 # Use configure_file to create BuildVariables.inc.
42 set(LLVM_SRC_ROOT ${LLVM_MAIN_SRC_DIR})
43 set(LLVM_OBJ_ROOT ${LLVM_BINARY_DIR})
44 set(LLVM_CPPFLAGS "${LLVM_DEFINITIONS}")
45 set(LLVM_CFLAGS "${LLVM_C_STD_FLAG} ${LLVM_DEFINITIONS}")
46 set(LLVM_CXXFLAGS "${LLVM_CXX_STD_FLAG} ${LLVM_CXX_STDLIB_FLAG} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}")
47 set(LLVM_BUILD_SYSTEM cmake)
48 set(LLVM_HAS_RTTI ${LLVM_CONFIG_HAS_RTTI})
49 set(LLVM_DYLIB_VERSION "${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX}")
50 set(LLVM_HAS_GLOBAL_ISEL "ON")
52 # Use the C++ link flags, since they should be a superset of C link flags.
53 set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}")
54 set(LLVM_BUILDMODE ${CMAKE_BUILD_TYPE})
55 set(LLVM_SYSTEM_LIBS ${SYSTEM_LIBS})
56 string(REPLACE ";" " " LLVM_TARGETS_BUILT "${LLVM_TARGETS_TO_BUILD}")
57 llvm_canonicalize_cmake_booleans(
63 llvm_expand_pseudo_components(LLVM_DYLIB_COMPONENTS_expanded "${LLVM_DYLIB_COMPONENTS}")
64 configure_file(${BUILDVARIABLES_SRCPATH} ${BUILDVARIABLES_OBJPATH} @ONLY)
66 # Set build-time environment(s).
67 add_definitions(-DCMAKE_CFG_INTDIR="${CMAKE_CFG_INTDIR}")
69 if(LLVM_ENABLE_MODULES)
70 target_compile_options(llvm-config PUBLIC
71 "-fmodules-ignore-macro=CMAKE_CFG_INTDIR"
75 # Add the dependency on the generation step.
76 add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.cpp ${BUILDVARIABLES_OBJPATH})
78 if(CMAKE_CROSSCOMPILING AND NOT LLVM_CONFIG_PATH)
79 build_native_tool(llvm-config LLVM_CONFIG_PATH)
80 set(LLVM_CONFIG_PATH "${LLVM_CONFIG_PATH}" CACHE STRING "")
82 add_custom_target(NativeLLVMConfig DEPENDS ${LLVM_CONFIG_PATH})
83 add_dependencies(llvm-config NativeLLVMConfig)