This repository serves as a centralized collection of custom CMake modules designed to simplify, standardize, and enhance project configuration. Inclusion of this library facilitates the reduction of boilerplate code and the enforcement of consistent build patterns across repositories.
- Reusable Logic: Contains modular, encapsulated CMake functions and macros.
- Standardization: Enforces consistent build patterns across multiple repositories.
- Easy Integration: Simple include mechanisms to drop these utilities into any CMake-based project.
One of the core utilities provided in this library is the multiple_choice function, located in the cmake/ subdirectory. This function is designed to handle robust input validation and option selection within your CMakeLists.txt files.
multiple_choice(
<var>
VALID_VALUES <val1> [<val2> ...]
[DEFAULT <default_val> [<default_val2> ...]]
[VALUE_MODE SINGLE|MULTI|SEQUENCE]
[TYPE <type>]
[HELP <help_string>]
[DEFAULT_ON_ERROR]
[FATAL_ERROR]
)
Implementation requires the following steps:
-
Project Integration: Clone the repository or incorporate it as a Git submodule.
-
Path Configuration: Append the cmake/ directory to the CMAKE_MODULE_PATH:
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/path/to/repo/cmake")
-
Module Inclusion: Include the desired module:
include(MultipleChoice)
-
Function Execution: Example defining valid choices:
# VALUE_MODE SINGLE is the default. # When DEFAULT is omitted, the first valid value ("red") is assigned as the default. multiple_choice(COLOR VALID_VALUES red green blue)