1
2include(MakeDistFiles)
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_C_FLAGS=${CMAKE_C_FLAGS}
45              -D CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
46              -D CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
47              -D CMAKE_INSTALL_PREFIX=../${INSTALL_DIR}
48              -D GTEST_ROOT=${GTEST_ROOT}
49              -D WITH_PYTHON=YES
50              ../${PACKAGE_PREFIX}
51            WORKING_DIRECTORY ${BUILD_DIR}
52            ERROR_MSG "CMake configure command failed."
53    )
54
55    # Run ninja in the build directory
56    execute_process_and_check_result(
57            COMMAND ${CMAKE_COMMAND} -E env ${NINJA_COMMAND}
58            WORKING_DIRECTORY ${BUILD_DIR}
59            ERROR_MSG "Ninja build failed."
60    )
61
62    # Run ninja install
63    execute_process_and_check_result(
64            COMMAND ${CMAKE_COMMAND} -E env ${NINJA_COMMAND} install
65            WORKING_DIRECTORY ${BUILD_DIR}
66            ERROR_MSG "Ninja install failed."
67    )
68
69    # Run ninja check in the build directory
70    execute_process_and_check_result(
71            COMMAND ${CMAKE_COMMAND} -E env ${NINJA_COMMAND} check
72            WORKING_DIRECTORY ${BUILD_DIR}
73            ERROR_MSG "Ninja check failed."
74    )
75
76    # Run ninja dist
77    execute_process_and_check_result(
78            COMMAND ${CMAKE_COMMAND} -E env ${NINJA_COMMAND} dist
79            WORKING_DIRECTORY ${BUILD_DIR}
80            ERROR_MSG "Ninja dist failed."
81    )
82
83    message("distcheck complete.")
84
85endfunction()
86
87run_dist_check(${PACKAGE_PREFIX} .gz)
88