summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2020-07-02 22:40:28 +0200
committerJoerg Bornemann <joerg.bornemann@qt.io>2020-07-06 17:43:28 +0200
commitdbd3c7596542ab100a794831f1f28ea00be77a0f (patch)
treed9757c07deba88e2695202d743dd6bacd8830cd4 /cmake
parentffb8464cefd661cfa3428931bd80ee262cacbe13 (diff)
CMake: Teach configure.bat the -cmake argument
The configure scripts need to translate configure options to CMake arguments. It is not sensible to implement this translation twice, in sh and Windows batch language, so we're doing this once, in CMake language. The configure scripts write their options into config.opt and call a CMake script that reads config.opt, does the translation to CMake arguments and calls CMake to generate the build system. While we're at it, implement some more translations than the sh configure provided, like -extprefix, -top-level and -skip. Fixes: QTBUG-85349 Fixes: QTBUG-85350 Task-number: QTBUG-85373 Change-Id: Ida5d8b2a3c178b9349d41ec76d190c69a9456e74 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/QtProcessConfigureArgs.cmake115
1 files changed, 115 insertions, 0 deletions
diff --git a/cmake/QtProcessConfigureArgs.cmake b/cmake/QtProcessConfigureArgs.cmake
new file mode 100644
index 0000000000..f7c771ecf7
--- /dev/null
+++ b/cmake/QtProcessConfigureArgs.cmake
@@ -0,0 +1,115 @@
+# This script reads Qt configure arguments from config.opt,
+# translates the arguments to CMake arguments and calls CMake.
+#
+# This file is to be used in CMake script mode with the following variables set:
+# OPTFILE: A text file containing the options that were passed to configure
+# with one option per line.
+
+cmake_policy(SET CMP0007 NEW)
+
+set(cmake_args "")
+macro(push)
+ list(APPEND cmake_args ${ARGN})
+endmacro()
+
+macro(calculate_state)
+ set(state ON)
+ if(CMAKE_MATCH_1 MATCHES "no-?")
+ set(state OFF)
+ endif()
+endmacro()
+
+macro(pop_path_argument)
+ list(POP_FRONT configure_args path)
+ string(REGEX REPLACE "^\"(.*)\"$" "\\1" path "${path}")
+ file(TO_CMAKE_PATH "${path}" path)
+endmacro()
+
+get_filename_component(source_dir ".." ABSOLUTE BASE_DIR "${CMAKE_CURRENT_LIST_DIR}")
+file(STRINGS "${OPTFILE}" configure_args)
+list(FILTER configure_args EXCLUDE REGEX "^[ \t]*$")
+list(TRANSFORM configure_args STRIP)
+set(set_generator TRUE)
+while(configure_args)
+ list(POP_FRONT configure_args arg)
+ if(arg STREQUAL "-cmake")
+ # ignore
+ elseif(arg STREQUAL "-cmake-makefiles")
+ set(set_generator FALSE)
+ elseif(arg STREQUAL "-top-level")
+ get_filename_component(source_dir "../.." ABSOLUTE BASE_DIR "${CMAKE_CURRENT_LIST_DIR}")
+ elseif(arg STREQUAL "-skip")
+ list(POP_FRONT configure_args qtrepo)
+ push("-DBUILD_${qtrepo}=OFF")
+ elseif(arg STREQUAL "-opensource")
+ # to be done
+ elseif(arg STREQUAL "-commercial")
+ # to be done
+ elseif(arg STREQUAL "-confirm-license")
+ # to be done
+ elseif(arg MATCHES "^-(no)?make")
+ calculate_state()
+ list(POP_FRONT configure_args component)
+ if(component STREQUAL "tests")
+ push(-DBUILD_TESTING=${state})
+ elseif(component STREQUAL "examples")
+ push(-DBUILD_EXAMPLES=${state})
+ else()
+ string(TOUPPER "${component}" uc_component)
+ push(-DQT_NO_MAKE_${uc_component}=${state})
+ endif()
+ elseif(arg MATCHES "^-(no-)?feature")
+ calculate_state()
+ list(POP_FRONT configure_args feature)
+ push("-DFEATURE_${feature}=${state}")
+ elseif(arg MATCHES "^-(no-)pch")
+ calculate_state()
+ push("-DBUILD_WITH_PCH=${state}")
+ elseif(arg MATCHES "^-system-(.*)")
+ list(POP_FRONT configure_args lib)
+ push("-DFEATURE_system_${lib}=ON")
+ elseif(arg MATCHES "^-qt-(.*)")
+ list(POP_FRONT configure_args lib)
+ push("-DFEATURE_system_${lib}=OFF")
+ elseif(arg MATCHES "^-sanitize=(.*)")
+ push("-DECM_ENABLE_SANITIZERS=${CMAKE_MATCH_1}")
+ elseif(arg STREQUAL "-ccache")
+ push(-DQT_USE_CCACHE=ON)
+ elseif(arg STREQUAL "-developer-build")
+ push(-DFEATURE_developer_build=ON)
+ elseif(arg STREQUAL "-prefix")
+ pop_path_argument()
+ push("-DCMAKE_INSTALL_PREFIX=${path}")
+ elseif(arg STREQUAL "-extprefix")
+ pop_path_argument()
+ push("-DCMAKE_STAGING_PREFIX=${path}")
+ elseif(arg STREQUAL "-hostprefix")
+ message(FATAL_ERROR "${arg} is not supported in the CMake build.")
+ elseif(arg STREQUAL "-external-hostbindir")
+ # This points to the bin directory of the Qt installation.
+ # This can be multiple levels deep and we cannot deduce the QT_HOST_PATH safely.
+ message(FATAL_ERROR "${arg} is not supported anymore. Use -qt-host-path <dir> instead.")
+ elseif(arg STREQUAL "-qt-host-path")
+ pop_path_argument()
+ push("-DQT_HOST_PATH=${path}")
+ elseif(arg STREQUAL "--")
+ # Everything after this argument will be passed to CMake verbatim.
+ push(${configure_args})
+ break()
+ else()
+ message(FATAL_ERROR "Unknown configure argument: ${arg}")
+ endif()
+endwhile()
+
+if(set_generator)
+ push(-G Ninja)
+endif()
+
+push("${source_dir}")
+
+execute_process(COMMAND "${CMAKE_COMMAND}" ${cmake_args}
+ COMMAND_ECHO STDOUT
+ RESULT_VARIABLE exit_code)
+if(NOT exit_code EQUAL 0)
+ message(FATAL_ERROR "CMake exited with code ${exit_code}.")
+endif()