I'm a beginner in CMake and just recently migrated my current project from a Visual Studio 2015 solution to a CMake project. It took me a few days, but now I'm at the point where my project is fully migrated and the generated Visual Studio solution looks and feels exactly like the original solution. I can still build my project fine when using MSVC and platform toolset v140. Now after all of this, I wanted to try the benefits of CMake by building my project with different compilers. In particular, there is some template-related code in my project that I think is not very standard-conform, so I wanted to build it with Clang, which I know is stricter than MSVC on template-related stuff. To do this, I started CMake GUI, selected source code and binary paths, clicked configure, selected "Visual Studio 14 2015" and typed "v140_clang_3_7" into the platform toolset field, leaving all other settings untouched.
Unfortunately, when doing this, CMake fails to configure (and generate) my solution with the following error:
The C compiler identification is Clang 3.7.0
The CXX compiler identification is Clang 3.7.0
Check for working C compiler using: Visual Studio 14 2015
Check for working C compiler using: Visual Studio 14 2015 -- broken
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.5/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "C:/Program Files (x86)/Microsoft Visual Studio
14.0/VC/bin/cl.exe" is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/marku/Desktop/build_muell/CMakeFiles/CMakeTmp
Run Build Command:"C:/Program Files (x86)/MSBuild/14.0/bin/MSBuild.exe"
"cmTC_c4641.vcxproj" "/p:Configuration=Debug" "/p:VisualStudioVersion=14.0"
Microsoft (R)-Buildmodul, Version 14.0.25123.0
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.
Der Buildvorgang wurde am Mo, 23.05.2016 00:52:13 gestartet.
Das in einem BeforeTargets-Attribut bei "C:\Program Files
(x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets
(34,37)" aufgef�hrte Ziel "_ConvertPdbFiles" ist nicht im Projekt vorhanden
und wird daher ignoriert.
Das in einem AfterTargets-Attribut bei "C:\Program Files
(x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets
(34,70)" aufgef�hrte Ziel "_CollectPdbFiles" ist nicht im Projekt vorhanden
und wird daher ignoriert.
Das in einem BeforeTargets-Attribut bei "C:\Program Files
(x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets
(40,38)" aufgef�hrte Ziel "_CollectMdbFiles" ist nicht im Projekt vorhanden
und wird daher ignoriert.
Das in einem AfterTargets-Attribut bei "C:\Program Files
(x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets
(40,71)" aufgef�hrte Ziel "_CopyMdbFiles" ist nicht im Projekt vorhanden
und wird daher ignoriert.
Projekt
"C:\Users\marku\Desktop\build_muell\CMakeFiles\CMakeTmp\cmTC_c4641.vcxproj"
auf Knoten "1" (Standardziele).
PrepareForBuild:
Das Verzeichnis "cmTC_c4641.dir\Debug\" wird erstellt.
Das Verzeichnis "C:\Users\marku\Desktop\build_muell\CMakeFiles\CMakeTmp\Debug\" wird erstellt.
Das Verzeichnis "cmTC_c4641.dir\Debug\cmTC_c4641.tlog\" wird erstellt.
InitializeBuildStatus:
"cmTC_c4641.dir\Debug\cmTC_c4641.tlog\unsuccessfulbuild" wird erstellt, da "AlwaysCreate" angegeben wurde.
C:\Program Files
(x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Clang.targets(210,5):
error : Element <DebugInformationFormat> has an invalid value of
"ProgramDatabase".
[C:\Users\marku\Desktop\build_muell\CMakeFiles\CMakeTmp\cmTC_c4641.vcxproj]
Die Erstellung des Projekts
"C:\Users\marku\Desktop\build_muell\CMakeFiles\CMakeTmp\cmTC_c4641.vcxproj"
ist abgeschlossen (Standardziele) -- FEHLER.
Fehler beim Buildvorgang.
"C:\Users\marku\Desktop\build_muell\CMakeFiles\CMakeTmp\cmTC_c4641.vcxproj"
(Standardziel) (1) ->
(ClCompile Ziel) ->
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Clang.targets(210,5): error : Element <DebugInformationFormat> has an invalid value of "ProgramDatabase". [C:\Users\marku\Desktop\build_muell\CMakeFiles\CMakeTmp\cmTC_c4641.vcxproj]
0 Warnung(en)
1 Fehler
Verstrichene Zeit 00:00:00.70
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt
Configuring incomplete, errors occurred!
See also "C:/Users/marku/Desktop/build_muell/CMakeFiles/CMakeOutput.log".
See also "C:/Users/marku/Desktop/build_muell/CMakeFiles/CMakeError.log".
Now I have no idea what the meaning of this error is or what could be causing it, aside from the fact that CMake is apparently trying to compile a test program, which fails. The "Xamarin" stuff in the error log feels particularly out of place. I already tried a couple of things to fix this problem. Originally, I was on Visual Studio 2015 Update 1 and was actually getting a different error (which I don't remember, because I didn't document it). After some Google research, I decided to install Update 2 of VS2015, hoping it could fix the problem, but it only lead to a different error, which is the one you're seeing above.
Just out of curiosity, I also took my original VS solution and tried setting the platform toolset to Clang in there. It still didn't compile, but at least it gave me a reasonable error message that actually made some sense to me (mentioning that the solution's "warning level" property had a value it didn't expect). With this error log, though, I have no idea where to even start looking for the source of the problem.
Now I could share my CMake code here, but I'm not sure if that will be helpful. The project code is split between multiple files, so sharing it is a bit complicated, and I'm also unsure if the cause of the problem can be found with the CMake files in the first place. I'm actually assuming that the cause of the problem could be unrelated to the project code itself. I tried googling for information on this error, but unfortunately everything I got were around five hits, all of which only contained that above error log with no solutions to the problem. I'm not sure where to start looking. Anyone has some experience with this and can lead me into the right direction? Please let me know if you have an idea or expect that seeing any of my code could help with finding the cause of the error.
Just to answer @jml question above in comments about Element <DebugInformationFormat> has an invalid value of "ProgramDatabase"
. You should change your compiler command line arguments. For example, DebugInformationFormat=ProgramDatabase is a /Zi option for cl compiler which is unknown for clang. For it you should use "-g2 -gdwarf-2". For exceptions cl uses /EHsc but for clang it should be -fexceptions. In my cmake file I did the following:
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 -g2 -gdwarf-2 -fexceptions")
else ()
# for cl.exe
endif ()
The easiest way to find out those options is to open properties of any project and go through settings in C++ or Linker section and watch in suggested values. Basically you can use typical linux options for clang. Also, there are some options prefixed with ms-, you can find them in the Properties of the project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With