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 9find_package(Git QUIET) 10if (Git_FOUND AND (GIT_VERSION_STRING VERSION_GREATER "2.1.4") AND (NOT CMAKE_GENERATOR MATCHES Ninja) AND (NOT MSVC) ) # We use "-C" which requires a recent git 11 message(STATUS "Git is available and it is recent. We are enabling checkperf targets.") 12 # sync_git_repository(myrepo ...) creates two targets: 13 # myrepo - if the repo does not exist, creates and syncs it against the origin branch 14 # update_myrepo - will update the repo against the origin branch (and create if needed) 15 function(sync_git_repository name dir remote branch url) 16 # This conditionally creates the git repository 17 add_custom_command( 18 OUTPUT ${dir}/.git/config 19 COMMAND ${GIT_EXECUTABLE} init ${dir} 20 COMMAND ${GIT_EXECUTABLE} -C ${dir} remote add ${remote} ${url} 21 ) 22 add_custom_target(init-${name} DEPENDS ${dir}/.git/config) 23 # This conditionally syncs the git repository, first time only 24 add_custom_command( 25 OUTPUT ${dir}/.git/FETCH_HEAD 26 COMMAND ${GIT_EXECUTABLE} remote set-url ${remote} ${url} 27 COMMAND ${GIT_EXECUTABLE} fetch --depth=1 ${remote} ${branch} 28 COMMAND ${GIT_EXECUTABLE} reset --hard ${remote}/${branch} 29 WORKING_DIRECTORY ${dir} 30 DEPENDS init-${name} 31 ) 32 # This is the ${name} target, which will create and sync the repo first time only 33 add_custom_target(${name} DEPENDS ${dir}/.git/FETCH_HEAD) 34 # This is the update-${name} target, which will sync the repo (creating it if needed) 35 add_custom_target( 36 update-${name} 37 COMMAND ${GIT_EXECUTABLE} remote set-url ${remote} ${url} 38 COMMAND ${GIT_EXECUTABLE} fetch --depth=1 ${remote} ${branch} 39 COMMAND ${GIT_EXECUTABLE} reset --hard ${remote}/${branch} 40 WORKING_DIRECTORY ${dir} 41 DEPENDS init-${name} 42 ) 43 endfunction(sync_git_repository) 44 45 set(SIMDJSON_CHECKPERF_REMOTE origin CACHE STRING "Remote repository to compare performance against") 46 set(SIMDJSON_CHECKPERF_BRANCH master CACHE STRING "Branch to compare performance against") 47 set(SIMDJSON_CHECKPERF_DIR ${CMAKE_CURRENT_BINARY_DIR}/checkperf-reference/${SIMDJSON_CHECKPERF_BRANCH} CACHE STRING "Location to put checkperf performance comparison repository") 48 set(SIMDJSON_CHECKPERF_ARGS ${EXAMPLE_JSON} CACHE STRING "Arguments to pass to parse during checkperf") 49 sync_git_repository(checkperf-repo ${SIMDJSON_CHECKPERF_DIR} ${SIMDJSON_CHECKPERF_REMOTE} ${SIMDJSON_CHECKPERF_BRANCH} ${SIMDJSON_GITHUB_REPOSITORY}) 50 51 # Commands to cause cmake on benchmark/checkperf-master/build/ 52 # - first, copy CMakeCache.txt 53 add_custom_command( 54 OUTPUT ${SIMDJSON_CHECKPERF_DIR}/build/CMakeCache.txt 55 COMMAND ${CMAKE_COMMAND} -E make_directory ${SIMDJSON_CHECKPERF_DIR}/build 56 COMMAND ${CMAKE_COMMAND} -E copy ${SIMDJSON_USER_CMAKECACHE} ${SIMDJSON_CHECKPERF_DIR}/build/CMakeCache.txt 57 DEPENDS checkperf-repo simdjson-user-cmakecache 58 ) 59 # - second, cmake .. 60 add_custom_command( 61 OUTPUT ${SIMDJSON_CHECKPERF_DIR}/build/cmake_install.cmake # We make many things but this seems the most cross-platform one we can depend on 62 COMMAND 63 ${CMAKE_COMMAND} -E env CXX=${CMAKE_CXX_COMPILER} CC=${CMAKE_C_COMPILER} 64 ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DSIMDJSON_GOOGLE_BENCHMARKS=OFF -DSIMDJSON_COMPETITION=OFF -G ${CMAKE_GENERATOR} .. 65 WORKING_DIRECTORY ${SIMDJSON_CHECKPERF_DIR}/build 66 DEPENDS ${SIMDJSON_CHECKPERF_DIR}/build/CMakeCache.txt 67 ) 68 69 # - third, build parse. 70 if (CMAKE_CONFIGURATION_TYPES) 71 set(CHECKPERF_PARSE ${SIMDJSON_CHECKPERF_DIR}/build/benchmark/$<CONFIGURATION>/parse) 72 else() 73 set(CHECKPERF_PARSE ${SIMDJSON_CHECKPERF_DIR}/build/benchmark/parse) 74 endif() 75 add_custom_target( 76 checkperf-parse ALL # TODO is ALL necessary? 77 # Build parse 78 COMMAND ${CMAKE_COMMAND} --build . --target parse --config $<CONFIGURATION> 79 WORKING_DIRECTORY ${SIMDJSON_CHECKPERF_DIR}/build 80 DEPENDS ${SIMDJSON_CHECKPERF_DIR}/build/cmake_install.cmake # We make many things but this seems the most cross-platform one we can depend on 81 ) 82 83 # Target to build everything needed for the checkperf test 84 add_custom_target(checkperf DEPENDS parse perfdiff checkperf-parse) 85 86 # Add the actual checkperf test 87 add_test( 88 NAME checkperf 89 # COMMAND ECHO $<TARGET_FILE:perfdiff> \"$<TARGET_FILE:parse> -t ${SIMDJSON_CHECKPERF_ARGS}\" \"${CHECKPERF_PARSE} -t ${SIMDJSON_CHECKPERF_ARGS}\" } 90 COMMAND $<TARGET_FILE:perfdiff> $<TARGET_FILE:parse> ${CHECKPERF_PARSE} -H -t ${SIMDJSON_CHECKPERF_ARGS} 91 ) 92 set_property(TEST checkperf APPEND PROPERTY LABELS per_implementation explicitonly) 93 set_property(TEST checkperf APPEND PROPERTY DEPENDS parse perfdiff ${SIMDJSON_USER_CMAKECACHE}) 94 set_property(TEST checkperf PROPERTY RUN_SERIAL TRUE) 95else() 96 if (CMAKE_GENERATOR MATCHES Ninja) 97 message(STATUS "We disable the checkperf targets under Ninja.") 98 else() 99 message(STATUS "Either git is unavailable or else it is too old. We are disabling checkperf targets.") 100 endif() 101endif () 102