[cmake-developers] [CMake 0014052]: System-specific variables are undefined before using project() command

Mantis Bug Tracker mantis at public.kitware.com
Sun Mar 31 11:57:24 EDT 2013


The following issue has been SUBMITTED. 
====================================================================== 
http://www.cmake.org/Bug/view.php?id=14052 
====================================================================== 
Reported By:                alecool
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   14052
Category:                   CMake
Reproducibility:            always
Severity:                   major
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2013-03-31 11:57 EDT
Last Modified:              2013-03-31 11:57 EDT
====================================================================== 
Summary:                    System-specific variables are undefined before using
project() command
Description: 
Using a trivial CMakeLists.txt, the MSVC variable is NOT defined when I add a
project() command. The bug is reproduced with both generators "Visual Studio 10"
and "Visual Studio 11" as well as the Win64 versions. Likewise, the MSYS
variable is undefined when using the "MSYS Makefiles" generator. These are the
only build toolsets that I cared to install on my system.

Steps to Reproduce: 
### Using the following CMakeLists.txt
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

message( INFO ${CMAKE_GENERATOR} )
if(WIN32)
	message(INFO Win32)
	if(MSVC)
	  message(INFO MSVC)
	else()
	    message(INFO not MSVC)
	endif()

	if(MSVC_IDE)
	  message(INFO MSVC_IDE)
	else()
	    message(INFO not MSVC_IDE)
	endif()
	
	if(MSYS)
	  message(INFO MSYS)
	else()
	    message(INFO not MSYS)
	endif()
else()
	message(INFO not Win32)
endif()

#Project configuration
project (test)

message( INFO ${CMAKE_GENERATOR} )
if(WIN32)
	message(INFO Win32)
	if(MSVC)
	  message(INFO MSVC)
	else()
	    message(INFO not MSVC)
	endif()

	if(MSVC_IDE)
	  message(INFO MSVC_IDE)
	else()
	    message(INFO not MSVC_IDE)
	endif()
	
	if(MSYS)
	  message(INFO MSYS)
	else()
	    message(INFO not MSYS)
	endif()
else()
	message(INFO not Win32)
endif()


I get the following output:
>cmake -G"Visual Studio 11" ..
INFOVisual Studio 11
INFOWin32
INFOnotMSVC
INFOnotMSVC_IDE
INFOnotMSYS
-- The C compiler identification is MSVC 17.0.51106.1
-- The CXX compiler identification is MSVC 17.0.51106.1
-- Check for working C compiler using: Visual Studio 11
-- Check for working C compiler using: Visual Studio 11 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 11
-- Check for working CXX compiler using: Visual Studio 11 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
INFOVisual Studio 11
INFOWin32
INFOMSVC
INFOMSVC_IDE
INFOnotMSYS
-- Configuring done
-- Generating done
-- Build files have been written to: E:/dev/cpp/test/TestCMake/VC11_x86

### Removing the project command as follows:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

message( INFO ${CMAKE_GENERATOR} )
if(WIN32)
	message(INFO Win32)
	if(MSVC)
	  message(INFO MSVC)
	else()
	    message(INFO not MSVC)
	endif()

	if(MSVC_IDE)
	  message(INFO MSVC_IDE)
	else()
	    message(INFO not MSVC_IDE)
	endif()
	
	if(MSYS)
	  message(INFO MSYS)
	else()
	    message(INFO not MSYS)
	endif()
else()
	message(INFO not Win32)
endif()

#Project configuration
# project (test)

message( INFO ${CMAKE_GENERATOR} )
if(WIN32)
	message(INFO Win32)
	if(MSVC)
	  message(INFO MSVC)
	else()
	    message(INFO not MSVC)
	endif()

	if(MSVC_IDE)
	  message(INFO MSVC_IDE)
	else()
	    message(INFO not MSVC_IDE)
	endif()
	
	if(MSYS)
	  message(INFO MSYS)
	else()
	    message(INFO not MSYS)
	endif()
else()
	message(INFO not Win32)
endif()

I get the following output, which was expected with the previous CMakeLists.txt
>cmake -G"Visual Studio 11" ..
-- The C compiler identification is MSVC 17.0.51106.1
-- The CXX compiler identification is MSVC 17.0.51106.1
-- Check for working C compiler using: Visual Studio 11
-- Check for working C compiler using: Visual Studio 11 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 11
-- Check for working CXX compiler using: Visual Studio 11 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
INFOVisual Studio 11
INFOWin32
INFOMSVC
INFOMSVC_IDE
INFOnotMSYS
INFOVisual Studio 11
INFOWin32
INFOMSVC
INFOMSVC_IDE
INFOnotMSYS
-- Configuring done
-- Generating done
-- Build files have been written to: E:/dev/cpp/test/TestCMake/VC11_x86

Additional Information: 
We observe that depending on the presence and the position of the project()
command, the behavior of code dependent on the definition of system-specific
variables can change a great deal. I couldn't find any documentation whether
this is known and specified behavior, and it seems a bit counter-intuitive that
a command documented as "Setting a name for the entire project" would influence
the behavior of a cmake script that much.
====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2013-03-31 11:57 alecool        New Issue                                    
======================================================================




More information about the cmake-developers mailing list