Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork56
A general-purpose CMake library that provides functions that improve the CMake experience following the best practices.
License
MIT, Unlicense licenses found
Licenses found
aminya/project_options
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A general-purpose CMake library that provides functions that improve theCMake experience following the best practices.
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 projectfor seamless usage via find_package/target_link through CMake'sFetchContent, vcpkg, etc.run_vcpkg
: automatic installation of vcpkg and the projectdependenciesrun_conan
: automatic installation of conan and the projectdependenciesdynamic_project_options
: a wrapper aroundproject_options
tochange the options on the fly dynamicallytarget_link_system_libraries
andtarget_include_system_directories
: linking/including externaldependencies/headers without warningstarget_link_cuda
: linking Cuda to a target
The full documentation is available here:
https://aminya.github.io/project_options/
See theproject_options()
in action inthis templaterepository.cpp_vcpkg_project hasprepared all the best practices for a production-ready C++ project.
Here is an example of the usage:
cmake_minimum_required(VERSION3.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_VERSIONVERSION_GREATER_EQUAL"3.24.0")cmake_policy(SETCMP0135NEW)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.41.0")FetchContent_Declare(_project_optionsURLhttps://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"86a181505ac6460f98496a79abdee6a0f49905ec")# Install conan dependencies: - should be called before defining project()run_conan()# Set the project name and languageproject(myprojectLANGUAGESCXXC)# Build Featuresoption(FEATURE_TESTS"Enable the tests"OFF)option(FEATURE_DOCS"Enable the docs"OFF)# vcpkg test featureif(FEATURE_TESTS)list(APPENDVCPKG_MANIFEST_FEATURES"tests")endif()# Enable sanitizers and static analyzers when running the testsif(FEATURE_TESTS)set(ENABLE_CLANG_TIDY"ENABLE_CLANG_TIDY")set(ENABLE_CPPCHECK"ENABLE_CPPCHECK")set(ENABLE_COVERAGE"ENABLE_COVERAGE")set(ENABLE_SANITIZER_ADDRESS"ENABLE_SANITIZER_ADDRESS")set(ENABLE_SANITIZER_UNDEFINED"ENABLE_SANITIZER_UNDEFINED")endif()# Enable doxgen for the docsif(FEATURE_DOCS)set(ENABLE_DOXYGEN"ENABLE_DOXYGEN")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_INTERPROCEDURAL_OPTIMIZATION# ENABLE_NATIVE_OPTIMIZATION${ENABLE_DOXYGEN}${ENABLE_COVERAGE}${ENABLE_SANITIZER_ADDRESS}${ENABLE_SANITIZER_UNDEFINED}# ${ENABLE_SANITIZER_THREAD}# ${ENABLE_SANITIZER_MEMORY}# ENABLE_SANITIZER_POINTER_COMPARE# ENABLE_SANITIZER_POINTER_SUBTRACT# 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")
Then add the executables or libraries to the project:
add_executable(mainmain.cpp)# link project_options/warningstarget_link_libraries(mainPRIVATEmyproject_project_optionsmyproject_project_warnings)# Find dependencies:target_find_dependencies(mainPRIVATE_CONFIGfmtEigen3)# Link dependenciestarget_link_system_libraries(mainPRIVATEfmt::fmtEigen3::Eigen)# Package the projectpackage_project(TARGETSmain)
add_library(my_lib"./src/my_lib/lib.cpp")# link project_options/warningstarget_link_libraries(my_libPRIVATEmyproject_project_optionsmyproject_project_warnings)# Includes:target_include_interface_directories(my_lib"${CMAKE_CURRENT_SOURCE_DIR}/include")# Find dependencies:target_find_dependencies(my_libPRIVATE_CONFIGfmtEigen3)# Link dependencies:target_link_system_libraries(my_libPRIVATEfmt::fmtEigen3::Eigen)# Package the projectpackage_project(# Note that you must export `myproject_project_options` and `myproject_project_warnings` for `my_lib`TARGETSmy_libmyproject_project_optionsmyproject_project_warnings)
add_library(my_header_libINTERFACE)# link project_options/warningstarget_link_libraries(my_header_libINTERFACEmyproject_project_optionsmyproject_project_warnings)# Includes:target_include_interface_directories(my_header_lib"${CMAKE_CURRENT_SOURCE_DIR}/include")# Find dependencies:target_find_dependencies(my_header_libINTERFACE_CONFIGfmtEigen3)# Link dependencies:target_link_system_libraries(my_header_libINTERFACEfmt::fmtEigen3::Eigen)# Package the projectpackage_project(TARGETSmy_header_libmyproject_project_optionsmyproject_project_warnings)
This project can be used under the terms of either theMITlicense or theUnlicensedepending on your choice.
About
A general-purpose CMake library that provides functions that improve the CMake experience following the best practices.
Topics
Resources
License
MIT, Unlicense licenses found
Licenses found
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.