Sample CMakeLists.txt file for LLVM project
The answer from arrowdodger lead me in the right way :) Because llvm_map_components_to_libraries
didn't work as expected, I had to do what it does manually which is finding the right order of dependencies. I came up with this:
set (LIBS
${LLVM_LIBRARIES_PATH}/LLVMSupport.lib
${LLVM_LIBRARIES_PATH}/LLVMCore.lib
${LLVM_LIBRARIES_PATH}/LLVMMC.lib
${LLVM_LIBRARIES_PATH}/LLVMTarget.lib
${LLVM_LIBRARIES_PATH}/LLVMAnalysis.lib
${LLVM_LIBRARIES_PATH}/LLVMipa.lib
${LLVM_LIBRARIES_PATH}/LLVMTransformUtils.lib
${LLVM_LIBRARIES_PATH}/LLVMInstCombine.lib
${LLVM_LIBRARIES_PATH}/LLVMScalarOpts.lib
${LLVM_LIBRARIES_PATH}/LLVMCodeGen.lib
${LLVM_LIBRARIES_PATH}/LLVMExecutionEngine.lib
${LLVM_LIBRARIES_PATH}/LLVMJIT.lib
${LLVM_LIBRARIES_PATH}/LLVMX86Utils.lib
${LLVM_LIBRARIES_PATH}/LLVMX86Info.lib
${LLVM_LIBRARIES_PATH}/LLVMMCParser.lib
${LLVM_LIBRARIES_PATH}/LLVMX86AsmParser.lib
${LLVM_LIBRARIES_PATH}/LLVMX86AsmPrinter.lib
${LLVM_LIBRARIES_PATH}/LLVMAsmPrinter.lib
${LLVM_LIBRARIES_PATH}/LLVMSelectionDAG.lib
${LLVM_LIBRARIES_PATH}/LLVMX86CodeGen.lib
${LLVM_LIBRARIES_PATH}/LLVMX86Disassembler.lib
${LLVM_LIBRARIES_PATH}/LLVMInterpreter.lib
)
target_link_libraries(main ${LIBS})
And then I only had some issues with debug/release lib for LLVMX86Utils
(_ITERATOR_DEBUG_LEVEL
).
Here is all information you need: http://llvm.org/docs/CMake.html#embedding-llvm-in-your-project.
You are observing such problem because some linkers can't automatically link static libraries in proper order. For this, you need to utilize llvm_map_components_to_libraries
function.