1set(LLVM_LINK_COMPONENTS support)
2
3set(BUILDVARIABLES_SRCPATH ${CMAKE_CURRENT_SOURCE_DIR}/BuildVariables.inc.in)
4set(BUILDVARIABLES_OBJPATH ${CMAKE_CURRENT_BINARY_DIR}/BuildVariables.inc)
5
6# Add the llvm-config tool.
7add_llvm_tool(llvm-config
8  llvm-config.cpp
9  )
10
11# Compute the substitution values for various items.
12get_property(LLVM_SYSTEM_LIBS_LIST TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS)
13foreach(l ${LLVM_SYSTEM_LIBS_LIST})
14  set(SYSTEM_LIBS ${SYSTEM_LIBS} "-l${l}")
15endforeach()
16string(REPLACE ";" " " SYSTEM_LIBS "${SYSTEM_LIBS}")
17
18# Fetch target specific compile options, e.g. RTTI option
19get_property(COMPILE_FLAGS TARGET llvm-config PROPERTY COMPILE_FLAGS)
20
21# Use configure_file to create BuildVariables.inc.
22set(LLVM_SRC_ROOT ${LLVM_MAIN_SRC_DIR})
23set(LLVM_OBJ_ROOT ${LLVM_BINARY_DIR})
24set(LLVM_CPPFLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
25set(LLVM_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
26set(LLVM_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}")
27set(LLVM_BUILD_SYSTEM cmake)
28set(LLVM_HAS_RTTI ${LLVM_CONFIG_HAS_RTTI})
29
30# Use the C++ link flags, since they should be a superset of C link flags.
31set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}")
32set(LLVM_BUILDMODE ${CMAKE_BUILD_TYPE})
33set(LLVM_SYSTEM_LIBS ${SYSTEM_LIBS})
34if(BUILD_SHARED_LIBS)
35  set(LLVM_ENABLE_SHARED ON)
36else()
37  set(LLVM_ENABLE_SHARED OFF)
38endif()
39string(REPLACE ";" " " LLVM_TARGETS_BUILT "${LLVM_TARGETS_TO_BUILD}")
40configure_file(${BUILDVARIABLES_SRCPATH} ${BUILDVARIABLES_OBJPATH} @ONLY)
41
42# Set build-time environment(s).
43add_definitions(-DCMAKE_CFG_INTDIR="${CMAKE_CFG_INTDIR}")
44
45# Add the dependency on the generation step.
46add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.cpp ${BUILDVARIABLES_OBJPATH})
47
48if(CMAKE_CROSSCOMPILING)
49  set(${project}_LLVM_CONFIG_EXE "${LLVM_NATIVE_BUILD}/bin/llvm-config")
50  set(${project}_LLVM_CONFIG_EXE ${${project}_LLVM_CONFIG_EXE} PARENT_SCOPE)
51
52  add_custom_command(OUTPUT "${${project}_LLVM_CONFIG_EXE}"
53    COMMAND ${CMAKE_COMMAND} --build . --target llvm-config --config $<CONFIGURATION>
54    DEPENDS ${LLVM_NATIVE_BUILD}/CMakeCache.txt
55    WORKING_DIRECTORY ${LLVM_NATIVE_BUILD}
56    COMMENT "Building native llvm-config...")
57  add_custom_target(${project}NativeLLVMConfig DEPENDS ${${project}_LLVM_CONFIG_EXE})
58  add_dependencies(${project}NativeLLVMConfig CONFIGURE_LLVM_NATIVE)
59
60  add_dependencies(llvm-config ${project}NativeLLVMConfig)
61endif(CMAKE_CROSSCOMPILING)
62