[CMake] Most convenient way to pass information from dashboard script to cmake script

Tyler Roscoe tyler at cryptio.net
Tue Dec 28 12:41:14 EST 2010


On Mon, Dec 27, 2010 at 03:56:20PM +0100, Wojciech Migda wrote:
> I'm trying to pass information from a script executed for dashboard
> submission (ctest -S) to the underlying CMakeLists.txt which is to be
> parsed by (internally called by ctest) cmake. In other words, I'd like
> to have a system which will behave differently when configured
> directly through direct cmake invocation and through ctest -S script
> execution.

Kitware does this in its ctest -S script for doing dashboard builds of CMake. I
took that some time ago and modified it, so now the relevant sections look like
this:

# Set up dashboard_cache, a string containing var=value pairs that will be
# written into the initial CMakeCache.txt.
#
# Careful with quoting and newlines here. Unquoted spaces will cause CMake
# to interpret this variable as a list, resulting in a spurious semicolon
# in the resulting CMakeCache.txt (which doesn't work; CMake will ignore these
# cache entries). Leading whitespace appears to be ok, so we can preserve the
# indentation in this file even though that whitespace is quoted and included
# in the dashboard_cache variable.
if (NOT DEFINED dashboard_cache)
    set (dashboard_cache
        "BUILD_run_unittest_during_build:BOOL=OFF
        BUILD_code_quality:BOOL=${BUILD_code_quality}
        TP_ARCHIVE_TYPE:STRING=${TP_ARCHIVE_TYPE}
        TP_PACKAGE:BOOL=${TP_PACKAGE}
        TP_PACKAGE_WITH_INSTALLSHIELD:BOOL=${TP_PACKAGE_WITH_INSTALLSHIELD}
        TP_PUBLISH:BOOL=${TP_PUBLISH}
        TP_EXERCISE:BOOL=${TP_EXERCISE}
        TP_EXERCISE_QUICK:BOOL=${TP_EXERCISE_QUICK}
        TP_WINDOWS_USE_PRECOMPILED_HEADERS:BOOL=${TP_WINDOWS_USE_PRECOMPILED_HEADERS}"
    )
    # We only add these values to the cache if they are defined. If they are
    # undefined, we let the configure step set up defaults later on.
    if (DEFINED TP_CODE_QUALITY_MAX_CRAP_VALUE)
        set (dashboard_cache
            "${dashboard_cache}
            TP_CODE_QUALITY_MAX_CRAP_VALUE:STRING=${TP_CODE_QUALITY_MAX_CRAP_VALUE}"
        )
    endif ()
endif ()

[...]

# Helper macro to write the initial cache.
macro (write_cache)
    if (CTEST_CMAKE_GENERATOR MATCHES "Make")
      set (cache_build_type CMAKE_BUILD_TYPE:STRING=${CTEST_BUILD_CONFIGURATION})
    endif ()
    file (WRITE ${CTEST_BINARY_DIRECTORY}/CMakeCache.txt "
SITE:STRING=${CTEST_SITE}
BUILDNAME:STRING=${CTEST_BUILD_NAME}
${cache_build_type}
${dashboard_cache}
")
endmacro ()

[...]

    if (NOT EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt")
        set (dashboard_fresh 1)
        message ("INFO: No CMakeCache.txt found in binary directory ${CTEST_BINARY_DIRECTORY}. Writing new cache and starting fresh build.")
        write_cache ()
    endif ()




hth,
tyler


More information about the CMake mailing list