From 5371267ca70bde82b44dee8e50d229e84aab7201 Mon Sep 17 00:00:00 2001 From: TimePath Date: Wed, 2 Aug 2017 22:38:07 +1000 Subject: [PATCH] Update CMakeLists.txt --- CMakeLists.txt | 60 +++++++++++++++++++++++++------- check-cvars.sh | 3 ++ qcsrc/server/command/radarmap.qc | 3 +- qcsrc/tools/genmod.sh | 12 +++++++ qcsrc/tools/headerstyle.sh | 6 ++-- qcsrc/tools/whitespace.sh | 20 ++++++++--- 6 files changed, 82 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d550d7b6c..5ef6db722 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,46 @@ -cmake_minimum_required(VERSION 2.8.11) -list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -project(xonotic-data LANGUAGES ASM) +cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") +project(xonotic-data ASM) + +set(checks qc-checks) +add_custom_target(${checks}) + +# depend on qcc +if (TARGET gmqcc) + add_dependencies(${checks} gmqcc) +endif () + +add_dependencies(${checks} data-check-cvars) +add_custom_target(data-check-cvars + COMMENT "checking cvars" + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" + VERBATIM COMMAND ${CMAKE_COMMAND} -E + env "CMAKE=1" + "${PROJECT_SOURCE_DIR}/check-cvars.sh" + ) + +add_dependencies(${checks} qc-genmod) +add_custom_target(qc-genmod + COMMENT "genmod.sh" + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/qcsrc" + VERBATIM COMMAND ./tools/genmod.sh + ) + +add_dependencies(${checks} qc-headerstyle) +add_custom_target(qc-headerstyle + COMMENT "headerstyle.sh" + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/qcsrc" + VERBATIM COMMAND ${CMAKE_COMMAND} -E + env "VERBOSE=0" + ./tools/headerstyle.sh + ) + +add_dependencies(${checks} qc-whitespace) +add_custom_target(qc-whitespace + COMMENT "whitespace.sh" + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/qcsrc" + VERBATIM COMMAND ./tools/whitespace.sh + ) include_directories(qcsrc) @@ -10,10 +50,10 @@ add_definitions(-DENABLE_EFFECTINFO=0) add_definitions(-DENABLE_DEBUGDRAW=0) add_definitions(-DENABLE_DEBUGTRACE=0) -find_package(Git REQUIRED) if (DEFINED ENV{VERSION}) set(GIT_DESC "$ENV{VERSION}") else () + find_package(Git REQUIRED) execute_process( COMMAND ${GIT_EXECUTABLE} describe --tags --dirty=~ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} @@ -33,22 +73,16 @@ set_source_files_properties( ) add_executable(csprogs qcsrc/client/progs.inc) +add_dependencies(csprogs ${checks}) target_compile_definitions(csprogs PRIVATE -DGAMEQC -DCSQC) -if (TARGET gmqcc) - add_dependencies(csprogs gmqcc) -endif () add_executable(progs qcsrc/server/progs.inc) +add_dependencies(progs ${checks}) target_compile_definitions(progs PRIVATE -DGAMEQC -DSVQC) -if (TARGET gmqcc) - add_dependencies(progs gmqcc) -endif () add_executable(menu qcsrc/menu/progs.inc) +add_dependencies(menu ${checks}) target_compile_definitions(menu PRIVATE -DMENUQC) -if (TARGET gmqcc) - add_dependencies(menu gmqcc) -endif () function(set_prelude target prelude) get_target_property(MY_PROJECT_SOURCES target SOURCES) diff --git a/check-cvars.sh b/check-cvars.sh index 031613a7b..43683feb8 100755 --- a/check-cvars.sh +++ b/check-cvars.sh @@ -27,6 +27,9 @@ check_files "balance-xonotic.cfg" "balance-*.cfg" "/^seta? g_/" check_files "_hud_descriptions.cfg" "hud_*.cfg" "/^seta? hud_/" if $errord; then + if [ "$CMAKE" != "" ]; then + exit 1 + fi echo "Please wait for 30 seconds, so you have had enough time to read this..." sleep 30 fi diff --git a/qcsrc/server/command/radarmap.qc b/qcsrc/server/command/radarmap.qc index d8b179716..a04274ed2 100644 --- a/qcsrc/server/command/radarmap.qc +++ b/qcsrc/server/command/radarmap.qc @@ -1,8 +1,7 @@ +#include "radarmap.qh" #ifdef RADARMAP -#include "radarmap.qh" #include -#include "radarmap.qh" #include "../g_world.qh" #include "../g_subs.qh" diff --git a/qcsrc/tools/genmod.sh b/qcsrc/tools/genmod.sh index 9a3ba1098..1c0eadcbe 100755 --- a/qcsrc/tools/genmod.sh +++ b/qcsrc/tools/genmod.sh @@ -6,9 +6,17 @@ ROOT=$PWD/ MOD=_mod +function hash() { + git hash-object $1 +} + function genmod() { # use context to work around cmake issue #12619 CTX="${PWD#$ROOT}/" + oldHashC=$(hash ${MOD}.inc) + oldTimeC=$(stat -c "%Y" ${MOD}.inc) + oldHashH=$(hash ${MOD}.qh) + oldTimeH=$(stat -c "%Y" ${MOD}.qh) echo '// generated file; do not modify' > ${MOD}.inc echo '// generated file; do not modify' > ${MOD}.qh for f in $(ls | sort -k 1,1 -t .); do @@ -43,6 +51,10 @@ function genmod() { echo "#include <${CTX}$f/${mod}.qh>" >> ${MOD}.qh fi fi; done + newHashC=$(hash ${MOD}.inc) + if [[ $newHashC == $oldHashC ]]; then touch -d @$oldTimeC ${MOD}.inc; fi + newHashH=$(hash ${MOD}.qh) + if [[ $newHashH == $oldHashH ]]; then touch -d @$oldTimeH ${MOD}.qh; fi } (cd lib; genmod) diff --git a/qcsrc/tools/headerstyle.sh b/qcsrc/tools/headerstyle.sh index 924083166..795a32e6d 100755 --- a/qcsrc/tools/headerstyle.sh +++ b/qcsrc/tools/headerstyle.sh @@ -3,6 +3,8 @@ set -eu cd ${0%/*} cd .. +VERBOSE=${VERBOSE:-1} + function startswith() { declare -l file="${1}" declare -l prelude="${2}" @@ -15,7 +17,7 @@ function startswith() { function check() { declare -l base="${1}" find "$base" -type f -name '*.qc' -print0 | sort -z | while read -r -d '' file; do - echo "$file" + [ "$VERBOSE" != "0" ] && echo "$file" declare -l file_h="${file%.qc}.qh" if [[ ! -f "$file_h" ]]; then echo "#pragma once" > "$file_h"; fi @@ -25,7 +27,7 @@ function check() { startswith "$file" "$include" done find "$base" -type f -name '*.qh' -a \! -name '_mod.qh' -print0 | sort -z | while read -r -d '' file; do - echo "$file" + [ "$VERBOSE" != "0" ] && echo "$file" startswith "$file" "#pragma once" done } diff --git a/qcsrc/tools/whitespace.sh b/qcsrc/tools/whitespace.sh index 594c60ea2..46db12400 100755 --- a/qcsrc/tools/whitespace.sh +++ b/qcsrc/tools/whitespace.sh @@ -3,13 +3,23 @@ set -eu cd ${0%/*} cd .. +function hash() { + git hash-object $1 +} + function check() { declare -l base="${1}" - find "$base" -type f -print0 | sort -z | xargs -0 sed -i \ - `# strip trailing spaces` \ - -e 's/[[:space:]]*$//' \ - `# line feed at EOF for #include to work properly` \ - -e '$a\' + # strip trailing spaces + STRIP_TRAILING_WS='s/[[:space:]]\+$//' + # line feed at EOF for #include to work properly + ENSURE_EOFLF='$a\' + find "$base" -type f -print0 | sort -z | while read -r -d '' file; do + oldHash=$(hash ${file}) + oldTime=$(stat -c "%Y" ${file}) + sed -i -e ${STRIP_TRAILING_WS} -e ${ENSURE_EOFLF} ${file} + newHash=$(hash ${file}) + if [[ $newHash == $oldHash ]]; then touch -d @$oldTime ${file}; fi + done } check lib -- 2.39.2