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 if(MSVC) 15 set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}.lib") 16 else() 17 if (l MATCHES "^-") 18 # If it's an option, pass it without changes. 19 set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}") 20 else() 21 # Otherwise assume it's a library name we need to link with. 22 set(SYSTEM_LIBS ${SYSTEM_LIBS} "-l${l}") 23 endif() 24 endif() 25endforeach() 26string(REPLACE ";" " " SYSTEM_LIBS "${SYSTEM_LIBS}") 27 28# Fetch target specific compile options, e.g. RTTI option 29get_property(COMPILE_FLAGS TARGET llvm-config PROPERTY COMPILE_FLAGS) 30 31# Use configure_file to create BuildVariables.inc. 32set(LLVM_SRC_ROOT ${LLVM_MAIN_SRC_DIR}) 33set(LLVM_OBJ_ROOT ${LLVM_BINARY_DIR}) 34set(LLVM_CPPFLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}") 35set(LLVM_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}") 36set(LLVM_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}") 37set(LLVM_BUILD_SYSTEM cmake) 38set(LLVM_HAS_RTTI ${LLVM_CONFIG_HAS_RTTI}) 39set(LLVM_DYLIB_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}${LLVM_VERSION_SUFFIX}") 40set(LLVM_HAS_GLOBAL_ISEL "${LLVM_BUILD_GLOBAL_ISEL}") 41 42# Use the C++ link flags, since they should be a superset of C link flags. 43set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}") 44set(LLVM_BUILDMODE ${CMAKE_BUILD_TYPE}) 45set(LLVM_SYSTEM_LIBS ${SYSTEM_LIBS}) 46if(BUILD_SHARED_LIBS) 47 set(LLVM_ENABLE_SHARED ON) 48else() 49 set(LLVM_ENABLE_SHARED OFF) 50endif() 51string(REPLACE ";" " " LLVM_TARGETS_BUILT "${LLVM_TARGETS_TO_BUILD}") 52configure_file(${BUILDVARIABLES_SRCPATH} ${BUILDVARIABLES_OBJPATH} @ONLY) 53 54# Set build-time environment(s). 55add_definitions(-DCMAKE_CFG_INTDIR="${CMAKE_CFG_INTDIR}") 56 57# Add the dependency on the generation step. 58add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.cpp ${BUILDVARIABLES_OBJPATH}) 59 60if(CMAKE_CROSSCOMPILING) 61 set(${project}_LLVM_CONFIG_EXE "${LLVM_NATIVE_BUILD}/bin/llvm-config") 62 set(${project}_LLVM_CONFIG_EXE ${${project}_LLVM_CONFIG_EXE} PARENT_SCOPE) 63 64 add_custom_command(OUTPUT "${${project}_LLVM_CONFIG_EXE}" 65 COMMAND ${CMAKE_COMMAND} --build . --target llvm-config --config $<CONFIGURATION> 66 DEPENDS ${LLVM_NATIVE_BUILD}/CMakeCache.txt 67 WORKING_DIRECTORY ${LLVM_NATIVE_BUILD} 68 COMMENT "Building native llvm-config...") 69 add_custom_target(${project}NativeLLVMConfig DEPENDS ${${project}_LLVM_CONFIG_EXE}) 70 add_dependencies(${project}NativeLLVMConfig CONFIGURE_LLVM_NATIVE) 71 72 add_dependencies(llvm-config ${project}NativeLLVMConfig) 73endif(CMAKE_CROSSCOMPILING) 74