Created
September 26, 2018 20:01
-
-
Save EmilGedda/2f0708cd204807381fe603fc5a704825 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.12) | |
project(kattis C CXX) | |
file(GLOB_RECURSE srcs CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.c*") | |
find_program(HATTIS NAMES hattis) | |
add_custom_target(test-all) | |
foreach(file ${srcs}) | |
# Add target for problem | |
get_filename_component(_target ${file} NAME_WE) | |
add_executable(${_target} ${file}) | |
target_compile_features(${_target} PRIVATE cxx_std_14) | |
target_compile_options(${_target} PRIVATE -march=native -Wall -Wextra -pedantic) | |
set(zip_dir "${CMAKE_CURRENT_BINARY_DIR}/${_target}-tests") | |
set(zip_file "${zip_dir}/${_target}.tests.zip") | |
# Download testcases | |
IF(NOT EXISTS ${zip_dir}) | |
message(STATUS "Downloading testcases for ${_target}") | |
file(DOWNLOAD | |
https://open.kattis.com/problems/${_target}/file/statement/samples.zip | |
${zip_file} | |
) | |
# Unzip testcases | |
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzf ${zip_file} | |
WORKING_DIRECTORY ${zip_dir}) | |
# Remove zip file | |
execute_process(COMMAND ${CMAKE_COMMAND} -E remove ${zip_file}) | |
else() | |
message(STATUS "Testcases for ${_target} already downloaded") | |
endif() | |
# Aggregate target for all test cases | |
add_custom_target(${_target}-test) | |
add_dependencies(test-all ${_target}-test) | |
# Add a target for each problem's sample inputs | |
file(GLOB_RECURSE testcases "${zip_dir}/*.in") | |
foreach(testcase_file ${testcases}) | |
get_filename_component(testcase ${testcase_file} NAME_WE) | |
add_custom_target(${_target}-test_${testcase} | |
COMMAND echo [${_target}] Testcase ${testcase} succeeded | |
DEPENDS ${_target}) | |
add_dependencies(${_target}-test ${_target}-test_${testcase}) | |
message(STATUS "Adding testcase ${_target}-test_${testcase}") | |
endforeach() | |
# Enable submission to kattis if hattis is found | |
if(EXISTS ${HATTIS}) | |
add_custom_target(${_target}-submit | |
COMMAND ${HATTIS} -f ${_target} ${file} | |
DEPENDS ${_target}-test | |
) | |
endif() | |
endforeach() | |
if(NOT EXISTS ${HATTIS}) | |
message(STATUS "Hattis not found! Submitting disabled") | |
else() | |
message(STATUS "Hattis found. Submitting enabled") | |
endif() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment