• Stars
    star
    263
  • Rank 152,342 (Top 4 %)
  • Language CMake
  • License
    MIT License
  • Created almost 3 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A general-purpose CMake library that provides functions that improve the CMake experience following the best practices.

project_options

A general-purpose CMake library that provides functions that improve the CMake experience following the best practices.

documentation

ci

Features

  • project_options:
    • compiler warnings,
    • compiler optimizations (intraprocedural, native),
    • caching (ccache, sccache),
    • sanitizers,
    • static code analyzers (clang-tidy, cppcheck, visual studio, include-what-you-use),
    • document generation (doxygen),
    • test coverage analysis,
    • precompiled headers,
    • build time measurement,
    • unity builds
    • using custom linkers (e.g.ย lld)
  • package_project: automatic packaging/installation of the project for seamless usage via find_package/target_link through CMake's FetchContent, vcpkg, etc.
  • run_vcpkg: automatic installation of vcpkg and the project dependencies
  • ENABLE_CONAN in project_options: automatic installation of Conan and the project dependencies
  • dynamic_project_options: a wrapper around project_options to change the options on the fly dynamically
  • target_link_system_libraries and target_include_system_directories: linking/including external dependencies/headers without warnings
  • target_link_cuda: linking Cuda to a target

Documentation

The full documentation is available here:

https://aminya.github.io/project_options/

project_options function

See the project_options() in action in this template repository. cpp_vcpkg_project has prepared all the best practices for a production-ready C++ project.

project and project_options

Here is an example of the usage:

cmake_minimum_required(VERSION 3.20)

# set a default CXX standard for the tools and targets that do not specify them.
# If commented, the latest supported standard for your compiler is automatically set.
# set(CMAKE_CXX_STANDARD 20)

include(FetchContent)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
  cmake_policy(SET CMP0135 NEW)
endif()

# Add project_options from https://github.com/aminya/project_options
# Change the version in the following URL to update the package (watch the releases of the repository for future updates)
set(PROJECT_OPTIONS_VERSION "v0.29.0")
FetchContent_Declare(
  _project_options
  URL https://github.com/aminya/project_options/archive/refs/tags/${PROJECT_OPTIONS_VERSION}.zip)
FetchContent_MakeAvailable(_project_options)
include(${_project_options_SOURCE_DIR}/Index.cmake)

# install vcpkg dependencies: - should be called before defining project()
run_vcpkg(
    VCPKG_URL "https://github.com/microsoft/vcpkg.git"
    VCPKG_REV "9a5e44fcc1d6d734f46e385245438afaa7e53e28"
    ENABLE_VCPKG_UPDATE
)

# Set the project name and language
project(myproject LANGUAGES CXX C)

# Build Features
option(FEATURE_TESTS "Enable the tests" OFF)
if(FEATURE_TESTS)
  list(APPEND VCPKG_MANIFEST_FEATURES "tests")
endif()

option(FEATURE_DOCS "Enable the docs" OFF)

# Enable sanitizers and static analyzers when running the tests
set(ENABLE_CLANG_TIDY OFF)
set(ENABLE_CPPCHECK OFF)
set(ENABLE_SANITIZER_ADDRESS OFF)
set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR OFF)
set(ENABLE_COVERAGE OFF)

if(FEATURE_TESTS)
  set(ENABLE_CLANG_TIDY "ENABLE_CLANG_TIDY")
  set(ENABLE_CPPCHECK "ENABLE_CPPCHECK")
  set(ENABLE_COVERAGE "ENABLE_COVERAGE")

  if(NOT
     "${CMAKE_SYSTEM_NAME}"
     STREQUAL
     "Windows")
    set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS")
    set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "ENABLE_SANITIZER_UNDEFINED_BEHAVIOR")
  else()
    # or it is MSVC and has run vcvarsall
    string(FIND "$ENV{PATH}" "$ENV{VSINSTALLDIR}" index_of_vs_install_dir)
    if(MSVC AND "${index_of_vs_install_dir}" STREQUAL "-1")
      set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS")
    endif()
  endif()
endif()

if(FEATURE_DOCS)
  set(ENABLE_DOXYGEN "ENABLE_DOXYGEN")
else()
  set(ENABLE_DOXYGEN OFF)
endif()

# Initialize project_options variable related to this project
# This overwrites `project_options` and sets `project_warnings`
# uncomment to enable the options. Some of them accept one or more inputs:
project_options(
      PREFIX "myproject"
      ENABLE_CACHE
      ${ENABLE_CPPCHECK}
      ${ENABLE_CLANG_TIDY}
      ENABLE_VS_ANALYSIS
      # ENABLE_CONAN
      # ENABLE_INTERPROCEDURAL_OPTIMIZATION
      # ENABLE_NATIVE_OPTIMIZATION
      ${ENABLE_DOXYGEN}
      ${ENABLE_COVERAGE}
      ${ENABLE_SANITIZER_ADDRESS}
      ${ENABLE_SANITIZER_UNDEFINED_BEHAVIOR}
      # ENABLE_SANITIZER_THREAD
      # ENABLE_SANITIZER_MEMORY
      # ENABLE_CONTROL_FLOW_PROTECTION
      # ENABLE_STACK_PROTECTION
      # ENABLE_OVERFLOW_PROTECTION
      # ENABLE_ELF_PROTECTION
      # ENABLE_RUNTIME_SYMBOLS_RESOLUTION
      # ENABLE_COMPILE_COMMANDS_SYMLINK
      # ENABLE_PCH
      # PCH_HEADERS
      # WARNINGS_AS_ERRORS
      # ENABLE_INCLUDE_WHAT_YOU_USE
      # ENABLE_GCC_ANALYZER
      # ENABLE_BUILD_WITH_TIME_TRACE
      # ENABLE_UNITY
      # LINKER "lld"
      # CONAN_PROFILE ${profile_path}  # passes a profile to conan: see https://docs.conan.io/en/latest/reference/profiles.html
)

Then add the executables or libraries to the project:

executable usage

add_executable(main main.cpp)

# link project_options/warnings
target_link_libraries(main
  PRIVATE myproject_project_options myproject_project_warnings
)

# Find dependencies:
target_find_dependencies(main
  PRIVATE_CONFIG
  fmt
  Eigen3
)

# Link dependencies
target_link_system_libraries(main
  PRIVATE
  fmt::fmt
  Eigen3::Eigen
)

# Package the project
package_project(TARGETS main)

library usage

add_library(my_lib "./src/my_lib/lib.cpp")

# link project_options/warnings
target_link_libraries(my_lib
  PRIVATE myproject_project_options myproject_project_warnings
)

# Includes:
target_include_interface_directories(my_lib "${CMAKE_CURRENT_SOURCE_DIR}/include")

# Find dependencies:
target_find_dependencies(my_lib
  PRIVATE_CONFIG
  fmt
  Eigen3
)

# Link dependencies:
target_link_system_libraries(my_lib
  PRIVATE
  fmt::fmt
  Eigen3::Eigen
)

# Package the project
package_project(
  # Note that you must export `myproject_project_options` and `myproject_project_warnings` for `my_lib`
  TARGETS my_lib myproject_project_options myproject_project_warnings
)

header-only library usage

add_library(my_header_lib INTERFACE)

# link project_options/warnings
target_link_libraries(my_header_lib
  INTERFACE myproject_project_options myproject_project_warnings
)

# Includes:
target_include_interface_directories(my_header_lib "${CMAKE_CURRENT_SOURCE_DIR}/include")

# Find dependencies:
target_find_dependencies(my_header_lib
  INTERFACE_CONFIG
  fmt
  Eigen3
)

# Link dependencies:
target_link_system_libraries(my_header_lib
  INTERFACE
  fmt::fmt
  Eigen3::Eigen
)

# Package the project
package_project(
  TARGETS my_header_lib myproject_project_options myproject_project_warnings
)

License

This project can be used under the terms of either the MIT license or the Unlicense depending on your choice.

More Repositories

1

setup-cpp

Install all the tools required for building and testing C++/C projects.
TypeScript
118
star
2

solid-simple-table

Blazing fast Table component with solid-js
TypeScript
46
star
3

tocPDF

Generates bookmarks from the table of contents already available at the beginning of pdf files.
25
star
4

package-switch

Easy package activation/deactivation
TypeScript
24
star
5

CompileBot.jl

Automatic compilation for Julia packages
Julia
17
star
6

cpp_vcpkg_project

A production-ready C++ project made with vcpkg
CMake
13
star
7

astro-parcel

Build and optimize your Astro project using Parcel
TypeScript
11
star
8

eslint-plugin-yaml

Lint YAML files using ESLint
TypeScript
9
star
9

typescript-optimization

Compares different for-loops in TypeScript/JavaScript
TypeScript
7
star
10

VarStructs.jl

Variable Julia Structs with dispatching
Julia
7
star
11

d-tree-sitter

The D bindings for tree-sitter
D
7
star
12

AcuteMSWord

My Microsoft Word VBA macros
VBA
6
star
13

minijson

Minify JSON files fast! Supports Comments. Uses D, C, and AVX2 and SSE4_1 SIMD.
D
6
star
14

juno-plus

Enhances Juno - Julia IDE
TypeScript
5
star
15

globify_gitignore

Convert Gitignore to Glob patterns in Go
Go
4
star
16

AcuteML.jl

Acute Markup Language - HTML/XML in Julia
Julia
4
star
17

AcuteLyx

A collection of environments, shortcuts, toolbars, packages, etc. to enhance Lyx.
TeX
4
star
18

AcutePowerShell

Various PowerShell scripts
PowerShell
3
star
19

TypeTransform.jl

Transform the given type to another type during defining a method
Julia
3
star
20

patha

File paths library. All you need to work with paths. Tiny drop-in replacement for 'path'. Works in Node, Browser, and Deno.
TypeScript
3
star
21

Dispatch.m

Runtime multiple dispatch for Matlab.
MATLAB
2
star
22

aminya

2
star
23

jira-issue-navigate

Go to the next/prev issue using buttons
TypeScript
2
star
24

AcuteGit

My most used git commands for the operations that are not available through github desktop software
PowerShell
2
star
25

AcuteBenchmark.jl

Automatically benchmark functions!
Julia
2
star
26

cmove

Move const values in C++
CMake
2
star
27

assemblyscript-template

An AssemblyScript template with support for many environments
TypeScript
2
star
28

chocolatey-wabt

The WebAssembly Binary Toolkit
PowerShell
1
star
29

.github

1
star
30

Matlab-Snippets

Generate Matlab snippets for Atom and VSCode
Julia
1
star
31

globify-gitignore

Convert Gitignore to Glob patterns
TypeScript
1
star
32

chocolatey-emscripten

Chocolatey package for emscripten
PowerShell
1
star
33

admina

Detect root/admin/sudo and execute commands as it if available
TypeScript
1
star
34

projsync

Sync projects to different remote machines over SSH or WSL
Rust
1
star
35

svg-extract

Extract inline SVG to a new file in VsCode
TypeScript
1
star