[LLVMdev] building a pass with cmake

erkan diken erkandiken at gmail.com
Mon Jul 23 07:18:02 PDT 2012


Dear all,

I want to build an LLVM pass by using CMake.

After reading the ralevant part of the documentation (
http://llvm.org/releases/3.1/docs/CMake.html#passdev),
I copied the files in the llvm/lib/Transforms/Hello to another folder in
order to give a try.
Then  I renamed the folder as Hello2.
Then I have changed CMakeLists.txt as following:

cmake_minimum_required(VERSION 2.8)

# A convenience variable:
set(LLVM_ROOT "../llvm_cmake_build" CACHE PATH "Root of LLVM install.")

# A bit of a sanity check:
if( NOT EXISTS ${LLVM_ROOT}/include/llvm )
message(FATAL_ERROR "LLVM_ROOT (${LLVM_ROOT}) is not a valid LLVM install")
endif()

# We incorporate the CMake features provided by LLVM:
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LLVM_ROOT}/share/llvm/cmake")
include(LLVMConfig)

find_package(LLVM)

if( NOT LLVM_FOUND )
  message(FATAL_ERROR "LLVM package can't be found. Set CMAKE_PREFIX_PATH
variable to LLVM's installation prefix.")
endif()

# Define add_llvm_* macro's.
include(AddLLVM)

add_definitions(${LLVM_DEFINITIONS})
include_directories(${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})


add_llvm_loadable_module( LLVMHello
  Hello.cpp
  )

Furthermore, I created a separate build and install directories in order to
build and install my pass.
cd Hello2_build
cmake ../Hello2 -DCMAKE_INSTALL_PREFIX=../Hello2_install/

-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done

It seems that cmake is ok. When I run make install, it gives errors (see
below) and i think the reason is that it can not find the directory to llvm
header files.
I could not figure it out which variable to set and how to use it in order
to point the required directory ?
( as in the make pass build which requires LLVM_SRC_ROOT LLVM_OBJ_ROOT
variables to be set)

Hello2/Hello.cpp:17:23: error: llvm/Pass.h: No such file or directory
Hello2/Hello.cpp:18:27: error: llvm/Function.h: No such file or directory
Hello2/Hello.cpp:19:38: error: llvm/Support/raw_ostream.h: No such file or
directory
Hello2/Hello.cpp:20:32: error: llvm/ADT/Statistic.h: No such file or
directory
Hello2/Hello.cpp:21: error: ‘llvm’ is not a namespace-name
...

Your feedback is very welcome.
Thanks.

-- 
Best Regards,
Erkan
------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120723/517155df/attachment.html>


More information about the llvm-dev mailing list