I'm searching for way to set Target Platform Version of MSVC project generated with CMake. I found the following ticket in CMake issue tracker which is now closed. I'm with latest 3.9.1 version of CMake. But the solution described there seems to not work. I tried
set (CMAKE_SYSTEM_VERSION 8.1)
in my CMakeLists.txt.
How to set Terget Platform Version when using CMake?
Afterwords:
Now I checked that setting CMAKE_SYSTEM_VERSION from command line when generating solution works but I want if possible to be able to set this from CMakeLists.txt file.
cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_SYSTEM_VERSION=8.1 ..\source\
At least it will be good to be able to set this from CMake GUI.
Using set (CMAKE_SYSTEM_VERSION 8.1 CACHE TYPE INTERNAL FORCE) before first usage of project solves the problem.
Related
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)?
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.
I have a huge project in c++ for which i use cmake to generate the the .proj files.
Using CMake version 3.12.2 which supports generation of VS2017 proj files.
So for windows 64 bit compilation i use the following generator
CMAKE_GENERATOR="Visual Studio 15 2017 Win64"
This creates a .proj file at build time and is used to compile.
But from build logs what i found is that the visual studio compiler cl.exe is taken from cross compilation location
C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.15.26726/bin/Hostx86/x64/cl.exe
/Hostx86/x64/cl.exe is being used.
But i want it to be built strictly using x64 compiler. From /Hostx64/x64/cl.exe
I have read from other questions where people have mentioned to add few tags to the .proj file to force vs to use x64 compiler.
But how do i do that withe cmake file ?
I did not find any reference with this regards except the cmake generator mentioend above.
Could anyone please help me how to use cmake to strictly make VS use x64 compilor?
Note: I want it to be built with x64 compiler because i am linking to the boost library which is also compiled with
address-model=64 architecture=x86
And while the main project is compiled i am getting platform related errors.
fatal error LNK1112: module machine type 'x86' conflicts with target machine type 'x64'
That's why i wanted to compile the main project with x64 compiler.
And also, whats the difference between Hostx86/x64/cl.exe and Hostsx64/x64/cl.exe ?
This is a usual "problem". By default CMake will pick up the 32bits compiler, which is usually fine, except for projects like LLVM.
Use -T host=x64 (see https://cmake.org/cmake/help/v3.11/generator/Visual%20Studio%2015%202017.html) to use the native 64bits compiler.
Note that the last entry in the path is the target platform, not the host platform, so both the 32bits and the 64bits compilers will produce 64bits code.
I've had the same problem as described in the OP.
I think the explicit (and in my opinion recommended) way to set the build system, compiler, architecture, toolset and Windows SDK on a Microsoft Windows operating system is to use the following CMake command line arguments:
-G "Visual Studio 15 2017"
-A x64
-T v141,host=x64,version=14.12.25827
-DCMAKE_CXX_COMPILER:FILEPATH=cl
-DCMAKE_C_COMPILER:FILEPATH=cl
-DCMAKE_SYSTEM_VERSION:STRING=10.0.16299.0
This sets the compiler executable as follows on my system:
%PROGRAMFILES(X86)%\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\bin\Hostx64\x64\cl.exe
The -A x64 argument sets the italic part in the file path above and the ,host=x64 part of the -T argument sets the bold part.
It's also a good idea to explicitly set the toolset, both the major version (v141) and the minor version ,version=14.12.25827.
According to the official CMake documentation the "Visual Studio 15 2017 Win64" generator is there only for compatibility with CMake versions prior to 3.1. I suggest to not use the "[...] Win64" generators any longer in general.
Sources:
https://cmake.org/cmake/help/latest/generator/Visual%20Studio%2015%202017.html
https://cmake.org/cmake/help/latest/variable/CMAKE_GENERATOR_TOOLSET.html
How can I force Cmake to use Visual Studio 2010 for compiling my emscripten projects, and now VS 2015?
I keep running into an issue where cmake says it cannot find the build tools for MSBuild v140. I know it exists though, as the file path is
C:\Program Files (x86)\MSBuild\14.0\Bin
I've even tried setting the path in the Emscripten Command Prompt with
set PATH=C:\Program Files (x86)\MSBuild\14.0\Bin;%PATH%
but the issue still occurs.
If I open this solution in VS 2015, I can see that the configuration is set to Msbuild v 1.40, so I can't wrap my head around why Emscripten says it can't locate it.
The closest thing I could find is in this GitHub bug report on Emscripten.
Any suggestions?
Emscripten in Visual Studio is only supported for VS2010 AFAIK. Personally, I suggest you work with makefiles when generating from CMake. It is much more stable from my experience. The Visual Studio support for Emscripten is not working well, at least for me.
But if you still want to use VS2010, then you have to set the CMake generator to "Visual Studio 10 2010", and then specify the Emscripten toolchain file. You might have to set the CMake platform name to Emscripten, using the -A argument.
cmake.exe -G "Visual Studio 10 2010" -A Emscripten -DCMAKE_TOOLCHAIN_FILE=%EMSCRIPTEN%\cmake\Modules\Platform\Emscripten.cmake
I tried doing this, but each time I did, Emscripten would return a different path to Emscripten.cmake, and say it couldn't find it. Not sure where it was getting this new path from.
Long story short, I realized I installed the web installer for Emscripten installed. So I uninstalled that and instead went with the Full installer, and it all worked well.
With Visual Studio 2012 Update 1 released, I am hoping to build a C++ project to support Windows XP. Is there a way to use CMake to generate a project that targets Windows XP? Basically CMake would need to generate a project file that uses Platform Toolset = Visual Studio 2012 - Windows XP (v110_xp).
According to http://www.cmake.org/Bug/view.php?id=10722 the answer is now (soon) yes.
Fixed in Version CMake 2.8.11
A new "generator toolset" feature has been added here:
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7dab9977 [^]
One may now run CMake from the command line with
-G "Visual Studio 10" -T "v90"
in order to build with a specific toolset. We've not yet added a
first-class interface to cmake-gui for this, but one may add the cache
entry "CMAKE_GENERATOR_TOOLSET" to contain the "-T" value before
configuring.
According to http://www.cmake.org/Bug/view.php?id=10722 the answer is no yes.
Update: The bug mentioned above has been resolved with the following comment:
Fixed in Version CMake 2.8.11
A new "generator toolset" feature has been added here:
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7dab9977 [^]
One may now run CMake from the command line with
-G "Visual Studio 10" -T "v90"
in order to build with a specific toolset. We've not yet added a
first-class interface to cmake-gui for this, but one may add the cache
entry "CMAKE_GENERATOR_TOOLSET" to contain the "-T" value before
configuring.
You might also look at the comments made to the other answers.
I think you can just generate a Solution for Visual Studio 2010/2012. Open this solution, open the solution/project in visual Studio, open the properties and reconfigure the Platform toolset to v110_xp.
Then you should be fine. But I'm still searching for the solution how to setupo the command line to build v110_xp programs...
I think the best way to address this problem is use CMake to build your project for Visual Studio 2010 and then open the project with Visual Studio 2012. When you do this the toolset used will be vs2010, which works for WinXP.
I have the Intel compiler platform install on my development machine, when using Cmake to generate a visual studio 2010 solution, I want to be able to specify the platform toolset to be using "Intel" instead of "vc100".
I cant seem to find the setting to change this, when I change the compiler to icl the solution still builds with the vc100 compiler until I manually change the platform toolset.
I was looking for similar functionality as well, for setting the Windows SDK 7.1 as the default toolset for a large number of projects, without having to go through and change each one by hand.
I believe that the CMAKE people have added that functionality, and you can use something like:
set_target_properties(${YOUR TARGET} PROPERTIES PLATFORM_TOOLSET "Intel C++ Compiler XE 12.1")
Have a look at:
http://public.kitware.com/Bug/view.php?id=12876
for details of the change.
I was able to change the platform toolset by using a command-line option (CMake 3.2):
cmake . -G "Visual Studio 12" -T "LLVM-vs2013"