MantisBT - CMake
View Issue Details
0014269CMakeCMakepublic2013-07-03 12:562013-12-02 08:51
dbcfd 
Brad King 
normalminoralways
closedfixed 
CMake 2.8.11.1 
CMake 2.8.12CMake 2.8.12 
0014269: CMAKE_CONFIGURATION_TYPES does not work with Visual Studio
CMAKE_CONFIGURATION_TYPES cannot be set to work with Visual Studio (possibly other multi configuration ides). Per 0006788, it should work by setting prior to calling project, however this does not produce the desired behavior.

Using the following CMake on a clean build:
    message("CONFIGS IS ${CMAKE_CONFIGURATION_TYPES}")
    set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE)
    message("CONFIGS IS ${CMAKE_CONFIGURATION_TYPES}")
    
    #project variables
    project(${_project} CXX)
    message("CONFIGS IS ${CMAKE_CONFIGURATION_TYPES}")
    set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE)
    message("CONFIGS IS ${CMAKE_CONFIGURATION_TYPES}")

The output will be

CONFIGS IS Debug;Release
CONFIGS IS Debug;Release
CONFIGS IS Debug;Release;MinSizeRel;RelWithDebInfo
CONFIGS IS Debug;Release

Indicating that the Project command resets the cached variable.
Modules\Platform\Windows-MSVC.cmake, line 55

if(NOT CMAKE_NO_BUILD_TYPE AND CMAKE_GENERATOR MATCHES "Visual Studio")
  set (CMAKE_NO_BUILD_TYPE 1)
  set (CMAKE_CONFIGURATION_TYPES "Debug;Release;MinSizeRel;RelWithDebInfo" CACHE STRING
     "Semicolon separated list of supported configuration types, only supports Debug, Release, MinSizeRel, and RelWithDebInfo, anything else will be ignored.")
  mark_as_advanced(CMAKE_CONFIGURATION_TYPES)
endif()

This should only set CMAKE_CONFIGURATION_TYPES if not already set:

if(NOT CMAKE_NO_BUILD_TYPE AND CMAKE_GENERATOR MATCHES "Visual Studio")
  set (CMAKE_NO_BUILD_TYPE 1)
  if(NOT CMAKE_CONFIGURATION_TYPES)
     set (CMAKE_CONFIGURATION_TYPES "Debug;Release;MinSizeRel;RelWithDebInfo" CACHE STRING
     "Semicolon separated list of supported configuration types, only supports Debug, Release, MinSizeRel, and RelWithDebInfo, anything else will be ignored.")
  endif()
  mark_as_advanced(CMAKE_CONFIGURATION_TYPES)
endif()

No tags attached.
zip Reproduce.zip (813) 2013-07-03 14:33
https://public.kitware.com/Bug/file/4811/Reproduce.zip
Issue History
2013-07-03 12:56dbcfdNew Issue
2013-07-03 13:06dbcfdNote Added: 0033466
2013-07-03 14:33dbcfdFile Added: Reproduce.zip
2013-07-03 14:34dbcfdNote Added: 0033469
2013-07-03 15:03dbcfdNote Added: 0033471
2013-07-03 16:26Brad KingNote Added: 0033474
2013-07-03 16:53Brad KingNote Added: 0033477
2013-07-03 16:53Brad KingAssigned To => Brad King
2013-07-03 16:53Brad KingStatusnew => resolved
2013-07-03 16:53Brad KingResolutionopen => fixed
2013-07-03 16:53Brad KingFixed in Version => CMake 2.8.12
2013-07-03 16:53Brad KingTarget Version => CMake 2.8.12
2013-07-03 17:06dbcfdNote Added: 0033478
2013-07-03 17:06dbcfdStatusresolved => feedback
2013-07-03 17:06dbcfdResolutionfixed => reopened
2013-07-03 18:46dbcfdNote Added: 0033481
2013-07-03 18:46dbcfdStatusfeedback => assigned
2013-07-08 08:30Brad KingNote Added: 0033498
2013-07-08 08:30Brad KingStatusassigned => resolved
2013-07-08 08:30Brad KingResolutionreopened => fixed
2013-12-02 08:51Robert MaynardNote Added: 0034636
2013-12-02 08:51Robert MaynardStatusresolved => closed

Notes
(0033466)
dbcfd   
2013-07-03 13:06   
The additional information is possibly unneeded. It seems that cache variables cannot be set in that script, and CMAKE_CONFIGURATION_TYPES will always be unset.
(0033469)
dbcfd   
2013-07-03 14:34   
Added a set of CMake files to reproduce issue. If macro ConfigurationFixer is commented out in CMakeLists.txt, configurations will not be set properly. If macro remains in file, configurations will be set properly.
(0033471)
dbcfd   
2013-07-03 15:03   
cmMakefile.cxx, line 650

Project command is required for top level CMakeLists.txt. The pulled in file has a macro which has the project command, but since the macro is not evaluated at this time, cmake provides a project call via cmListFileCache.

By including a project call (even one that is not used, but in a macro), the project call in the included file will correctly be evaluated after the caching of the configuration types.
(0033474)
Brad King   
2013-07-03 16:26   
This may have been fixed by a recent post-2.8.11 change:

 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=42bb42d1 [^]
(0033477)
Brad King   
2013-07-03 16:53   
Re 0014269:0033474: Local testing tells me that commit 42bb42d1 fixed this issue.
(0033478)
dbcfd   
2013-07-03 17:06   
Reproduction was done using latest code in github.

The issue is where a project command is in a file pulled in by include() (which should just drop it inline). cmMakefile.cxx will then not see a project command in the top level CMakeLists.txt, and automatically add one, which will set generator types to the standard 4.

You may want to close this issue and reopen a clearer issue with the reproduction steps. I'll test setting CMAKE_CONFIGURATION_TYPES after project, which would allow the project command to be added to the main file, rather than in an included file.
(0033481)
dbcfd   
2013-07-03 18:46   
Latest code in github still has issue where calling set(CMAKE_CONFIGURATION_TYPES) after project will not produce correct configurations, either from the same CMakeLists.txt as project() or via an included macro, on the first run.

Subsequent calls to cmake will produce the correct configurations.
(0033498)
Brad King   
2013-07-08 08:30   
The issue reported mentions nothing about include()-ing the project command, and the fix linked in 0014269:0033474 does fix what is actually reported. I'm resolving this again.

However, I've also added documentation to clarify that you can't include() a file to call project():

 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=4a711687 [^]

If you *really* need to do that then try

 project(MyProjectTop NONE)

to satisfy CMake's requirement and then include() files that call enable_language(). However, also note the enable_language() documentation:

 http://www.cmake.org/cmake/help/v2.8.11/cmake.html#command:enable_language [^]
 This command must be called on file scope (not inside a function)...

If you need further help with that approach please ask on the mailing list.
(0034636)
Robert Maynard   
2013-12-02 08:51   
Closing resolved issues that have not been updated in more than 4 months.