The following issue has been SUBMITTED. ====================================================================== https://public.kitware.com/Bug/view.php?id=16054 ====================================================================== Reported By: Daniel Richard G. Assigned To: ====================================================================== Project: CMake Issue ID: 16054 Category: CMake Reproducibility: always Severity: major Priority: normal Status: new ====================================================================== Date Submitted: 2016-04-07 16:53 EDT Last Modified: 2016-04-07 16:53 EDT ====================================================================== Summary: Cannot override CMAKE_{C,CXX}_FLAGS* to allow compiler check to succeed Description: I am attempting to build a project on a Windows system.
The development tools on this system are set up a little differently from the norm: Because my company always builds against the static C runtime library (i.e. using the /MT flag), the dynamic C runtime (/MD) stub library is not present at all. Any attempt to link an executable/DLL that was built with /MD will fail. Now, CMake ships with /MD or /MDd in the default flags. I set my desired flags (including /MT) in CFLAGS/CXXFLAGS in the environment, start up cmake-gui, and hit "Configure". "Error in configuration process, project files may be invalid" The log window shows CMake Error at C:/.../Modules/CMakeTestCCompiler.cmake:61 (message): The C compiler "C:/.../icl.exe" is not able to compile a simple test program. Lower down, after the compiler invocation, I see icl: command line warning https://public.kitware.com/Bug/view.php?id=10121: overriding '/MT' with '/MDd' CMake's flags are concatenated to my own, and /MDd wins out. Thus the linker fails to link the program, due to that missing stub library, and CMake reports the compiler as non-functional. Okay, so I edit the CMAKE_{C,CXX}_FLAGS* variables to remove all the /MD and /MDd flags. Then I configure again. Same error. It's _still_ passing /MDd to the compiler! At this point, I don't know where that flag is coming from. I grep through the nascent build tree to see if there are any instances of it still kicking around; the only hit is in CMakeError.log. I double-check that the project source isn't at fault: nope, the flag is nowhere to be found there either. Turns out, the place where that flag is coming from is CMake's own Modules/Platform/Windows-MSVC.cmake file. If I edit the _INIT variable in there (e.g. add /Dhi_mom), then I see the result reflected in the compiler test. The bug, then, is that I have no good way of overriding those flag variables in order to allow the compiler check to succeed. (Note that CMAKE_USER_MAKE_RULES_OVERRIDE is not applicable here, because I want to override those flags as a user, not modify the project to get the same effect.) Perhaps the edited variables are used later on, when building the project, but they are certainly not used when checking the compiler. I believe this bug has gone unnoticed for so long due to this specific scenario (missing dynamic CRT stub library) being uncommon. Note that this issue is reproducible with a trivial CMake project---I used one as described at cmake.org/examples---so the original project that exhibited this bug is not at issue. Additional Information: Because I need to use my company's exact compiler/linker flags, and will be given grief by my release-engineering group if I use anything else, it would be nice to be able to set some environment variable or the like that will tell CMake not to "help" with any default flags. While I can always edit the Windows-MSVC.cmake file, that then imposes the ongoing burden of maintaining that file, merging in upstream changes, etc. My goal is to just set CFLAGS/LDFLAGS/etc. in the environment and have the tools work with that, as is the case in Unix. (Setting a CMAKE_NO_DEFAULT_FLAGS variable or the like would be a reasonable solution.) ====================================================================== Issue History Date Modified Username Field Change ====================================================================== 2016-04-07 16:53 Daniel Richard G.New Issue ====================================================================== -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers