[LLVMdev] LLVM Cmake module?

Eli Gottlieb eligottlieb at gmail.com
Wed Nov 3 12:10:59 PDT 2010


I compiled and installed it to the prefix /usr, but that's not the 
issue.  Once I actually compile and install LLVM with CMake by hand, I 
get the share/llvm/cmake stuff installed correctly (can those files be 
included in "normal" builds, or will LLVM switch to CMake as its primary 
build system?).  Now I'm running into the problem of cflags or includes 
or something not being set properly.

CMakeLists.txt:
> cmake_minimum_required (VERSION 2.6)
> project (libjllvm)
> add_library(jllvm Analysis_wrap.c BitReader_wrap.c BitWriter_wrap.c 
> Core_wrap.c EnhancedDisassembly_wrap.c ExecutionEngine_wrap.c 
> LinkTimeOptimizer_wrap.c lto_wrap.c Target_wrap.c 
> Transforms/IPO_wrap.c Transforms/Scalar_wrap.c)
>
> # A convenience variable:
> set(LLVM_ROOT "/usr" CACHE /usr/ "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(LLVM)
> # Now set the header and library paths:
> include_directories( ${LLVM_ROOT}/include )
> link_directories( ${LLVM_ROOT}/lib )
> # Make sure to include the headers required for Java and JNI.
> FIND_PACKAGE(Java REQUIRED)
> FIND_PACKAGE(JNI REQUIRED)
> INCLUDE_DIRECTORIES(${JAVA_INCLUDE_PATH})
> INCLUDE_DIRECTORIES(${JAVA_INCLUDE_PATH2})
> # Let's suppose we want to build a JIT compiler with support for
> # binary code (no interpreter):
> llvm_map_components_to_libraries(REQ_LLVM_LIBRARIES jit native core)
> # Finally, we link the LLVM libraries to our executable:
> target_link_libraries(jllvm ${REQ_LLVM_LIBRARIES})

I run "cmake ." where I've got my source and then make.  This results in:
> eli at eli-netbook:~/Programs/decac/src/jllvm/llvm$ make
> Scanning dependencies of target jllvm
> [  9%] Building C object CMakeFiles/jllvm.dir/Analysis_wrap.c.o
> In file included from /usr/include/llvm-c/Core.h:36,
>                  from /usr/include/llvm-c/Analysis.h:22,
>                  from 
> /home/eli/Programs/decac/src/jllvm/llvm/Analysis_wrap.c:190:
> /usr/include/llvm/System/DataTypes.h:46: error: #error "Must #define 
> __STDC_LIMIT_MACROS before #including System/DataTypes.h"
> /usr/include/llvm/System/DataTypes.h:50: error: #error "Must #define 
> __STDC_CONSTANT_MACROS before " "#including System/DataTypes.h"
> make[2]: *** [CMakeFiles/jllvm.dir/Analysis_wrap.c.o] Error 1
> make[1]: *** [CMakeFiles/jllvm.dir/all] Error 2
> make: *** [all] Error 2

Thanks for all your help,
Eli



More information about the llvm-dev mailing list