1
2include(${CMAKE_MODULE_PATH}/DistCommon.cmake)
3
4function(run_dist_check PACKAGE_PREFIX EXT)
5
6    set(tarball ${PACKAGE_PREFIX}.tar${EXT})
7    if (NOT EXISTS ${tarball})
8        message(FATAL_ERROR "Can't find dist tarball '${tarball}'")
9    endif()
10
11    # Remove the directory we're about to extract to
12    file(REMOVE_RECURSE ${PACKAGE_PREFIX})
13
14    # Untar the distribution we want to check
15    set(TAR_OPTION "zxf")
16    if (${EXT} STREQUAL ".bz2")
17        set(TAR_OPTION "jxf")
18    endif()
19
20    FIND_PROGRAM(NINJA_COMMAND NAMES ninja ninja-build)
21    if (${NINJA_COMMAND} STREQUAL "NINJA_COMMAND-NOTFOUND")
22        message(FATAL_ERROR "Can't find the 'ninja' or 'ninja-build' program.")
23    endif ()
24
25    execute_process_and_check_result(
26            COMMAND ${CMAKE_COMMAND} -E tar ${TAR_OPTION} ${tarball}
27            WORKING_DIRECTORY .
28            ERROR_MSG "Command to untar ${tarball} failed."
29    )
30
31    # Officially, I should make the contents of the untarred dist directory read-only,
32    # but that will cause the build to fail (intltool is unhappy).
33
34    # Create a build directory and configure the Cmake build
35
36    set(BUILD_DIR "_cmake_build")
37    set(INSTALL_DIR "_cmake_install")
38    file(REMOVE_RECURSE ${BUILD_DIR} ${INSTALL_DIR})
39
40    file(MAKE_DIRECTORY ${BUILD_DIR} ${INSTALL_DIR})
41
42    execute_process_and_check_result(
43            COMMAND ${CMAKE_COMMAND} -G Ninja
44              -D CMAKE_INSTALL_PREFIX=../${INSTALL_DIR}
45              ../${PACKAGE_PREFIX}
46            WORKING_DIRECTORY ${BUILD_DIR}
47            ERROR_MSG "CMake configure command failed."
48    )
49
50    # Run ninja in the build directory
51    execute_process_and_check_result(
52            COMMAND ${CMAKE_COMMAND} -E env ${NINJA_COMMAND}
53            WORKING_DIRECTORY ${BUILD_DIR}
54            ERROR_MSG "Ninja build failed."
55    )
56
57    # Run ninja install
58    execute_process_and_check_result(
59            COMMAND ${CMAKE_COMMAND} -E env ${NINJA_COMMAND} install
60            WORKING_DIRECTORY ${BUILD_DIR}
61            ERROR_MSG "Ninja install failed."
62    )
63
64    # Run ninja check in the build directory
65    execute_process_and_check_result(
66            COMMAND ${CMAKE_COMMAND} -E env ${NINJA_COMMAND} check
67            WORKING_DIRECTORY ${BUILD_DIR}
68            ERROR_MSG "Ninja check failed."
69    )
70
71    message("distcheck complete.")
72
73endfunction()
74
75
76run_dist_check(${PACKAGE_PREFIX} .gz)
77