{"id":29948471,"url":"https://github.com/retifrav/cmake-target-link-libraries-example","last_synced_at":"2025-08-26T00:27:23.125Z","repository":{"id":182298556,"uuid":"666518473","full_name":"retifrav/cmake-target-link-libraries-example","owner":"retifrav","description":"An example of CMake target_link_libraries() scopes effects","archived":false,"fork":false,"pushed_at":"2023-10-07T15:44:13.000Z","size":40,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-01T21:33:09.850Z","etag":null,"topics":["cmake","cpp","example"],"latest_commit_sha":null,"homepage":"","language":"CMake","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/retifrav.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":["retifrav"]}},"created_at":"2023-07-14T18:19:55.000Z","updated_at":"2023-07-23T19:15:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"2746c5ef-14e4-460a-9aab-6ce8fd8494ad","html_url":"https://github.com/retifrav/cmake-target-link-libraries-example","commit_stats":null,"previous_names":["retifrav/cmake-target-link-libraries-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/retifrav/cmake-target-link-libraries-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/retifrav%2Fcmake-target-link-libraries-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/retifrav%2Fcmake-target-link-libraries-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/retifrav%2Fcmake-target-link-libraries-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/retifrav%2Fcmake-target-link-libraries-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/retifrav","download_url":"https://codeload.github.com/retifrav/cmake-target-link-libraries-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/retifrav%2Fcmake-target-link-libraries-example/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268512163,"owners_count":24261889,"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","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["cmake","cpp","example"],"created_at":"2025-08-03T08:16:49.632Z","updated_at":"2025-08-03T08:17:01.596Z","avatar_url":"https://github.com/retifrav.png","language":"CMake","readme":"# CMake target_link_libraries() scopes example\r\n\r\nAn example of particular effects from `PRIVATE`/`INTERFACE`/`PUBLIC` scope in CMake's `target_link_libraries()`.\r\n\r\nMore details in the [following article](https://decovar.dev/blog/2023/07/22/cmake-target-link-libraries-scopes/).\r\n\r\nUnlike the code fragments in the article, the `prjct` here handles linking scope via `THINGY_LINKING` cache variable, for example `-DTHINGY_LINKING=\"INTERFACE\"`. Based on that, certain target properties are set and carried over, changing certain compile definitions, making the compilation to account for the current linking scope \"automatically\" (*so you don't need to modify the sources yourself*).\r\n\r\n## Building\r\n\r\nIt is 3 projects that are built individually and in particular order:\r\n\r\n1. `dpndnc` - a library made to be a direct dependency of `prjct`;\r\n2. `prjct` - a project with two libraries, one of which directly depends on `dpndnc`;\r\n3. `tl` - a CLI tool that directly depends on `prjct` libraries and also transitively depends on `dpndnc`.\r\n\r\n### dpndnc\r\n\r\n``` sh\r\n$ cd /path/to/cmake-target-link-libraries-example/dpndnc\r\n$ mkdir build \u0026\u0026 cd $_\r\n$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=\"../install\" ..\r\n$ cmake --build . --target install\r\n```\r\n\r\n### prjct\r\n\r\n``` sh\r\n$ cd /path/to/cmake-target-link-libraries-example/prjct\r\n$ mkdir build \u0026\u0026 cd $_\r\n$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=\"../install\" \\\r\n    -DCMAKE_PREFIX_PATH=\"/path/to/cmake-target-link-libraries-example/dpndnc/install\" \\\r\n    -DTHINGY_LINKING=\"INTERFACE\" \\\r\n    ..\r\n$ cmake --build . --target install\r\n```\r\n\r\n### tl\r\n\r\n``` sh\r\n$ cd /path/to/cmake-target-link-libraries-example/tl\r\n$ mkdir build \u0026\u0026 cd $_\r\n$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=\"../install\" \\\r\n    -DCMAKE_PREFIX_PATH=\"/path/to/cmake-target-link-libraries-example/prjct/install;/path/to/cmake-target-link-libraries-example/dpndnc/install\" \\\r\n    ..\r\n$ cmake --build . --target install\r\n$ ../install/bin/some-tool\r\n```\r\n","funding_links":["https://github.com/sponsors/retifrav"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fretifrav%2Fcmake-target-link-libraries-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fretifrav%2Fcmake-target-link-libraries-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fretifrav%2Fcmake-target-link-libraries-example/lists"}