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