MantisBT - CMake
View Issue Details
0015917CMakeCMakepublic2016-01-13 18:162016-06-10 14:21
Daniel Williams 
 
normalmajoralways
closedno change required 
Win64Windows 7sp1
CMake 3.4.1 
 
0015917: Visual Studio project files generated incorrectly
Executables are incorrectly flagged as Application executables (i.e. to use winMain) instead of utility / console executables (and use the normal main)

when cmake is generating solution (.sln) and project (.vcxproj) files for Visual Studio, it cannot set the flags correctly. The generator creates:
    <ConfigurationType>Application</ConfigurationType>

Instead of:
    <ConfigurationType>Utility</ConfigurationType>

This in turn causes compile-time Link Errors

As it should. This is controlled by a flag on the executable. (or so says the documentation):
[1]https://cmake.org/cmake/help/v3.4/command/add_executable.html [^]
[2]https://cmake.org/cmake/help/v3.4/prop_tgt/WIN32_EXECUTABLE.html [^]




1) create empty project with supplied CMakeLists.txt
2) create a minimal 'main.cpp' (contents don't matter, empty should be fine)
3) run configure ; run generate
4) inspect $BUILD_DIR/test.exe.vcxproj
   DOM: Project/PropertyGroup/ConfigurationType values will all still be set to "Application" which requires the winmain symbol be defined.

This Application tag is generated both with and without the WIN32 flag. It is only supposed to be generated *with*. (Without the flag, the 'ConfigurationType' tag should be set to 'Utility', the console exe version.)
1) Originally Reproduced as far back as CMake 3.1.2
2) the 'set_executable(...)' function correctly sets the flag, as checked by 'get_target_property(...)', but this property does not carry through to the file generation stage.
No tags attached.
txt CMakeLists.txt (278) 2016-01-13 18:16
https://public.kitware.com/Bug/file/5610/CMakeLists.txt
txt CMakeLists-15917-ng.txt (430) 2016-01-14 03:21
https://public.kitware.com/Bug/file/5612/CMakeLists-15917-ng.txt
Issue History
2016-01-13 18:16Daniel WilliamsNew Issue
2016-01-13 18:16Daniel WilliamsFile Added: CMakeLists.txt
2016-01-14 03:21Nils GladitzFile Added: CMakeLists-15917-ng.txt
2016-01-14 03:22Nils GladitzNote Added: 0040228
2016-01-14 14:24Daniel WilliamsNote Added: 0040245
2016-01-14 14:45Nils GladitzStatusnew => resolved
2016-01-14 14:45Nils GladitzResolutionopen => no change required
2016-01-14 14:45Nils GladitzAssigned To => Nils Gladitz
2016-01-14 14:45Brad KingAssigned ToNils Gladitz =>
2016-06-10 14:21Kitware RobotNote Added: 0041287
2016-06-10 14:21Kitware RobotStatusresolved => closed

Notes
(0040228)
Nils Gladitz   
2016-01-14 03:22   
The distinction is not made through <ConfigurationType>.

GUI/Windows (WinMain) applications use:
    <SubSystem>Windows</SubSystem>

While console (main) applications use:
    <SubSystem>Console</SubSystem>

I attached a self-contained working example for both (CMakeLists-15917-ng.txt; rename to CMakeLists.txt).
(0040245)
Daniel Williams   
2016-01-14 14:24   
Understood.

I show adding the WIN32 tag to change the tag in the vcxproj as intended.

And I tracked down the error to a badly-configured dependency, (which exhibited the same link error symptom).

Therefore, I vote to close this issue as resolved.
(0041287)
Kitware Robot   
2016-06-10 14:21   
This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.