PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, September 13, 2022

[FIXED] How to crosscompile qt applications with CMake

 September 13, 2022     c++, cmake, cross-compiling, cross-platform, qt     No comments   

Issue

The situation is:

There is a compiled qt application for different platforms: Linux, Windows, Android (soon and Mac) on the Linux host. I need to build an application for all platforms on a Linux host.

I used qmake and everything was very simple there, it was enough to call qmake and pass -spec to it. Qmake wrote the necessary paths to variables on its own, and everything worked fine.

Now I am switching to CMake and I am having difficulty invoking CMake. How can I build the application for a specific platform?

  • Does CMake have a possibility similar to "spec" in qmake?

  • Or I need to manually set all the variables (I could not implement such a method)?


Solution

The CMake-equivalent of the qmake -spec option is essentially the -G (for "generator") command line option. This will tell CMake which generator to use. The CMake generator is responsible for generating the native buildsystem files (e.g. Unix Makefiles, Visual Studio project files, etc.) so it is a platform-dependent setting. For example,

cmake -G "Unix Makefiles" ..

Unlike qmake, where you specify a path to the platform/compiler information, you can tell CMake out-right which generator to choose from the list of supported generators. The CMake documentation conveniently breaks down the list of supported generators into command line and IDE groups. If you don't explicitly pick a generator, CMake will use a default generator based on the current platform.

CMake also provides additional options (that can be used along with -G) to further specify which toolset (-T) or platform (-A) to use with the generated buildsystem. The toolset and platform specifications can tell the buildsystem which specific compiler or SDK to choose. For example, we can tell CMake to prepare a build environment for an application with a Win32 platform (architecture) with Visual Studio 2019 using this:

cmake -G "Visual Studio 16 2019" -A Win32 ..

or we can change the architecture to 64-bit by specify this instead:

cmake -G "Visual Studio 16 2019" -A x64 ..

I encourage you to read through the linked documentation to understand more about how you can control CMake's buildsystem and compiler selection settings.



Answered By - Kevin
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing