llvm.org GIT mirror llvm / 23ba1e4
Document how to build a LLVM pass with CMake out of source. Patch by arrowdodger! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129381 91177308-0d34-0410-b5e6-96231b3b80d8 Oscar Fuentes 9 years ago
2 changed file(s) with 61 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
2121
  • Executing the test suite
  • 2222
  • Cross compiling
  • 2323
  • Embedding LLVM in your project
  • 24
    25
  • Developing LLVM pass out of source
  • 26
    2427
  • Compiler/Platform specific topics
  • 2528
    2629
  • Microsoft Visual C++
  • 457460
    458461
    459462
    463
    464
    465 Developing LLVM pass out of source
    466
    467
    468
    469
    470

    It is possible to develop LLVM passes against installed LLVM.

    471 An example of project layout provided below:

    472
    473
    474
    
                      
                    
    475 <project dir>/
    476 |
    477 CMakeLists.txt
    478 <pass name>/
    479 |
    480 CMakeLists.txt
    481 Pass.cpp
    482 ...
    483
    484
    485
    486

    Contents of <project dir>/CMakeLists.txt:

    487
    488
    489
    
                      
                    
    490 find_package(LLVM)
    491
    492 # Define add_llvm_* macro's.
    493 include(AddLLVM)
    494
    495 add_definitions(${LLVM_DEFINITIONS})
    496 include_directories(${LLVM_INCLUDE_DIRS})
    497 link_directories(${LLVM_LIBRARY_DIRS})
    498
    499 add_subdirectory(<pass name>)
    500
    501
    502
    503

    Contents of <project dir>/<pass name>/CMakeLists.txt:

    504
    505
    506
    
                      
                    
    507 add_llvm_loadable_module(LLVMPassname
    508 Pass.cpp
    509 )
    510
    511
    512
    513

    When you are done developing your pass, you may wish to integrate it

    514 into LLVM source tree. You can achieve it in two easy steps:
    515 1. Copying <pass name> folder into <LLVM root>/lib/Transform directory.
    516 2. Adding "add_subdirectory(<pass name>)" line into <LLVM root>/lib/Transform/CMakeLists.txt

    517
    460518
    461519
    462520
    210210 If your operating system uses a suffix other than .so (such as windows or
    211211 Mac OS/X), the appropriate extension will be used.

    212212
    213

    If you are used CMake to build LLVM, see

    214 Developing an LLVM pass with CMake.

    215
    213216

    Now that we have the build scripts set up, we just need to write the code for

    214217 the pass itself.

    215218