project(mydemo)
cmake_minimum_required(VERSION
3.10
)
if
(NOT DEFINED ENV{LLVM_HOME})
message(FATAL_ERROR
"Environment variable $LLVM_HOME is not defined, user should define it before running cmake!"
)
endif()
message(STATUS
"LLVM_HOME = [$ENV{LLVM_HOME}]"
)
if
(NOT DEFINED ENV{LLVM_DIR})
set
(ENV{LLVM_DIR} $ENV{LLVM_HOME}
/
lib
/
cmake
/
llvm)
endif()
if
(NOT EXISTS $ENV{LLVM_DIR})
message(STATUS
"Path ($ENV{LLVM_DIR}) not found!"
)
set
(ENV{LLVM_DIR} $ENV{LLVM_HOME}
/
lib64
/
cmake
/
llvm)
if
(NOT EXISTS $ENV{LLVM_DIR})
message(FATAL_ERROR
"Path ($ENV{LLVM_DIR}) not found!"
)
else
()
message(STATUS
"Path ($ENV{LLVM_DIR}) found!"
)
endif()
else
()
message(STATUS
"Path ($ENV{LLVM_DIR}) found!"
)
endif()
find_package(LLVM REQUIRED CONFIG)
add_definitions(${LLVM_DEFINITIONS})
include_directories(${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})
message(STATUS
"LLVM_DEFINITIONS : ${LLVM_DEFINITIONS}"
)
message(STATUS
"LLVM_INCLUDE_DIRS : ${LLVM_INCLUDE_DIRS}"
)
message(STATUS
"LLVM_LIBRARY_DIRS : ${LLVM_LIBRARY_DIRS}"
)
add_library(mydemo SHARED
.
/
src
/
mydemo.cpp
)
target_compile_features(mydemo PRIVATE cxx_range_for cxx_auto_type)
include_directories(.
/
include)
set_target_properties(mydemo PROPERTIES COMPILE_FLAGS
"-fno-rtti"
)
if
(APPLE)
set_target_properties(mydemo PROPERTIES LINK_FLAGS
"-undefined dynamic_lookup"
)
endif(APPLE)
target_link_libraries(mydemo
libLLVMCore.dll.a
libLLVMSupport.dll.a
libLLVMipo.dll.a
libLLVMDemangle.dll.a
libLLVMTransformUtils.dll.a
libLLVMAnalysis.dll.a
libpthread.a
)