CMake: Re-work configure flags for CMake generators

Remove the -cmake-makefiles configure argument as its meaning was in
essence "do not pass a -G argument to CMake".
Instead, we add the following arguments:
    -cmake-generator <name> to pass -G <name> to CMake
    -cmake-use-default-generator to pass no -G argument to CMake

If none of those arguments is given, we try to autodetect the
generator. If a ninja executable is found, we prefer the Ninja
generator. On Unix we fall back to "Unix Makefiles".
On Windows, we do a poor man's compiler detection and select one of
"NMake Makefiles", "NMake Makefiles JOM" and "MinGW Makefiles".

Change-Id: Ic36669bd50956d15fbc71cee73720732cd4bfab8
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Joerg Bornemann 2020-07-03 12:25:44 +02:00
parent dbd3c75965
commit 3ac054d6a8
2 changed files with 34 additions and 5 deletions

View File

@ -29,13 +29,16 @@ get_filename_component(source_dir ".." ABSOLUTE BASE_DIR "${CMAKE_CURRENT_LIST_D
file(STRINGS "${OPTFILE}" configure_args)
list(FILTER configure_args EXCLUDE REGEX "^[ \t]*$")
list(TRANSFORM configure_args STRIP)
set(set_generator TRUE)
unset(generator)
set(auto_detect_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 "-cmake-generator")
list(POP_FRONT configure_args generator)
elseif(arg STREQUAL "-cmake-use-default-generator")
set(auto_detect_generator FALSE)
elseif(arg STREQUAL "-top-level")
get_filename_component(source_dir "../.." ABSOLUTE BASE_DIR "${CMAKE_CURRENT_LIST_DIR}")
elseif(arg STREQUAL "-skip")
@ -101,8 +104,29 @@ while(configure_args)
endif()
endwhile()
if(set_generator)
push(-G Ninja)
if(NOT generator AND auto_detect_generator)
find_program(ninja ninja)
if(ninja)
set(generator Ninja)
else()
if(CMAKE_HOST_UNIX)
set(generator "Unix Makefiles")
elseif(CMAKE_HOST_WINDOWS)
find_program(msvc_compiler cl.exe)
if(msvc_compiler)
set(generator "NMake Makefiles")
find_program(jom jom)
if(jom)
string(APPEND generator " JOM")
endif()
else()
set(generator "MinGW Makefiles")
endif()
endif()
endif()
endif()
if(generator)
push(-G "${generator}")
endif()
push("${source_dir}")

View File

@ -85,6 +85,11 @@ Build options:
-commercial .......... Build the Commercial Edition of Qt
-confirm-license ..... Automatically acknowledge the license
-cmake ............... Use the CMake build system instead of the qmake one.
-cmake-generator <name> ... Explicitly specify the build system generator for
CMake instead of auto-detecting one.
-cmake-use-default-generator ... Turn off auto-detection of the CMake build
system generator.
-release ............. Build Qt with debugging turned off [yes]
-debug ............... Build Qt with debugging turned on [no]
-debug-and-release ... Build two versions of Qt, with and without