[CMake] Feature req: Project-specified mandatory variables
Oliver Smith
kfsone at gmail.com
Sat Nov 11 21:03:41 EST 2017
Consider the following:
PROJECT(Mandatory)
SET(USING_SHAPE "" CACHE STRING "[Required] Shape config: Round or
Square")
SET_PROPERTY(CACHE USING_SHAPE PROPERTY STRINGS Round Square)
IF (NOT USING_SHAPE)
MESSAGE(FATAL_ERROR "'USING_SHAPE' variable is required but was not
set. Choose Round or Square")
ENDIF ()
MESSAGE(STATUS "Shape config: ${USING_SHAPE}")
...
The first time a user runs cmake here, they will receive a wall of text
about compiler identification, followed by a complex error message that
most developers can probably parse, but it's poorly suited for other people
participating in a larger build system. etc.
This leads to a common case where teams wrap their cmake invocation behind
one or more script layers to hoist the setting checks out of the scripts.
Consider:
PROJECT(Mandatory)
EXTERNAL_VALUE( # or it could be 'set' with a special case for
'FATAL_ERROR' as the default
USING_SHAPE FATAL_ERROR
"Shape config"
STRINGS Round Square
)
MESSAGE(STATUS "Shape config: ${USING_SHAPE}")
The CMake GUI(s) could also pick up on these and prompt the user for them
at the start of the config state.
Other wordings:
SET(USING_SHAPE FATAL_ERROR "Shape Config" ...)
MANDATORY(USING_SHAPE "Shape Config ...)
REQUIRE_SETTING
REQUIRE_VARIABLE
REQUIRED_VARIABLE
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20171111/aae84272/attachment.html>
More information about the CMake
mailing list