|
| 1 | +# Relevant targets: |
| 2 | +# checkperf-parse: builds the reference checkperf-parse, syncing reference repository if needed |
| 3 | +# checkperf: builds the targets needed for checkperf (parse, perfdiff, checkperf-parse) |
| 4 | +# update-checkperf-repo: updates the reference repository we're checking performance against |
| 5 | +# checkperf-repo: initialize and sync reference repository (first time only) |
| 6 | +# TEST checkperf: runs the actual checkperf test |
| 7 | + |
| 8 | +# Clone the repository if it's not there |
| 9 | +find_package(Git QUIET) |
| 10 | +if (Git_FOUND) |
| 11 | + # sync_git_repository(myrepo ...) creates two targets: |
| 12 | + # myrepo - if the repo does not exist, creates and syncs it against the origin branch |
| 13 | + # update_myrepo - will update the repo against the origin branch (and create if needed) |
| 14 | + function(sync_git_repository name dir remote branch url) |
| 15 | + # This conditionally creates the git repository |
| 16 | + add_custom_command( |
| 17 | + OUTPUT ${dir}/.git/config |
| 18 | + COMMAND ${GIT_EXECUTABLE} init ${dir} |
| 19 | + COMMAND ${GIT_EXECUTABLE} -C ${dir} remote add ${remote} ${url} |
| 20 | + ) |
| 21 | + add_custom_target(init-${name} DEPENDS ${dir}/.git/config) |
| 22 | + # This conditionally syncs the git repository, first time only |
| 23 | + add_custom_command( |
| 24 | + OUTPUT ${dir}/.git/FETCH_HEAD |
| 25 | + COMMAND ${GIT_EXECUTABLE} remote set-url ${remote} ${url} |
| 26 | + COMMAND ${GIT_EXECUTABLE} fetch --depth=1 ${remote} ${branch} |
| 27 | + COMMAND ${GIT_EXECUTABLE} reset --hard ${remote}/${branch} |
| 28 | + WORKING_DIRECTORY ${dir} |
| 29 | + DEPENDS init-${name} |
| 30 | + ) |
| 31 | + # This is the ${name} target, which will create and sync the repo first time only |
| 32 | + add_custom_target(${name} DEPENDS ${dir}/.git/FETCH_HEAD) |
| 33 | + # This is the update-${name} target, which will sync the repo (creating it if needed) |
| 34 | + add_custom_target( |
| 35 | + update-${name} |
| 36 | + COMMAND ${GIT_EXECUTABLE} remote set-url ${remote} ${url} |
| 37 | + COMMAND ${GIT_EXECUTABLE} fetch --depth=1 ${remote} ${branch} |
| 38 | + COMMAND ${GIT_EXECUTABLE} reset --hard ${remote}/${branch} |
| 39 | + WORKING_DIRECTORY ${dir} |
| 40 | + DEPENDS init-${name} |
| 41 | + ) |
| 42 | + endfunction(sync_git_repository) |
| 43 | + |
| 44 | + set(SIMDJSON_CHECKPERF_REMOTE origin CACHE STRING "Remote repository to compare performance against") |
| 45 | + set(SIMDJSON_CHECKPERF_BRANCH master CACHE STRING "Branch to compare performance against") |
| 46 | + set(SIMDJSON_CHECKPERF_DIR ${CMAKE_CURRENT_BINARY_DIR}/checkperf-reference/${SIMDJSON_CHECKPERF_BRANCH} CACHE STRING "Location to put checkperf performance comparison repository") |
| 47 | + set(SIMDJSON_CHECKPERF_ARGS ${EXAMPLE_JSON} CACHE STRING "Arguments to pass to parse during checkperf") |
| 48 | + sync_git_repository(checkperf-repo ${SIMDJSON_CHECKPERF_DIR} ${SIMDJSON_CHECKPERF_REMOTE} ${SIMDJSON_CHECKPERF_BRANCH} ${SIMDJSON_GITHUB_REPOSITORY}) |
| 49 | + |
| 50 | + # Commands to cause cmake on benchmark/checkperf-master/build/ |
| 51 | + # - first, copy CMakeCache.txt |
| 52 | + add_custom_command( |
| 53 | + OUTPUT ${SIMDJSON_CHECKPERF_DIR}/build/CMakeCache.txt |
| 54 | + COMMAND ${CMAKE_COMMAND} -E make_directory ${SIMDJSON_CHECKPERF_DIR}/build |
| 55 | + COMMAND ${CMAKE_COMMAND} -E copy ${SIMDJSON_USER_CMAKECACHE} ${SIMDJSON_CHECKPERF_DIR}/build/CMakeCache.txt |
| 56 | + DEPENDS checkperf-repo simdjson-user-cmakecache |
| 57 | + ) |
| 58 | + # - second, cmake .. |
| 59 | + add_custom_command( |
| 60 | + OUTPUT ${SIMDJSON_CHECKPERF_DIR}/build/cmake_install.cmake # We make many things but this seems the most cross-platform one we can depend on |
| 61 | + COMMAND ${CMAKE_COMMAND} -DSIMDJSON_GOOGLE_BENCHMARKS=OFF -DSIMDJSON_COMPETITION=OFF -G ${CMAKE_GENERATOR} .. |
| 62 | + WORKING_DIRECTORY ${SIMDJSON_CHECKPERF_DIR}/build |
| 63 | + DEPENDS ${SIMDJSON_CHECKPERF_DIR}/build/CMakeCache.txt |
| 64 | + ) |
| 65 | + |
| 66 | + # - third, build parse. |
| 67 | + if (CMAKE_CONFIGURATION_TYPES) |
| 68 | + set(CHECKPERF_PARSE ${SIMDJSON_CHECKPERF_DIR}/build/benchmark/$<CONFIGURATION>/parse) |
| 69 | + else() |
| 70 | + set(CHECKPERF_PARSE ${SIMDJSON_CHECKPERF_DIR}/build/benchmark/parse) |
| 71 | + endif() |
| 72 | + add_custom_target( |
| 73 | + checkperf-parse ALL # TODO is ALL necessary? |
| 74 | + # Build parse |
| 75 | + COMMAND ${CMAKE_COMMAND} --build . --target parse --config $<CONFIGURATION> |
| 76 | + WORKING_DIRECTORY ${SIMDJSON_CHECKPERF_DIR}/build |
| 77 | + DEPENDS ${SIMDJSON_CHECKPERF_DIR}/build/cmake_install.cmake # We make many things but this seems the most cross-platform one we can depend on |
| 78 | + ) |
| 79 | + |
| 80 | + # Target to build everything needed for the checkperf test |
| 81 | + add_custom_target(checkperf DEPENDS parse perfdiff checkperf-parse) |
| 82 | + |
| 83 | + # Add the actual checkperf test |
| 84 | + add_test( |
| 85 | + NAME checkperf |
| 86 | + # COMMAND ECHO $<TARGET_FILE:perfdiff> \"$<TARGET_FILE:parse> -t ${SIMDJSON_CHECKPERF_ARGS}\" \"${CHECKPERF_PARSE} -t ${SIMDJSON_CHECKPERF_ARGS}\" } |
| 87 | + COMMAND $<TARGET_FILE:perfdiff> $<TARGET_FILE:parse> ${CHECKPERF_PARSE} -t ${SIMDJSON_CHECKPERF_ARGS} |
| 88 | + ) |
| 89 | + set_property(TEST checkperf APPEND PROPERTY LABELS per_implementation) |
| 90 | + set_property(TEST checkperf APPEND PROPERTY DEPENDS parse perfdiff ${SIMDJSON_USER_CMAKECACHE}) |
| 91 | + set_property(TEST checkperf PROPERTY RUN_SERIAL TRUE) |
| 92 | + |
| 93 | +endif (Git_FOUND) |
0 commit comments