Reputation: 939
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)?
Upvotes: 1
Views: 576
Reputation: 18243
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.
Upvotes: 1