Does anyone know how to add the option `llvm-config --cxxflags --ldflags --libs`
into CMake? The tricky part for me is the backtick `
.
I need to config my CMake files to obtain a compilation command like:
g++ test.cpp -lclangBasic -I/usr/lib/llvm-6.0/include
-Wall `llvm-config --cxxflags --ldflags --libs`
I tried to use the following options, but they don't work:
add_compile_options(`llvm-config --cxxflags --ldflags --libs`)
# or
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} `llvm-config --cxxflags --ldflags --libs`")
Thank you in advance.
===============
Update 1.
Using the output from `llvm-config --cxxflags --ldflags --libs`
, I can compile successfully with the following command:
g++ test.cpp -lclangBasic -I/usr/lib/llvm-6.0/include
-Wall -I/usr/lib/llvm-6.0/include -L/usr/lib/llvm-6.0/lib -lLLVM-6.0
I can pass -I/usr/lib/llvm-6.0/include
by using include_directories(usr/lib/llvm-6.0/include)
.
But still, I don't know how to pass the part -L/usr/lib/llvm-6.0/lib -lLLVM-6.0
to CMake. Using link_directories
and target_link_libraries
like the following doesn't work for me:
link_directories(/usr/lib/llvm-6.0/lib)
target_link_libraries(test PUBLIC "LLVM-6.0")
Does anyone know to make them work in CMake?
===============
Update 2.
I have to add the following code into the file CMakeLists.txt
to make CMake work.
add_library(LLVM-6.0 SHARED IMPORTED) # or STATIC instead of SHARED
set_target_properties(LLVM-6.0 PROPERTIES
IMPORTED_LOCATION "/usr/lib/llvm-6.0/lib/libLLVM-6.0.so"
INTERFACE_INCLUDE_DIRECTORIES "/usr/lib/llvm-6.0/include"
)
add_library(clangBasic SHARED IMPORTED) # or STATIC instead of SHARED
set_target_properties(clangBasic PROPERTIES
IMPORTED_LOCATION "/usr/lib/llvm-6.0/lib/libclangBasic.a"
INTERFACE_INCLUDE_DIRECTORIES "/usr/lib/llvm-6.0/include"
)
target_link_libraries(solidity PUBLIC "LLVM-6.0;clangBasic")
However, this looks manually, and I'm still looking for better solutions...