From 98e2d5d0acdaabd805980944da79619977b76a03 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sun, 22 Sep 2024 11:30:04 +0200 Subject: [PATCH] add a clangd and qtcreator make targets Add a clangd make target: $ make clangd This installs a .clangd file with configuration (includes/macros/compiler flags) for the clandg language server. Add a qtcreator make target: $ make qtcreator This installs a .qtcreator directory with QTCreator IDE project files. In the QTCreator you can open a project by selecting the .qtcreator/pikotools.creator file. You can use 'make qtcreator' again to refresh .qtcreator/pikotools.files, the rest of the project files will not be modified. --- .gitignore | 14 +- .templates/.clangd | 2 + .templates/.qtcreator/pikotools.cflags | 1 + .templates/.qtcreator/pikotools.config | 1 + .templates/.qtcreator/pikotools.creator | 1 + .templates/.qtcreator/pikotools.creator.user | 184 +++++++++++++++++++ .templates/.qtcreator/pikotools.cxxflags | 1 + .templates/.qtcreator/pikotools.files | 1 + .templates/.qtcreator/pikotools.includes | 0 .templates/install_clangd.sh | 30 +++ .templates/install_qtcreator.sh | 71 +++++++ Makefile | 6 + 12 files changed, 302 insertions(+), 10 deletions(-) create mode 100644 .templates/.clangd create mode 100644 .templates/.qtcreator/pikotools.cflags create mode 100644 .templates/.qtcreator/pikotools.config create mode 100644 .templates/.qtcreator/pikotools.creator create mode 100644 .templates/.qtcreator/pikotools.creator.user create mode 100644 .templates/.qtcreator/pikotools.cxxflags create mode 100644 .templates/.qtcreator/pikotools.files create mode 100644 .templates/.qtcreator/pikotools.includes create mode 100755 .templates/install_clangd.sh create mode 100755 .templates/install_qtcreator.sh diff --git a/.gitignore b/.gitignore index d6889ec..5ee970d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,13 +4,7 @@ *.o src/pikotools.a tests/tests -m -.clangd -.qtc_clangd/ -pikotools.cflags -pikotools.config -pikotools.creator -pikotools.creator.user -pikotools.cxxflags -pikotools.files -pikotools.includes +/m +/.clangd +/.qtcreator/ +/.qtc_clangd/ diff --git a/.templates/.clangd b/.templates/.clangd new file mode 100644 index 0000000..2ddd902 --- /dev/null +++ b/.templates/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + Add: [-pthread, -std=c++20, -I%%%CURRENT_DIR%%%/src, -I%%%GLOBAL_WORKING_DIR%%%/morm/src, -I/usr/include, -I/usr/local/include, -DPT_HAS_MORM_LIBRARY] diff --git a/.templates/.qtcreator/pikotools.cflags b/.templates/.qtcreator/pikotools.cflags new file mode 100644 index 0000000..594bcef --- /dev/null +++ b/.templates/.qtcreator/pikotools.cflags @@ -0,0 +1 @@ +-std=c20 diff --git a/.templates/.qtcreator/pikotools.config b/.templates/.qtcreator/pikotools.config new file mode 100644 index 0000000..157c7cc --- /dev/null +++ b/.templates/.qtcreator/pikotools.config @@ -0,0 +1 @@ +#define PT_HAS_MORM_LIBRARY 1 diff --git a/.templates/.qtcreator/pikotools.creator b/.templates/.qtcreator/pikotools.creator new file mode 100644 index 0000000..e94cbbd --- /dev/null +++ b/.templates/.qtcreator/pikotools.creator @@ -0,0 +1 @@ +[General] diff --git a/.templates/.qtcreator/pikotools.creator.user b/.templates/.qtcreator/pikotools.creator.user new file mode 100644 index 0000000..cdf567a --- /dev/null +++ b/.templates/.qtcreator/pikotools.creator.user @@ -0,0 +1,184 @@ + + + + + + EnvironmentId + {5ab9881c-fa5d-4482-9095-89b8f4d69c9e} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + 0 + false + true + false + 0 + true + true + 0 + 8 + true + false + 2 + true + true + true + *.md, *.MD, Makefile + false + true + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + false + + + 0 + true + + true + true + Builtin.DefaultTidyAndClazy + 3 + true + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + Desktop + {d8d7580a-b779-40c7-980c-a52adf87b0ab} + 0 + 0 + 0 + + %%%CURRENT_DIR%%% + + + + all + + /usr/local/bin/gmake + true + GenericProjectManager.GenericMakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + /usr/local/bin/gmake + true + GenericProjectManager.GenericMakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Default + GenericProjectManager.GenericBuildConfiguration + + 1 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + 0 + true + + 2 + + false + -e cpu-cycles --call-graph dwarf,4096 -F 250 + + ProjectExplorer.CustomExecutableRunConfiguration + + false + true + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/.templates/.qtcreator/pikotools.cxxflags b/.templates/.qtcreator/pikotools.cxxflags new file mode 100644 index 0000000..e23b2ae --- /dev/null +++ b/.templates/.qtcreator/pikotools.cxxflags @@ -0,0 +1 @@ +-std=c++20 diff --git a/.templates/.qtcreator/pikotools.files b/.templates/.qtcreator/pikotools.files new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.templates/.qtcreator/pikotools.files @@ -0,0 +1 @@ + diff --git a/.templates/.qtcreator/pikotools.includes b/.templates/.qtcreator/pikotools.includes new file mode 100644 index 0000000..e69de29 diff --git a/.templates/install_clangd.sh b/.templates/install_clangd.sh new file mode 100755 index 0000000..7287ac7 --- /dev/null +++ b/.templates/install_clangd.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +CURRENT_DIR=$(pwd) +GLOBAL_WORKING_DIR=$(realpath ${CURRENT_DIR}/../..) + +# ---------- + +# make sure the current directory is correct +if [ ! -d ${CURRENT_DIR}/.templates ] ; then + echo "this script should be called by make: make clangd (one level up)" + exit 1 +fi + +# change / to \/ in paths +CURRENT_DIR_FOR_SED=$(echo ${CURRENT_DIR} | sed 's/\//\\\//g') +GLOBAL_WORKING_DIR_FOR_SED=$(echo ${GLOBAL_WORKING_DIR} | sed 's/\//\\\//g') + + +if [ -f "${CURRENT_DIR}/.templates/.clangd" ] ; then + if [ ! -f "${CURRENT_DIR}/.clangd" ] ; then + cat "${CURRENT_DIR}/.templates/.clangd" | \ + sed -e "s/%%%CURRENT_DIR%%%/${CURRENT_DIR_FOR_SED}/g" \ + -e "s/%%%GLOBAL_WORKING_DIR%%%/${GLOBAL_WORKING_DIR_FOR_SED}/g" > \ + ${CURRENT_DIR}/.clangd + + echo "added a ${CURRENT_DIR}/.clangd file" + fi +fi + + diff --git a/.templates/install_qtcreator.sh b/.templates/install_qtcreator.sh new file mode 100755 index 0000000..55ab825 --- /dev/null +++ b/.templates/install_qtcreator.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +CURRENT_DIR=$(pwd) +GLOBAL_WORKING_DIR=$(realpath ${CURRENT_DIR}/..) +QTCREATOR_DIR=${CURRENT_DIR}/.qtcreator + +# ---------- + +# make sure the current directory is correct +if [ ! -d ${CURRENT_DIR}/.templates ] ; then + echo "this script should be called by make: make qtcreator (one level up)" + exit 1 +fi + +# change / to \/ in paths +CURRENT_DIR_FOR_SED=$(echo ${CURRENT_DIR} | sed 's/\//\\\//g') +GLOBAL_WORKING_DIR_FOR_SED=$(echo ${GLOBAL_WORKING_DIR} | sed 's/\//\\\//g') + +was_qtcreator_dir=0 + +if [ -d "${QTCREATOR_DIR}" ] ; then + was_qtcreator_dir=1 +else + mkdir -p "${QTCREATOR_DIR}" +fi + +if [ -d "${QTCREATOR_DIR}" ] ; then + + if [ -d ${CURRENT_DIR}/.templates/.qtcreator ] ; then + cd ${CURRENT_DIR}/.templates/.qtcreator + + if [ $? -eq 0 ] ; then + + for i in * ; do + if [ ! -f "${QTCREATOR_DIR}/$i" ] ; then + cat "$i" | \ + sed -e "s/%%%CURRENT_DIR%%%/${CURRENT_DIR_FOR_SED}/g" \ + -e "s/%%%GLOBAL_WORKING_DIR%%%/${GLOBAL_WORKING_DIR_FOR_SED}/g" > \ + "${QTCREATOR_DIR}/$i" + fi + done + + if [ $was_qtcreator_dir -eq 0 ] ; then + echo "QTCreator files generated to ${QTCREATOR_DIR} directory" + echo "select an 'open project...' option and find a ${QTCREATOR_DIR}/*.creator file" + fi + + fi + fi + + + find ${QTCREATOR_DIR} -name "*.files" | while read projectfiles ; do + + cd ${CURRENT_DIR}/src + + if [ $? -eq 0 ] ; then + find ../src -type f \( -iname "*.cpp" -o -iname "*.h" \) | sort > ${projectfiles} + echo "file ${projectfiles} has been updated" + fi + + cd ${CURRENT_DIR}/tests + + if [ $? -eq 0 ] ; then + find ../tests -type f \( -iname "*.cpp" -o -iname "*.h" \) | sort >> ${projectfiles} + fi + + done + +fi + + diff --git a/Makefile b/Makefile index cf1cd7f..9e3a0b0 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,12 @@ depend: FORCE $(MAKE) -C tests depend +clangd: FORCE + @.templates/install_clangd.sh + + +qtcreator: clangd + @.templates/install_qtcreator.sh FORCE: