summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorAlexey Edelev <alexey.edelev@qt.io>2023-01-18 22:06:08 +0100
committerAlexey Edelev <alexey.edelev@qt.io>2023-02-08 12:59:19 +0100
commit214c3a033a4e9191f0082bf6f88624d356a45384 (patch)
tree95f412ee2ab668e1b903ae1d002d32f3decd27ea /bin
parent52150469a837a1eca7e31b8aaea077127db0432f (diff)
Add simple project generation based on existing source files
Introduce the qt-cmake-create script. The script generates the simple CMakeLists.txt based on the source files located in the current or specified directory. The initial version can generate a CMake code for the following file types: - .c .cc .cpp .cxx .h .hh .hxx .hpp - generates the qt_add_executable call with prerequisites. - .qml .js .mjs - generates the qt_add_qml_module call with prerequisites. - .ui - adds the found ui files to the existing executable. Requires C++ files be present in the directory too. - .qrc - generates the qt_add_resources call and adds the resources to the existing executable. Requires C++ files be present in the directory too. - .proto - generates qt_add_protobuf call with prerequisites. The QtInitProject.cmake script contains the 'handle_type' function that allows extending the script capabilities and establish simple relation chains between the file types. Note: The initial implementation doesn't deal with sub-directories, so all files from sub-directories will be added to and handled in the top-level CMakeLists.txt file. This can be extended by user request. Task-number: QTBUG-104388 Change-Id: I5abd9e07da109e867ff95986572ed2bf02ef9d3d Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'bin')
-rw-r--r--bin/qt-cmake-create.bat.in18
-rwxr-xr-xbin/qt-cmake-create.in29
2 files changed, 47 insertions, 0 deletions
diff --git a/bin/qt-cmake-create.bat.in b/bin/qt-cmake-create.bat.in
new file mode 100644
index 0000000000..ff8f7310e9
--- /dev/null
+++ b/bin/qt-cmake-create.bat.in
@@ -0,0 +1,18 @@
+@echo off
+:: The directory of this script is the expanded absolute path of the "$qt_prefix/bin" directory.
+set script_dir_path=%~dp0
+
+:: Try to use original cmake, otherwise to make it relocatable, use any cmake found in PATH.
+set cmake_path=@CMAKE_COMMAND@
+if not exist "%cmake_path%" set cmake_path=cmake
+
+if NOT "%~2" == "" goto :showhelp
+if NOT "%~1" == "" (set PROJECT_DIR=%~1) else (set PROJECT_DIR=%cd%)
+
+"%cmake_path%" -DPROJECT_DIR="%PROJECT_DIR%" -P "%script_dir_path%\@__GlobalConfig_relative_path_from_bin_dir_to_cmake_config_dir@\QtInitProject.cmake"
+exit /b %errorlevel%
+
+:showhelp
+echo Usage
+echo. qt-cmake-create <path/to/project>
+exit /b 1
diff --git a/bin/qt-cmake-create.in b/bin/qt-cmake-create.in
new file mode 100755
index 0000000000..7865d0fe91
--- /dev/null
+++ b/bin/qt-cmake-create.in
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+HELP_MESSAGE="Usage
+ qt-cmake-create <path/to/project>"
+
+# The directory of this script is the expanded absolute path of the "$qt_prefix/bin" directory.
+script_dir_path=`dirname $0`
+script_dir_path=`(cd "$script_dir_path"; /bin/pwd)`
+
+# Try to use original cmake, otherwise to make it relocatable, use any cmake found in PATH.
+original_cmake_path="@CMAKE_COMMAND@"
+cmake_path=$original_cmake_path
+if ! test -f "$cmake_path"; then
+ cmake_path="cmake"
+fi
+
+if [ "$#" -gt 1 ]; then
+ echo "Invalid number of arguments"
+ echo "$HELP_MESSAGE"
+ exit 1
+fi
+
+if [ "$#" -gt 0 ]; then
+ PROJECT_DIR=$1
+else
+ PROJECT_DIR=$PWD
+fi
+exec "$cmake_path" -DPROJECT_DIR="$PROJECT_DIR" -P \
+ "$script_dir_path/@__GlobalConfig_relative_path_from_bin_dir_to_cmake_config_dir@/QtInitProject.cmake"