No C or C++ compiler found Visual Studio 2017 Cmake - windows

I have seen tons of posts on this particular issue and I have tried about every one that I could find. I am completely lost and stuck on this issue now and I don't really know where to turn.
I get the following error when I run my cmake file:
The C compiler identification is unknown
The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:9 (project):
No CMAKE_C_COMPILER could be found.
CMake Error at CMakeLists.txt:9 (project):
No CMAKE_CXX_COMPILER could be found.
Which is super confusing to me, since I have built a cmake project, using the same compiler with Cmake before with no errors. I even copied the elements from their cmake file into mine to see if it would make a difference but I always end up with the same error. I have even sent the test project I made to another coworker and their cmake compiled my program just fine and created a visual studio project solution with no issues.
Which makes me believe that there is something going on my end that is causing it to fail to find my compilers. Steps that I have taken:
I have added the Windows kits to my path
I have added the vcvashall.bat and cl.exe to my path
I have downloaded and installed individual plugins with Visual Studio such as:
Visual Studio C++ Core features
Visual C++ 2017 Redistributable Update
VC++ 2017 version 15.9 v14.16 latest v141 tools
Windows 10 SDK (10.0.17763.0)
Visual C++ runtime for UWP
Windows Universal C Runtime
Visual Studio SDK
Visual C++ tools for CMake and Linux
Visual C++ tools for CMake
I have tried the GUI, the Command Prompt, and Visual Studio Developer Command Prompt. All of which do not work. I have typed:
cmake --help and it automatically detects Visual Studio 15 2017 as the default compiler. I have tried cmake -G "Visual Studio 15 2017 Win64" and that also does not work.
I have since all of this, uninstalled Cmake and reinstalled it and the same issue still persists. What I haven't tried is uninstalling Visual Studio 2017 and reinstalling it again. It is also important to note, I do not have any other visual studio installations on my machine. This is the only one that I have. I do have MinGW, and I have used that successfully. However I am trying to build a Visual Studio solution.
As I have said, I am very stuck on this issue and I really do not understand why one cmake script detects and builds:
The C compiler identification is MSVC 19.16.27031.1
The CXX compiler identification is MSVC 19.16.27031.1
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
And then mine fails to find my compiler and aborts above. I can link the test project for those who want to try and compile my program. I know links are looked down on, so if it is requested I will make it available to download.

I am not an expert in cmake, and struggled through this error for weeks. I finally solved it by uninstalling cmake and installing a different version of cmake. I have no idea why that worked but it did.

Related

CMake toolset specification seems to be ignored

I'm trying to compile instant-ngp, but there are bugs building on Windows that require you to force MSVC to 14.25 (Documented in this GitHub issue.)
I'm trying to override this with -T version=14.25 or -DCMAKE_GENERATOR_TOOLSET=version=14.25, but they just don't work.
> cmake . -B build -T 'version=14.25'
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19044.
-- The C compiler identification is MSVC 19.29.30146.0
-- The CXX compiler identification is MSVC 19.29.30146.0
...
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
...
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
...
And it definitely builds with the 14.29 compiler.
14.25 is installed, and I know CMake can see it because if I try a version like 14.24 I get an error message about that not being installed, but 14.25 works.
How do I make CMake respect this setting instead of instantly ignoring it?

OpenCV error: No CMAKE_C_COMPILER could be found [duplicate]

I'm trying make a Visual Studio solution with CMake to compile the latest version of aseprite and CMake keeps giving me the:
No CMAKE_C_COMPILER could be found.
No CMAKE_CXX_COMPILER could be found.
I've already downloaded GCC, and I'm using Visual Studio 2015.
I'm following this tutorial:
https://github.com/aseprite/aseprite/blob/master/INSTALL.md
For Ubuntu, please install the below things:
sudo apt-get update && sudo apt-get install build-essential
Those error messages
CMake Error at ... (project):
No CMAKE_C_COMPILER could be found.
-- Configuring incomplete, errors occurred!
See also ".../CMakeFiles/CMakeOutput.log".
See also ".../CMakeFiles/CMakeError.log".
or
CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found.
Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
...
-- Configuring incomplete, errors occurred!
just mean that CMake was unable to find your C/CXX compiler to compile a simple test program (one of the first things CMake tries while detecting your build environment).
The steps to find your problem are dependent on the build environment you want to generate. The following tutorials are a collection of answers here on Stack Overflow and some of my own experiences with CMake on Microsoft Windows 7/8/10 and Ubuntu 14.04.
Preconditions
You have installed the compiler/IDE and it was able to once compile any other program (directly without CMake)
You e.g. may have the IDE, but may not have installed the compiler or supporting framework itself like described in Problems generating solution for VS 2017 with CMake or How do I tell CMake to use Clang on Windows?
You have the latest CMake version
You have access rights on the drive you want CMake to generate your build environment
You have a clean build directory (because CMake does cache things from the last try) e.g. as sub-directory of your source tree
Windows cmd.exe
> rmdir /s /q VS2015
> mkdir VS2015
> cd VS2015
Bash shell
$ rm -rf MSYS
$ mkdir MSYS
$ cd MSYS
and make sure your command shell points to your newly created binary output directory.
General things you can/should try
Is CMake able find and run with any/your default compiler? Run without giving a generator
> cmake ..
-- Building for: Visual Studio 14 2015
...
Perfect if it correctly determined the generator to use - like here Visual Studio 14 2015
What was it that actually failed?
In the previous build output directory look at CMakeFiles\CMakeError.log for any error message that make sense to you or try to open/compile the test project generated at CMakeFiles\[Version]\CompilerIdC|CompilerIdCXX directly from the command line (as found in the error log).
CMake can't find Visual Studio
Try to select the correct generator version:
> cmake --help
> cmake -G "Visual Studio 14 2015" ..
If that doesn't help, try to set the Visual Studio environment variables first (the path could vary):
> "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
> cmake ..
or use the Developer Command Prompt for VS2015 short-cut in your Windows Start Menu under All Programs/Visual Studio 2015/Visual Studio Tools (thanks at #Antwane for the hint).
Background: CMake does support all Visual Studio releases and flavors (Express, Community, Professional, Premium, Test, Team, Enterprise, Ultimate, etc.). To determine the location of the compiler it uses a combination of searching the registry (e.g. at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\[Version];InstallDir), system environment variables and - if none of the others did come up with something - plainly try to call the compiler.
CMake can't find GCC (MinGW/MSys)
You start the MSys bash shell with msys.bat and just try to directly call gcc
$ gcc
gcc.exe: fatal error: no input files
compilation terminated.
Here it did find gcc and is complaining that I didn't gave it any parameters to work with.
So the following should work:
$ cmake -G "MSYS Makefiles" ..
-- The CXX compiler identification is GNU 4.8.1
...
$ make
If GCC was not found call export PATH=... to add your compilers path (see How to set PATH environment variable in CMake script?) and try again.
If it's still not working, try to set the CXX compiler path directly by exporting it (path may vary)
$ export CC=/c/MinGW/bin/gcc.exe
$ export CXX=/c/MinGW/bin/g++.exe
$ cmake -G "MinGW Makefiles" ..
-- The CXX compiler identification is GNU 4.8.1
...
$ mingw32-make
For more details see How to specify new GCC path for CMake
Note: When using the "MinGW Makefiles" generator you have to use the mingw32-make program distributed with MinGW
Still not working? That's weird. Please make sure that the compiler is there and it has executable rights (see also preconditions chapter above).
Otherwise the last resort of CMake is to not try any compiler search itself and set CMake's internal variables directly by
$ cmake -DCMAKE_C_COMPILER=/c/MinGW/bin/gcc.exe -DCMAKE_CXX_COMPILER=/c/MinGW/bin/g++.exe ..
For more details see Cmake doesn't honour -D CMAKE_CXX_COMPILER=g++ and Cmake error setting compiler
Alternatively those variables can also be set via cmake-gui.exe on Windows. See Cmake cannot find compiler
Background: Much the same as with Visual Studio. CMake supports all sorts of GCC flavors. It searches the environment variables (CC, CXX, etc.) or simply tries to call the compiler. In addition it will detect any prefixes (when cross-compiling) and tries to add it to all binutils of the GNU compiler toolchain (ar, ranlib, strip, ld, nm, objdump, and objcopy).
This happened to me after I installed Visual Studio 15 2017.
The C++ compiler for Visual Studio 14 2015 was not the problem. It seemed to be a problem with the Windows 10 SDK.
Adding the Windows 10 SDKs to Visual Studio 14 2015 solved the problem for me.
See attached screenshot.
This works for me in Ubuntu 17.10 (Artful Aardvark):
apt-get update
apt-get install build-essential
I also experienced this error when working with CMake:
No CMAKE_C_COMPILER could be found.
No CMAKE_CXX_COMPILER could be found.
The 'warning' box in the MSDN library article Visual C++ in Visual Studio 2015 gave me the help that I needed.
Visual Studio 2015 doesn't come with C++ installed by default. So, creating a new C++ project will prompt you to download the necessary C++ components.
I ran into this issue while building libgit2-0.23.4. For me the problem was that C++ compiler & related packages were not installed with VS2015, therefore "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" file was missing and Cmake wasn't able to find the compiler.
I tried manually creating a C++ project in the Visual Studio 2015 GUI (C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe)
and while creating the project, I got a prompt to download the C++ & related packages.
After downloading required packages, I could see vcvarsall.bat & Cmake was able to find the compiler & executed successfully with following log:
C:\Users\aksmahaj\Documents\MyLab\fritzing\libgit2\build64>cmake ..
-- Building for: Visual Studio 14 2015
-- The C compiler identification is MSVC 19.0.24210.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual
Studio 14.0/VC/bin/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual
Studio 14.0/VC/bin/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
-- Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
-- zlib was not found; using bundled 3rd-party sources.
-- LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of
the default search path.
-- Looking for futimens
-- Looking for futimens - not found
-- Looking for qsort_r
-- Looking for qsort_r - not found
-- Looking for qsort_s
-- Looking for qsort_s - found
-- Looking for clock_gettime in rt
-- Looking for clock_gettime in rt - not found
-- Found PythonInterp: C:/csvn/Python25/python.exe (found version "2.7.1")
-- Configuring done
-- Generating done
-- Build files have been written to:
C:/Users/aksmahaj/Documents/MyLab/fritzing/libgit2/build64
I had the same errors with CMake. In my case, I have used the wrong Visual Studio version in the initial CMake dialog where we have to select the Visual Studio compiler.
Then I changed it to "Visual Studio 11 2012" and things worked. (I have Visual Studio Ultimate 2012 version on my PC). In general, try to input an older version of Visual Studio version in the initial CMake configuration dialog.
For me, this problem went away on Windows when I moved my project to a shallower parent directory, i.e. to:
C:\Users\spenc\Desktop\MyProjectDirectory
instead of
C:\Users\spenc\Desktop\...\MyProjectDirectory.
I think the source of the problem was that MSBuild has a file path length restriction to 260 characters. This causes the basic compiler test CMake performs to build a project called CompilerIdCXX.vcxproj to fail with the error:
C1083: Cannot open source file: 'CMakeCXXCompilerId.cpp'
because the length of the file's path e.g.
C:\Users\spenc\Desktop\...\MyProjectDirectory\build\CMakeFiles\...\CMakeCXXCompilerId.cpp
exceeds the MAX_PATH restriction.
CMake then concludes there is no CXX compiler.
Make sure you have selected the correct version of Visual Studio. This is trickier than it seems because Visual Studio 2015 is actually Visual Studio 14, and similarly Visual Studio 2012 is Visual Studio 11. I had incorrectly selected Visual Studio 15 which is actually Visual Studio 2017, when I had 2015 installed.
After trying out all of the solutions with no luck, I just provided those missing parameter by cmake -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ ...
Make sure you have installed Windows SDK when you were installing Visual Studio. To add windows SDK you can go to Visual Studio Installer and hit "Modify" and then tick the checkbox of Windows SDK and install it.
None of the solutions here solves my problem - only when I install Windows Update for universal C runtime.
Now CMake is working and no more link hangs from Visual Studio.
Update for Universal C Runtime in Windows
You can also make sure you are the sudo user and you have READ/WRITE access on the directory you are working. I had a similar problem on OS X, and I got it fixed just by entering in sudo mode.
Just in case it helps any one like me in future:
I have had this issue for 24 hours now, on 3 different 64-bit machines(Win7 , Windows 8.1 VM and WIn 8.1 laptop) - whilst trying to build WebKit with VS 2017.
The simple issue here is that the VC++ compiler (i.e cl.exe and it's dependent DLLs) is not visible to CMake. Simple. By making the VC++ folders containing those binaries visible to CMake and your working command prompt(if you're running Cmake from a command prompt), voila! (In addition to key points raised by others , above)
Anyway, after all kinds of fixes - as posted on these many forums- I discovered that it was SIMPLY a matter of ensuring that the PATH variable's contents are not cluttered with multiple Visual Studio BIN paths etc; and instead, points to :
a) the location of your compiler (i.e. cl.exe for your preferred version of Visual Studio ), which in my case(targeting 64-bit platform, and developing on a 64-bit host) is:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\Hostx64\x64
b) and in addition, the folder containing a dependent DLL called (which cl.exe is dependent on):
api-ms-win-crt-runtime-l1-1-0.dll - which on my machine is:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\Remote Debugger\x64
These two directories being added to a simplified and CUSTOM System Path variable(working under a Admin priviledged commmand prompt), eliminated my "No CMAKE_C_COMPILER could be found" and "No CMAKE_CXX_COMPILER could be found." errors.
Hope it helps someone.
I get exactly the reported error if ccache is enabled, when using CMake's Xcode generator. Disabling ccache fixed the problem for me. Below I present a fix/check that works for MacOS, but should work similarly on other platforms.
Apparently, it is possible to use CMake's Xcode generator (and others) also in combination with ccache, as is described here. But I never tried it out myself.
# 1) To check if ccache is enabled:
echo $CC
echo $CXX
# This prints something like the following:
# ccache clang -Qunused-arguments -fcolor-diagnostics.
# CC or CXX are typically set in the `.bashrc` or `.zshrc` file.
# 2) To disable ccache, use the following:
CC=clang
CXX=clang++
# 3) Then regenerate the cmake project
cmake -G Xcode <path/to/CMakeLists.txt>
I know this question is about visual studio 2015. I faced this issue with visual studio 2017. When searched on google I landed to this page. After looking at first 2,3 answers I realized this is the problem with vc++ installation. Installing the workload "Desktop development with c++" resolved the issue.
I updated Visual Studio 2015 update 2 to Visual Studio 2015 update 3, and it solved my problem.
I had the same issue with cmake-gui (No CMAKE_CXX_COMPILER could be found.), while running CMake from the command line worked fine. After manually adding the entries
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin
to the PATH environment variable it worked for me.
For me it worked to use the Developer Command Prompt that comes with Visual Studio and then just cd to your/jcef/dir and run cmake -G "Visual Studio 14 Win64" ..
I had the same problem.
I was trying to install dlib on my machine and it gave me this error.
The tutorial mentioned in the question leads to downloading visual studio 2017. I solved this by uninstalling VS 2017 and installing VS 2015
One can install VS 2015 via this stackoverflow thread :
How to download Visual Studio Community Edition 2015 (not 2017)
Look in the Cmakelists.txt if you find ARM you need to install C++ for ARM
It's these packages:
C++ Universal Windows Platform for ARM64 "Not Required"
Visual C++ Compilers and libraries for ARM "Not Required"
Visual C++ Compilers and libraries for ARM64 "Very Likely Required"
Required for finding Threads on ARM
enable_language(C)
enable_language(CXX)
Then the problems
No CMAKE_C_COMPILER could be found.
No CMAKE_CXX_COMPILER could be found.
Might disappear unless you specify c compiler like clang, and maybe installing clang will work in other favour.
You can with optional remove in cmakelists.txt both with # before enable_language if you are not compiling for ARM.
On M1 Mac, add the following config to fix it for me
-DCMAKE_C_COMPILER="${OTHER_CXX_FLAG}" -DCMAKE_C_COMPILER="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -DCMAKE_CXX_COMPILER="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++"
The config result is:
cmake ../build -DCMAKE_C_COMPILER="${OTHER_CXX_FLAG}" -DCMAKE_C_COMPILER="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -DCMAKE_CXX_COMPILER="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++" -DCMAKE_SYSTEM_NAME=Darwin -DCMAKE_TARGET_SYSTEM=mac -GXcode

Failing to compile Visual Studio project via the command line. What am I doing wrong?

I am not really trying to learn C/C++ but I need to compile the sources for a utility that I will be using with Python.
The installation instructions say that I need to run CMake to build the Visual Studio Project. After I successfully run that I got this output
C:/metis-5.1.0\build\Windows>cmake -DCMAKE_CONFIGURATION_TYPES="Release" ..\..
-- Building for: Visual Studio 14 2015
-- Selecting Windows SDK version to target Windows 10.0.17134.
-- The C compiler identification is MSVC 19.0.24210.0
-- The CXX compiler identification is MSVC 19.0.24210.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for execinfo.h
-- Looking for execinfo.h - not found
-- Looking for getline
-- Looking for getline - not found
-- Configuring done
-- Generating done
-- Build files have been written to: C:/metis-5.1.0/build/Windows
Since I need to build the above for Python 3.5 x86 I thought that the best option was to use Visual C++ 2015 x86 x64 Cross Build Tools Command Prompt So I opened up that command prompt and I used the following command line to compile the resulting project (created by the above)
C:\metis-5.1.0\build\Windows>MSBuild METIS.sln /property:Configuration=Release /property:Platform=x86
Microsoft (R) Build Engine version 14.0.25420.1
Copyright (C) Microsoft Corporation. All rights reserved.
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 9/8/2018 8:36:45 PM.
Project "c:\metis-5.1.0\build\Windows\METIS.sln" on node 1 (default targets).
c:\metis-5.1.0\build\Windows\METIS.sln.metaproj : error MSB4126: The specified solutio
n configuration "Release|x86" is invalid. Please specify a valid solution configuration using the Configuration and Platform proper
ties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU") or leave those properties blank to use the defaul
t solution configuration. c:\metis-5.1.0\build\Windows\METIS.sln]
Done Building Project "c:\metis-5.1.0\build\Windows\METIS.sln" (default targets) -- FA
ILED.
Build FAILED.
c:\metis-5.1.0\build\Windows\METIS.sln" (default target) (1) ->
(ValidateSolutionConfiguration target) ->
c:\metis-5.1.0\build\Windows\METIS.sln.metaproj : error MSB4126: The specified solut
ion configuration "Release|x86" is invalid. Please specify a valid solution configuration using the Configuration and Platform prop
erties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU") or leave those properties blank to use the defa
ult solution configuration. [c:\metis-5.1.0\build\Windows\METIS.sln]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.10
What am I doing wrong ?
Update: here are the build instructions
The Visual Studio project will be called METIS.sln. Open it in Visual
Studio. If the configuration is not already "Release", set it to
"Release". Type F7 to build. The METIS library will be in
<BINARY_DIR>\libmetis\Release and the executable programs will be in
<BINARY_DIR>\programs\Release. (<BINARY_DIR> will be build\windows if
you used the command line or whatever you choose if using the CMake
GUI.)
They are for Visual Studio not for Command Line so I do not know if I have to set the "Release" flag and where ?
Update: changing the command line to
MSBuild METIS.sln /property:Configuration=Release /property:Platform=Win32 Solved the problem but now I am getting other errors :-(
Had to change the command line Platform option to Win32

cmake fails to pick up clang++ and always use visual studio instead on Windows

I have visual studio 2017 and clang both installed in a 64-bit Windows 10 PC.
clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
I have tried running cmake with clang using:
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
but cmake always pick up visual studio instead of clang as the c++ compiler.
-- Building for: Visual Studio 15 2017
-- The C compiler identification is MSVC 19.13.26131.1
-- The CXX compiler identification is MSVC 19.13.26131.
Is there a way to ONLY use clang as my c++ compiler in cmake without other tools like visual studio?
If you wish to use VisualStudio 201x with clang/c2 compiler, forgot about linux/mac approach (it works for mingw/msys etc.). There is no need to use these CMAKE_C??_COMPILER variables.
Try e.g.
cd build
cmake -G"Visual Studio 15 2017" -T "v141_clang_c2" <SRC_DIR>
I list of available toolsets can be observed when you open any C++ project and then look to Propertiese menu -> General: "Platform toolsets" combobox-list
Or using LLVM snapshot build the page define toolset names to be used in above command e.g. LLVM-vs2013.
sample output:
C:\work\build>cmake -G"Visual Studio 15 2017" -T"v141_clang_c2" <SRC>
-- The C compiler identification is Clang 3.8.0
-- The CXX compiler identification is Clang 3.8.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/ClangC2/14.10.25903/bin/HostX86/clang.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/ClangC2/14.10.25903/bin/HostX86/clang.exe -- works
-- Detecting C compiler ABI info
....

How to generate a Visual Studio project that uses the Intel Compiler using cmake under Windows

I'm developing a cross-platform (Linux/Windows) application in C. I've gotten tired of maintaining both a usable Makefile and the Visual Studio solution/projects so I wanted to transition to cmake. I'm using the Intel Compiler on both platforms.
I've downloaded cmake 3.0 on Windows and cmake 2.8 on Linux (it's the one in ubuntu 12.04 repositories). On Linux everything went smooth and the Makefiles were generated successfully. It was a simple matter of running: CC=icc CXX=icc cmake ...
On Windows, however, no matter what command I try I cannot use the Intel Compiler. The output vcxproj is always using the MSVC compiler.
I've tried the following command:
cmake -G "Visual Studio 11 2012 Win64" -D CMAKE_C_COMPILER="C:/Program Files (x86)/Intel/Composer XE/bin/intel64/icl.exe" -D CMAKE_CXX_COMPILER="C:/Program Files (x86)/Intel/Composer XE/bin/intel64/icl.exe" ..
The output is:
-- The C compiler identification is MSVC 17.0.61030.0
-- The CXX compiler identification is MSVC 17.0.61030.0
-- Check for working C compiler using: Visual Studio 11 2012 Win64
-- Check for working C compiler using: Visual Studio 11 2012 Win64 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 11 2012 Win64
-- Check for working CXX compiler using: Visual Studio 11 2012 Win64 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
When I change the generator to "NMake Makefiles" then icc is set as the compiler.
-- The C compiler identification is Intel 14.0.3.20140422
-- The CXX compiler identification is Intel 14.0.3.20140422
-- Check for working C compiler: C:/Program Files (x86)/Intel/Composer XE/bin/intel64/icl.exe
I'm testing this on a pretty basic project with only one source file, so my CMakeLists.txt file contains only:
project(dummy_cmake)
add_executable(hellonikola main.c)
Any help is greatly appreciated!
P.S.
cmake-gui behaves the same. I select to specify a different native compiler and give the path to icc and get the above outputs as well.
I've tried using cmake 2.8 on Windows as well and the behaviour is the same.
I've found the answer so I'm posting it in case anyone else has the same problem.
The solution was to add this line to the CMakeLists.txt
set(CMAKE_GENERATOR_TOOLSET "Intel C++ Compiler XE 14.0" CACHE STRING "Platform Toolset" FORCE)
I found this out on this blog and adapted it to use the Intel Compiler.

Resources