View Issue Details [ Jump to Notes ] | [ Print ] | ||||||||
ID | Project | Category | View Status | Date Submitted | Last Update | ||||
0014052 | CMake | CMake | public | 2013-03-31 11:57 | 2016-06-10 14:31 | ||||
Reporter | alecool | ||||||||
Assigned To | Kitware Robot | ||||||||
Priority | normal | Severity | major | Reproducibility | always | ||||
Status | closed | Resolution | moved | ||||||
Platform | PC | OS | Windows | OS Version | 7 64 bit | ||||
Product Version | CMake 2.8.10.2 | ||||||||
Target Version | Fixed in Version | ||||||||
Summary | 0014052: 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. | ||||||||
Tags | No tags attached. | ||||||||
Attached Files | |||||||||
Relationships | |
Relationships |
Notes | |
(0032732) Eric NOULARD (developer) 2013-03-31 14:29 |
AIFAIK this is not a bug, this is the way it works in CMake for ages. Setting MSVC before project(Blah C) does not seem possible because (cmake --help-variable MSVC) MSVC True when using Microsoft Visual C and no C compiler is searched by CMake before the C language is enabled: 1) by project(Blah C) or project(Blah) (which enables C and CXX by default) 2) by enable enable_language(C) I shall add that "asking" for a generator on the command line/GUI does not make it available so that MVSC will be set as soon as C - language is enabled AND some MS C compiler is found. I mean you may ask for "Visual Studio 11" but CMake may not be able to find the corresponding compiler. Then regarding your test. you should always try from a pristine build directory, I think (but I may be wrong) that in your case you did not delete the cache and/or use a pristine build dir so that the value of MSVC may be cached from the previous run. |
(0032733) alecool (reporter) 2013-03-31 17:06 |
I did clean my cache between every try at running the project generation. I felt that "it's the way it works" would be the answer i'd get. Anyway, it seems that when not having a project() command (nor enable_language()), the language is determined before everything : in the second try of the bug report, when no project() is used, the two test sequences are displayed consecutively, both after compiler identification ; whereas in the first try (using project()), I get the first test sequence, then the identification of the compiler, then the second test sequence. In my case (where I found out about this behavior), I tried to detect boost using find_package, which would fail when the find_package command is called before the project command. Having such strong behavior implications on a command that "sets the name of the project" is a bit counter-intuitive. I wonder why cmake would be able to detect the presence of the compiler first-off when there is no project() command, and would need to wait to proceed that command when it is used in the script. |
(0032734) Brad King (manager) 2013-04-01 08:04 |
Re 0014052:0032733: A project() command is required (exactly to detect system/compiler info) so if there isn't one CMake inserts one implicitly on line 0 of the top-level CMakeLists.txt file. |
(0042258) Kitware Robot (administrator) 2016-06-10 14:28 |
Resolving issue as `moved`. 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. |
Notes |
Issue History | |||
Date Modified | Username | Field | Change |
2013-03-31 11:57 | alecool | New Issue | |
2013-03-31 14:29 | Eric NOULARD | Note Added: 0032732 | |
2013-03-31 17:06 | alecool | Note Added: 0032733 | |
2013-04-01 08:04 | Brad King | Note Added: 0032734 | |
2016-06-10 14:28 | Kitware Robot | Note Added: 0042258 | |
2016-06-10 14:28 | Kitware Robot | Status | new => resolved |
2016-06-10 14:28 | Kitware Robot | Resolution | open => moved |
2016-06-10 14:28 | Kitware Robot | Assigned To | => Kitware Robot |
2016-06-10 14:31 | Kitware Robot | Status | resolved => closed |
Issue History |
Copyright © 2000 - 2018 MantisBT Team |