{"id":15136958,"url":"https://github.com/aminya/project_options","last_synced_at":"2025-04-08T09:12:49.417Z","repository":{"id":38187027,"uuid":"409011266","full_name":"aminya/project_options","owner":"aminya","description":"A general-purpose CMake library that provides functions that improve the CMake experience following the best practices.","archived":false,"fork":false,"pushed_at":"2024-11-12T13:56:19.000Z","size":20074,"stargazers_count":365,"open_issues_count":39,"forks_count":56,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-04-01T08:39:21.868Z","etag":null,"topics":["c","clang-tidy","cmake","cmake-modules","cmake-template","conan","cpp","cppcheck","hacktoberfest","project","sanitizer","starter","starter-project","vcpkg"],"latest_commit_sha":null,"homepage":"https://aminya.github.io/project_options/","language":"CMake","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aminya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["aminya"],"polar":"aminya","patreon":"aminya"}},"created_at":"2021-09-22T00:11:30.000Z","updated_at":"2025-03-07T16:13:46.000Z","dependencies_parsed_at":"2023-11-14T07:24:29.487Z","dependency_job_id":"0867f4b8-3efd-4410-a1a5-41a042a1ef73","html_url":"https://github.com/aminya/project_options","commit_stats":{"total_commits":667,"total_committers":22,"mean_commits":"30.318181818181817","dds":0.2863568215892054,"last_synced_commit":"ca3ecdcda321940a6ecb6552b665950bba49756a"},"previous_names":[],"tags_count":75,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminya%2Fproject_options","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminya%2Fproject_options/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminya%2Fproject_options/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminya%2Fproject_options/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aminya","download_url":"https://codeload.github.com/aminya/project_options/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247809964,"owners_count":20999816,"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":["c","clang-tidy","cmake","cmake-modules","cmake-template","conan","cpp","cppcheck","hacktoberfest","project","sanitizer","starter","starter-project","vcpkg"],"created_at":"2024-09-26T06:42:09.912Z","updated_at":"2025-04-08T09:12:49.375Z","avatar_url":"https://github.com/aminya.png","language":"CMake","readme":"# project_options\n\nA general-purpose CMake library that provides functions that improve the\nCMake experience following the best practices.\n\n[![documentation](https://img.shields.io/badge/documentation-blue?style=flat\u0026logo=docs.rs\u0026link=https://aminya.github.io/project_options/)](https://aminya.github.io/project_options/)\n\n[![ci](https://github.com/aminya/project_options/actions/workflows/ci.yml/badge.svg)](https://github.com/aminya/project_options/actions/workflows/ci.yml)\n\n## Features\n\n-   `project_options`:\n    -   compiler warnings,\n    -   compiler optimizations (intraprocedural, native),\n    -   caching (ccache, sccache),\n    -   sanitizers,\n    -   static code analyzers (clang-tidy, cppcheck, visual studio,\n        include-what-you-use),\n    -   document generation (doxygen),\n    -   test coverage analysis,\n    -   precompiled headers,\n    -   build time measurement,\n    -   unity builds\n    -   using custom linkers (e.g. lld)\n-   `package_project`: automatic packaging/installation of the project\n    for seamless usage via find_package/target_link through CMake's\n    FetchContent, vcpkg, etc.\n-   `run_vcpkg`: automatic installation of vcpkg and the project\n    dependencies\n-   `run_conan`: automatic installation of conan and the project\n    dependencies\n-   `dynamic_project_options`: a wrapper around `project_options` to\n    change the options on the fly dynamically\n-   `target_link_system_libraries` and\n    `target_include_system_directories`: linking/including external\n    dependencies/headers without warnings\n-   `target_link_cuda`: linking Cuda to a target\n\n## Documentation\n\nThe full documentation is available here:\n\n\u003chttps://aminya.github.io/project_options/\u003e\n\n## `project_options` function\n\nSee the `project_options()` in action in [this template\nrepository](https://github.com/aminya/cpp_vcpkg_project).\n[cpp_vcpkg_project](https://github.com/aminya/cpp_vcpkg_project) has\nprepared all the best practices for a production-ready C++ project.\n\n### `project` and `project_options`\n\nHere is an example of the usage:\n\n``` cmake\ncmake_minimum_required(VERSION 3.20)\n\n# set a default CXX standard for the tools and targets that do not specify them.\n# If commented, the latest supported standard for your compiler is automatically set.\n# set(CMAKE_CXX_STANDARD 20)\n\ninclude(FetchContent)\nif(CMAKE_VERSION VERSION_GREATER_EQUAL \"3.24.0\")\n  cmake_policy(SET CMP0135 NEW)\nendif()\n\n# Add project_options from https://github.com/aminya/project_options\n# Change the version in the following URL to update the package (watch the releases of the repository for future updates)\nset(PROJECT_OPTIONS_VERSION \"v0.41.0\")\nFetchContent_Declare(\n  _project_options\n  URL https://github.com/aminya/project_options/archive/refs/tags/${PROJECT_OPTIONS_VERSION}.zip)\nFetchContent_MakeAvailable(_project_options)\ninclude(${_project_options_SOURCE_DIR}/Index.cmake)\n\n# install vcpkg dependencies: - should be called before defining project()\nrun_vcpkg(\n    VCPKG_URL \"https://github.com/microsoft/vcpkg.git\"\n    VCPKG_REV \"86a181505ac6460f98496a79abdee6a0f49905ec\"\n)\n# Install conan dependencies: - should be called before defining project()\nrun_conan()\n\n# Set the project name and language\nproject(myproject LANGUAGES CXX C)\n\n# Build Features\noption(FEATURE_TESTS \"Enable the tests\" OFF)\noption(FEATURE_DOCS \"Enable the docs\" OFF)\n\n# vcpkg test feature\nif(FEATURE_TESTS)\n  list(APPEND VCPKG_MANIFEST_FEATURES \"tests\")\nendif()\n\n# Enable sanitizers and static analyzers when running the tests\nif(FEATURE_TESTS)\n  set(ENABLE_CLANG_TIDY \"ENABLE_CLANG_TIDY\")\n  set(ENABLE_CPPCHECK \"ENABLE_CPPCHECK\")\n  set(ENABLE_COVERAGE \"ENABLE_COVERAGE\")\n\n  set(ENABLE_SANITIZER_ADDRESS \"ENABLE_SANITIZER_ADDRESS\")\n  set(ENABLE_SANITIZER_UNDEFINED \"ENABLE_SANITIZER_UNDEFINED\")\nendif()\n\n# Enable doxgen for the docs\nif(FEATURE_DOCS)\n  set(ENABLE_DOXYGEN \"ENABLE_DOXYGEN\")\nendif()\n\n# Initialize project_options variable related to this project\n# This overwrites `project_options` and sets `project_warnings`\n# uncomment to enable the options. Some of them accept one or more inputs:\nproject_options(\n      PREFIX \"myproject\"\n      ENABLE_CACHE\n      ${ENABLE_CPPCHECK}\n      ${ENABLE_CLANG_TIDY}\n      ENABLE_VS_ANALYSIS\n      # ENABLE_INTERPROCEDURAL_OPTIMIZATION\n      # ENABLE_NATIVE_OPTIMIZATION\n      ${ENABLE_DOXYGEN}\n      ${ENABLE_COVERAGE}\n      ${ENABLE_SANITIZER_ADDRESS}\n      ${ENABLE_SANITIZER_UNDEFINED}\n      # ${ENABLE_SANITIZER_THREAD}\n      # ${ENABLE_SANITIZER_MEMORY}\n      # ENABLE_SANITIZER_POINTER_COMPARE\n      # ENABLE_SANITIZER_POINTER_SUBTRACT\n      # ENABLE_CONTROL_FLOW_PROTECTION\n      # ENABLE_STACK_PROTECTION\n      # ENABLE_OVERFLOW_PROTECTION\n      # ENABLE_ELF_PROTECTION\n      # ENABLE_RUNTIME_SYMBOLS_RESOLUTION\n      # ENABLE_COMPILE_COMMANDS_SYMLINK\n      # ENABLE_PCH\n      # PCH_HEADERS\n      # WARNINGS_AS_ERRORS\n      # ENABLE_INCLUDE_WHAT_YOU_USE\n      # ENABLE_GCC_ANALYZER\n      # ENABLE_BUILD_WITH_TIME_TRACE\n      # ENABLE_UNITY\n      # LINKER \"lld\"\n)\n```\n\nThen add the executables or libraries to the project:\n\n### [executable usage](https://github.com/aminya/cpp_vcpkg_project/tree/main/my_exe)\n\n``` cmake\nadd_executable(main main.cpp)\n\n# link project_options/warnings\ntarget_link_libraries(main\n  PRIVATE myproject_project_options myproject_project_warnings\n)\n\n# Find dependencies:\ntarget_find_dependencies(main\n  PRIVATE_CONFIG\n  fmt\n  Eigen3\n)\n\n# Link dependencies\ntarget_link_system_libraries(main\n  PRIVATE\n  fmt::fmt\n  Eigen3::Eigen\n)\n\n# Package the project\npackage_project(TARGETS main)\n```\n\n### [library usage](https://github.com/aminya/cpp_vcpkg_project/tree/main/my_lib)\n\n``` cmake\nadd_library(my_lib \"./src/my_lib/lib.cpp\")\n\n# link project_options/warnings\ntarget_link_libraries(my_lib\n  PRIVATE myproject_project_options myproject_project_warnings\n)\n\n# Includes:\ntarget_include_interface_directories(my_lib \"${CMAKE_CURRENT_SOURCE_DIR}/include\")\n\n# Find dependencies:\ntarget_find_dependencies(my_lib\n  PRIVATE_CONFIG\n  fmt\n  Eigen3\n)\n\n# Link dependencies:\ntarget_link_system_libraries(my_lib\n  PRIVATE\n  fmt::fmt\n  Eigen3::Eigen\n)\n\n# Package the project\npackage_project(\n  # Note that you must export `myproject_project_options` and `myproject_project_warnings` for `my_lib`\n  TARGETS my_lib myproject_project_options myproject_project_warnings\n)\n```\n\n### [header-only library usage](https://github.com/aminya/cpp_vcpkg_project/tree/main/my_header_lib)\n\n``` cmake\nadd_library(my_header_lib INTERFACE)\n\n# link project_options/warnings\ntarget_link_libraries(my_header_lib\n  INTERFACE myproject_project_options myproject_project_warnings\n)\n\n# Includes:\ntarget_include_interface_directories(my_header_lib \"${CMAKE_CURRENT_SOURCE_DIR}/include\")\n\n# Find dependencies:\ntarget_find_dependencies(my_header_lib\n  INTERFACE_CONFIG\n  fmt\n  Eigen3\n)\n\n# Link dependencies:\ntarget_link_system_libraries(my_header_lib\n  INTERFACE\n  fmt::fmt\n  Eigen3::Eigen\n)\n\n# Package the project\npackage_project(\n  TARGETS my_header_lib myproject_project_options myproject_project_warnings\n)\n```\n\n## License\n\nThis project can be used under the terms of either the [MIT\nlicense](../../LICENSE.txt) or the [Unlicense](../../Unlicense.txt)\ndepending on your choice.\n","funding_links":["https://github.com/sponsors/aminya","https://polar.sh/aminya","https://patreon.com/aminya"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faminya%2Fproject_options","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faminya%2Fproject_options","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faminya%2Fproject_options/lists"}