{"id":46518767,"url":"https://github.com/compor/llvm-ir-cmake-utils","last_synced_at":"2026-03-06T18:58:19.825Z","repository":{"id":38898722,"uuid":"64301799","full_name":"compor/llvm-ir-cmake-utils","owner":"compor","description":"LLVM IR CMake utils for bitcode file manipulation by opt and friends","archived":false,"fork":false,"pushed_at":"2023-10-24T12:51:31.000Z","size":49,"stargazers_count":57,"open_issues_count":8,"forks_count":15,"subscribers_count":6,"default_branch":"master","last_synced_at":"2023-10-24T13:41:16.492Z","etag":null,"topics":["bitcode","cmake","intermediate-representation","llvm"],"latest_commit_sha":null,"homepage":"","language":"CMake","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-2.1","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/compor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-07-27T11:07:25.000Z","updated_at":"2023-10-19T16:52:46.000Z","dependencies_parsed_at":"2023-02-18T09:30:41.846Z","dependency_job_id":"e4ec5112-6ae7-4ef0-b0a0-30c2b32ff5a8","html_url":"https://github.com/compor/llvm-ir-cmake-utils","commit_stats":null,"previous_names":[],"tags_count":40,"template":null,"template_full_name":null,"purl":"pkg:github/compor/llvm-ir-cmake-utils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compor%2Fllvm-ir-cmake-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compor%2Fllvm-ir-cmake-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compor%2Fllvm-ir-cmake-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compor%2Fllvm-ir-cmake-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/compor","download_url":"https://codeload.github.com/compor/llvm-ir-cmake-utils/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compor%2Fllvm-ir-cmake-utils/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30192250,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T18:54:55.862Z","status":"ssl_error","status_checked_at":"2026-03-06T18:53:04.013Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitcode","cmake","intermediate-representation","llvm"],"created_at":"2026-03-06T18:58:19.279Z","updated_at":"2026-03-06T18:58:19.812Z","avatar_url":"https://github.com/compor.png","language":"CMake","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LLVM IR cmake utilities\n\n## Introduction\n\nA collection of helper `cmake` functions/macros that eases the generation of `LLVM` IR and the application of various\n`LLVM` `opt` passes while obtaining and preserving the separate IR files that are generated by each user-defined step.\n\n## Requirements\n\n-   [`cmake`][1] 3.0.0 or later\n-   [`LLVM`][2] tools:\n    -   Currently used:\n        -   `clang/clang++`\n        -   `opt`\n        -   `llvm-dis` / `llvm-as`\n        -   `llvm-link`\n    -   Tested with:\n        -   3.7 and later\n\n## Installation\n\n-   Clone this repo (or even add it as a submodule to your project).\n-   In your `CMakeLists.txt` file `include(LLVMIRUtil)`.\n-   You are good to go!\n\n## Quick overview\n\nThe provided `cmake` commands are expected to work in a parasitic way to targets created via `add_executable()` and\n`add_library`. The \"gateway\" command is `llvmir_attach_bc_target()` which generates the required bitcode files.\nCurrently, `C/C++` are supported via `clang/clang++`, but in theory any compiler which produces `LLVM` bitcode should be\neasily supported (depending how nice it plays with `cmake` too).\n\nThe `cmake` calls currently provided are:\n\n-   `llvmir_attach_bc_target()`\n  Attaches to an existing target that can be compiled down to `LLVM IR` and does just that, using all the related flags\n  and options from the main target. The existing supported targets make use of `clang/clang++`, so currently this means\n  that the `C/C++` language is supported. It uses `add_custom_library()` `cmake` command under the hood. This creates a\n  target of type `LLVMIR`.\n\n-   `llvmir_attach_opt_pass_target()`\n  Attaches to a target of type `LLVMIR` and applies various `opt` passes to its bitcode files, specified as arguments.\n  It uses `add_custom_library()` `cmake` command under the hood. This creates a target of type `LLVMIR`.\n\n-   `llvmir_attach_disassemble_target()`\n  Attaches to a target of type `LLVMIR` and uses `llvm-dis` to disassemble its bitcode files. It uses\n  `add_custom_library()` `cmake` command under the hood. This creates a target of type `LLVMIR`.\n\n-   `llvmir_attach_assemble_target()`\n  Attaches to a target of type `LLVMIR` and uses `llvm-as` to assemble its bitcode files. It uses `add_custom_library()`\n  `cmake` command under the hood. This creates a target of type `LLVMIR`.\n\n-   `llvmir_attach_link_target()`\n  Attaches to a target of type `LLVMIR` and uses `llvm-link` to link its bitcode files to a single bitcode file. The\n  output bitcode file is names after the target name. It uses `add_custom_library()` `cmake` command under the hood.\n  This creates a target of type `LLVMIR`.\n\n-   `llvmir_attach_library()`\n  Attaches to a target of type `LLVMIR` and uses the appropriate compiler to compile its bitcode files to a native\n  library. The output library name uses the target name according to platform rules. It uses `add_library()` `cmake`\n  command under the hood. This creates a target of type `LLVMIR`.\n\n-   `llvmir_attach_executable()`\n  Attaches to a target of type `LLVMIR` and uses the appropriate compiler to compile its bitcode files to a native\n  executable. The output library name uses the target name according to platform rules. It uses `add_executable()`\n  `cmake` command under the hood. This creates a target of type `LLVMIR`.\n\n### Influential properties\n\n- `LLVMIR_SHORT_NAME`\n  This property, if present, controls the output name for the calls that produce a single object (e.g. archive, library,\n  etc.):\n  - `llvmir_attach_link_target()`\n  - `llvmir_attach_library()`\n  - `llvmir_attach_executable()`\n\n\n_CAUTION_\n\nIf you require to get raw _unoptimized_ `LLVM` IR, but with the ability to further optimize it later on and you are\ncompiling  with `LLVM` 5 or later, you need to add the following compile options, either:\n\n```bash\n-O1 -Xclang -disable-llvm-passes\n```\n\nor\n\n```bash\n-O0 -Xclang -disable-O0-optnone\n```\n\nThis is because, since `LLVM` 5, using `-O0` add the `optnone` attribute to all functions.\n\n## Basic Usage\n\nHave a look and toy around with the included examples in this repo. The easiest way to start is:\n\n1.  `git clone` this repo.\n2.  Create a directory for an out-of-source build and `cd` into it.\n3.  `CC=clang CXX=clang++ cmake [path to example source dir]`\n4.  `cmake --build .`\n5.  `cmake --build . --target help` to see available target and use them for bitcode generation.\n\n[1]: https://cmake.org\n\n[2]: www.llvm.org\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompor%2Fllvm-ir-cmake-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcompor%2Fllvm-ir-cmake-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompor%2Fllvm-ir-cmake-utils/lists"}