{"id":16890843,"url":"https://github.com/grisumbras/object-libraries","last_synced_at":"2026-01-04T12:31:17.699Z","repository":{"id":83306780,"uuid":"112537187","full_name":"grisumbras/object-libraries","owner":"grisumbras","description":"Helper functions to manage CMake object libraries","archived":false,"fork":false,"pushed_at":"2017-11-29T23:01:15.000Z","size":5,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-25T09:12:35.006Z","etag":null,"topics":["cmake","objects"],"latest_commit_sha":null,"homepage":null,"language":"CMake","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/grisumbras.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,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-29T22:55:17.000Z","updated_at":"2023-07-02T07:35:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"4e0ecb1b-4539-4d19-b7b1-33517947b819","html_url":"https://github.com/grisumbras/object-libraries","commit_stats":{"total_commits":2,"total_committers":1,"mean_commits":2.0,"dds":0.0,"last_synced_commit":"dca45a488b2e987e408d03d362d67fdf6b8a894d"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grisumbras%2Fobject-libraries","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grisumbras%2Fobject-libraries/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grisumbras%2Fobject-libraries/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grisumbras%2Fobject-libraries/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grisumbras","download_url":"https://codeload.github.com/grisumbras/object-libraries/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244574798,"owners_count":20474818,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["cmake","objects"],"created_at":"2024-10-13T17:04:41.777Z","updated_at":"2026-01-04T12:31:12.674Z","avatar_url":"https://github.com/grisumbras.png","language":"CMake","funding_links":[],"categories":[],"sub_categories":[],"readme":"# object-libraries\n\n\u003e Helper functions to manage CMake object libraries\n\nIt is sometimes desirable to treat some object files as a separate entity,\nwithout linking or archiving them. CMake provides **object libraries** for\nthat, but using them isn't exactly straightforward. This project attempts to\nmitigate the issue.\n\n\n## Table of Contents\n\n* [Background](#background)\n* [Install](#install)\n* [Usage](#usage)\n* [API](#api)\n  + [`add_object_files`](#add_object_files)\n  + [`get_underlying_objects`](#get_underlying_objects)\n* [Contribute](#contribute)\n* [License](#license)\n\n\n## Background\n\nSo, what are the reasons to using object files that are not linked into a\nbinary? The number one reason is object file reuse. Suppose you have an\nexecutable and a unit test runner, they obviously need to share object files\nthat contain the code being tested. Another reason is setting special compiler\nflags for a subset of object files.\n\nNow, why the need for a dedicated project to create object libraries, after\nall, CMake already has a command that does it? Well, have you used a CMake\nobject library? Was it as convenient and idiomatic as using proper libraries?\nThis project tries to provide an interface to create object libraries in such\na way, so using them is simple.\n\n\n## Install\n\nThis package requires at least CMake 3.5.  It can be installed from sources\nusing CMake. First, obtain a copy of the sources via git or otherwise:\n\n```shell\n$ git clone https://github.com/grisumbras/object-libraries.git\n```\n\nAfter that, you can either install it, or use it as a subproject of your\nproject. For the former, enter the project directory, then run CMake to\nconfigure and install.\n\n```shell\n$ cd object-libraries\n$ cmake -DCMAKE_INSTALL_PREFIX=your/install/prefix .\n$ cmake --build . --target install\n```\n\nFor the latter, no further actions needed.\n\n\n## Usage\n\nIn order to use the _installed_ package, you need to import it inside one of\nyour `CMakeLists.txt` files:\n\n```cmake\nfind_package(ObjectLibraries)\n```\n\nIn order to use the project as a subproject, use `add_subdirectory` command,\nbut specify the build directory also:\n\n```cmake\nadd_subdirectory(path/to/object-libraries/sources object-libraries)\n```\n\n\n## API\n\n### add_object_files\n\n`add_object_files(\u003ctarget\u003e [NO_INCLUDE_CURRENT_DIR] source1 [source2 ...])`\n\nAdds two targets: a backend **object library**, that compiles specified sources\ninto object files, and a frontend **interface library**, called `\u003ctarget\u003e`,\nthat could be used by dependent targets to link with those object files. If\nyou need to set some properties on object files, you can use standard commands\non the frontend target. By defalt, `\u003ctarget\u003e` adds current source directory\nto the list of include directories of its dependent targets, to disable that\nuse `NO_INCLUDE_CURRENT_DIR` option. Example usage:\n\n```cmake\nadd_object_files(foo_objs a.cpp b.cpp)\ntarget_compile_definitions(foo_objs FOO_MACRO)\n\nadd_executable(foo main.cpp)\ntarget_link_libraries(foo PRIVATE foo_objs)\n\nadd_executable(foo-test test.cpp)\ntarget_link_libraries(foo PRIVATE foo_objs)\n```\n\n\n### get_underlying_objects\n\n`get_underlying_objects(\u003cvar\u003e \u003ctarget\u003e)`\n\nSets `\u003cvar\u003e` to the name of the backend object library corresponding to the\ninterface library `\u003ctarget\u003e`, that was created by `add_object_files`.\nUsually, you only have to deal with the frontend target, but for the cases,\nwhere that is not enough, you can use this function. Example usage:\n\n```cmake\nadd_object_files(objs x.cpp)\nget_underlying_objects(objs_bkend objs)\n# set an option for a single object file, not for the whole linked binary\ntarget_compile_options(objs_bkend -fobscure-option)\n```\n\n## License\n\n[BSL-1.0](./LICENSE) (C) Dmitry Arkhipov\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrisumbras%2Fobject-libraries","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrisumbras%2Fobject-libraries","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrisumbras%2Fobject-libraries/lists"}