Skip to content

Commit

Permalink
CMake: Re-work configure flags for CMake generators
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jobor committed Jul 6, 2020
1 parent dbd3c75 commit 3ac054d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
34 changes: 29 additions & 5 deletions cmake/QtProcessConfigureArgs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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}")
Expand Down
5 changes: 5 additions & 0 deletions config_help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3ac054d

Please sign in to comment.