project(mydemo)
cmake_minimum_required(VERSION 3.10)
if(NOT DEFINED ENV{LLVM_HOME})
# User must define the LLVM_HOME environment that point to the root installation dir of llvm
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})
# Default llvm config file path
set(ENV{LLVM_DIR} $ENV{LLVM_HOME}/lib/cmake/llvm)
endif()
# Check the path
if (NOT EXISTS $ENV{LLVM_DIR})
message(STATUS "
ath ($ENV{LLVM_DIR}) not found!")
# If default llvm config path not found, try this one,
# which is config with [-DLLVM_LIBDIR_SUFFIX=64] before building llvm
set(ENV{LLVM_DIR} $ENV{LLVM_HOME}/lib64/cmake/llvm)
if (NOT EXISTS $ENV{LLVM_DIR})
message(FATAL_ERROR "
ath ($ENV{LLVM_DIR}) not found!")
else()
message(STATUS "
ath ($ENV{LLVM_DIR}) found!")
endif()
else()
message(STATUS "
ath ($ENV{LLVM_DIR}) found!")
endif()
# Enable verbose output for debug,
# Same as: cmake -D CMAKE_VERBOSE_MAKEFILE=ON or make VERBOSE=1
# set(CMAKE_VERBOSE_MAKEFILE on)
find_package(LLVM REQUIRED CONFIG)
add_definitions(${LLVM_DEFINITIONS})
include_directories(${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})
# Debug
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
# Add your source file here, header file is not neccessary
./src/mydemo.cpp
)
# Use C++11 to compile your pass (i.e., supply -std=c++11).
target_compile_features(mydemo PRIVATE cxx_range_for cxx_auto_type)
include_directories(./include)
# LLVM is (typically) built with no C++ RTTI. We need to match that;
# otherwise, we'll get linker errors about missing RTTI data.
set_target_properties(mydemo PROPERTIES COMPILE_FLAGS "-fno-rtti")
# Get proper shared-library behavior (where symbols are not necessarily
# resolved when the shared library is linked) on OS X.
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
)