Skip to content

Commit

Permalink
configure: CMake: Add -no-prefix option
Browse files Browse the repository at this point in the history
Introduce a new -no-prefix option that can be used to build Qt without
having to install it.

Currently, -no-prefix is already implied by -developer-build, but
-developer-build also implies -warnings-are-errors and
-feature-private-tests, which not everyone might want to use.

Some Qt builders likely use -developer-build for the no-prefix
behavior, hence we introduce a standalone -no-prefix option to offer
a nicer user experience without -Werror and friends.

Previously it was possible to achieve the same by specifying
-prefix $PWD, but that relies on $PWD expanding property in the used
shell.

The new -no-prefix doesn't depend on the type of the shell and
is shorter to type.

Internally this gets passed by configure as -DINPUT_no_prefix=yes to
CMake, and transformed into a -DQT_FEATURE_no_prefix=ON feature.

The feature also gets automatically auto-detected to ON if
developer-build is set, -prefix is either unset or $PWD.

CMake code should still query QT_WILL_INSTALL to decide whether
files need to be installed or not.

As a drive-by, we now also export QT_FEATURE_developer_build to
be available for querying during configuration of other repos
(previously it was only possible to query FEATURE_developer_build).

Pick-to: 6.2 6.3
Change-Id: Iaa6c8d8ae2b736282e9949d2a5d7f412e290a253
Reviewed-by: Alexey Edelev <[email protected]>
Reviewed-by: Kai Koehne <[email protected]>
  • Loading branch information
alcroito committed Feb 24, 2022
1 parent 7a58ca2 commit 32b596b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 2 deletions.
8 changes: 8 additions & 0 deletions cmake/QtProcessConfigureArgs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,10 @@ while(1)
if(arg MATCHES "^--?enable-(.*)")
set(opt "${CMAKE_MATCH_1}")
set(val "yes")
# Handle -no-prefix so it's not interpreted as the negation of -prefix
elseif(arg MATCHES "-(no-prefix)")
set(opt "${CMAKE_MATCH_1}")
set(val "")
elseif(arg MATCHES "^--?(disable|no)-(.*)")
set(opt "${CMAKE_MATCH_2}")
set(val "no")
Expand Down Expand Up @@ -902,6 +906,10 @@ foreach(input ${config_inputs})
push("-DINPUT_${cmake_input}=${INPUT_${input}}")
endforeach()

if(DEFINED INPUT_no-prefix AND DEFINED INPUT_prefix)
qtConfAddError("Can't specify both -prefix and -no-prefix options at the same time.")
endif()

if(NOT generator AND auto_detect_generator)
find_program(ninja ninja)
if(ninja)
Expand Down
13 changes: 12 additions & 1 deletion cmake/QtSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ if(NOT FEATURE_developer_build AND INPUT_developer_build
set(FEATURE_developer_build ON)
endif()

# Pre-calculate the no_prefix feature if it's set by configure via INPUT_no_prefix.
# This needs to be done before qtbase/configure.cmake is processed.
if(NOT FEATURE_no_prefix AND INPUT_no_prefix
AND NOT "${INPUT_no_prefix}" STREQUAL "undefined")
set(FEATURE_no_prefix ON)
endif()

set(_default_build_type "Release")
if(FEATURE_developer_build)
set(_default_build_type "Debug")
Expand Down Expand Up @@ -95,7 +102,11 @@ set(CMAKE_LINK_DEPENDS_NO_SHARED ON)
# QtBuildInternalsExtra.cmake file.
if (PROJECT_NAME STREQUAL "QtBase" AND NOT QT_BUILD_STANDALONE_TESTS)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
if(FEATURE_developer_build)
# Handle both FEATURE_ and QT_FEATURE_ cases when they are specified on the command line
# explicitly. It's possible for one to be set, but not the other, because
# qtbase/configure.cmake is not processed by this point.
if(FEATURE_developer_build OR QT_FEATURE_developer_build
OR FEATURE_no_prefix OR QT_FEATURE_no_prefix)
# Handle non-prefix builds by setting the CMake install prefix to point to qtbase's
# build dir. While building another repo (like qtsvg) the CMAKE_PREFIX_PATH should be
# set on the command line to point to the qtbase build dir.
Expand Down
2 changes: 2 additions & 0 deletions cmake/configure-cmake-mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ The following table describes the mapping of configure options to CMake argument
| configure | cmake | Notes |
|---------------------------------------|---------------------------------------------------|-----------------------------------------------------------------|
| -prefix /opt/qt6 | -DCMAKE_INSTALL_PREFIX=/opt/qta6 | |
| -no-prefix (only available in Qt6) | -DCMAKE_INSTALL_PREFIX=$PWD (with bash) | In Qt5 this was done by specifying -prefix $PWD |
| or -DFEATURE_no_prefix=ON | |
| -extprefix /opt/qt6 | -DCMAKE_STAGING_PREFIX=/opt/qt6 | |
| -bindir <dir> | -DINSTALL_BINDIR=<dir> | similar for -headerdir -libdir and so on |
| -hostdatadir <dir> | -DINSTALL_MKSPECSDIR=<dir> | |
Expand Down
4 changes: 4 additions & 0 deletions config_help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Top-level installation directories:
-prefix <dir> ...... The deployment directory, as seen on the target device.
[/usr/local/Qt-$QT_VERSION; qtbase build directory if
-developer-build]
-no-prefix ......... The deployment directory is set to the qtbase build
directory. Can be used instead of -developer-build
to not have to install, as well as avoid
-developer-build's default of -warnings-are-errors.
-extprefix <dir> ... The installation directory, as seen on the host machine.
[SYSROOT/PREFIX]

Expand Down
10 changes: 9 additions & 1 deletion configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,18 @@ qt_feature("pkg-config" PUBLIC
)
qt_feature_config("pkg-config" QMAKE_PUBLIC_QT_CONFIG
NEGATE)
qt_feature("developer-build"
qt_feature("developer-build" PRIVATE
LABEL "Developer build"
AUTODETECT OFF
)
qt_feature("no-prefix" PRIVATE
LABEL "No prefix build"
# The var expansion on the right hand side is on purpose
# because the custom condition evaluator only expands the lhs
CONDITION (CMAKE_INSTALL_PREFIX STREQUAL "${QtBase_BINARY_DIR}")
OR CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT
AUTODETECT QT_FEATURE_developer_build
)
qt_feature("private_tests" PRIVATE
LABEL "Developer build: private_tests"
CONDITION QT_FEATURE_developer_build
Expand Down
2 changes: 2 additions & 0 deletions qt_cmdline.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ qt_commandline_subconfig(src/printsupport)
qt_commandline_subconfig(src/plugins/sqldrivers)
qt_commandline_subconfig(src/testlib)
qt_commandline_subconfig(src/tools)
# no-prefix needs to be placed before prefix
qt_commandline_option(no-prefix TYPE void)
qt_commandline_option(prefix TYPE string)
qt_commandline_option(extprefix TYPE string)
qt_commandline_option(archdatadir TYPE string)
Expand Down

0 comments on commit 32b596b

Please sign in to comment.