-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)
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}
)
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)
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
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)
cd ${0%/*}
cd ..
+VERBOSE=${VERBOSE:-1}
+
function startswith() {
declare -l file="${1}"
declare -l prelude="${2}"
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
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
}
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