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
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to