CMake remove "Full Path of Source Code File in Diagnostics" option /FC - visual-studio

How can I instruct CMake in the CMakeLists.txt to create a Visual Studio project that does not contain the /FP option?
Thanks

TL;DR: This seems to be impossible, at the moment. You may file a bug report on the
CMake Issue Tracker.
The default setting for "Full Path of Source Code File in Diagnostics" seems to be set to enabled. In Visual Studio, if you open the project's properties and navigate to Configuration Properties -> C/C++ -> Advanced, you will find the "Use Full Paths" property, which is enabled. You may also recognize that it is printed in a non-bold font, indicating a default value. Set it to "no" and it turns bold.
Saving the project will add a line to the <project>.vcxproj file:
[...]
<ClCompile>
[...]
<UseFullPaths>false</UseFullPaths>
</ClCompile>
[...]
Obviously, CMake needs to add this line to explicitly disable the compile flag. However, from a search of the repository, we learn that there is currently no implementation to achieve this. The FC flag is mapped to nothing or to true:
[...]
{ "UseFullPaths", "FC", "", "true", 0 },
[...]
Remember, both ways indicate to turn on "Full Path of Source Code File in Diagnostics".
To Conclude: There is no implementation in CMake, which allows to explicitly disable this flag. You have to write a post process script to change the <project>.vcxproj file accordingly.

Related

How to turn off a project for Debug config in CMake-generated Visual Studio solution

Right-click on the solution title in the Solution Explorer window, then go to Configuration Properties -> Configuration. The table appears, showing check-boxes, allowing to turn off/on a build of particular projects for certain configurations.
My solution and projects are generated with CMake.
Is it possible to turn off a particular project for Debug build configuration from CMakeLists.txt?
==
Background of a problem is failing build of Cython project for Debug config.
Release builds fine. CMake module was taken from this example on Github.
Debug config wants debug Python library python27_d.lib, that is forced by pyconfig.h. I use Anaconda python, which is missing this library.
Moreover, I don't need debug build of that project. I've unsuccessfully spent several hours, modifying CMakeLists.txt in various ways, trying to remove definition of _DEBUG macro from compiler command line. CLI parameter /D_DEBUG was absent in all dialogs with properties and "complete command line" listings, that Visual Studio has shown me. Nevertheless, something has always appended it.
So, I'd like to simply disable this project in Debug build for now.
This sets that check-box from the first part of the question to unchecked state:
set_property(TARGET <my Cython module>
PROPERTY EXCLUDE_FROM_DEFAULT_BUILD_DEBUG TRUE)
Now I wonder, where did compiler command line come from, because /D_DEBUG was absent in all dialogs with properties, that Visual Studio has shown me (second part of the question).
I am building this project in VS2013. Initially, that string /D_DEBUG was present in Project properties -> C/C++ -> Preprocessor -> Preprocessor definitions for the Debug configuration. Then I've added
string(REPLACE "/D_DEBUG" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
to my CMakeLists.txt file, building the Cython code, and that macro has disappeared from the Project properties.
Nevertheless, the project was still requiring python27_d.dll.
I've also added
#define _DEBUG
in one of files, and have got the following compiler warning
C:\projects\project\file.cpp(9): warning C4005: '_DEBUG' : macro redefinition
command-line arguments : see previous definition of '_DEBUG'

Where does VS save an environment variable like $(outdir)?

Where does Visual Studio save an environment variable like "$(OutDir)"?
I don't see anything resembling "OutDir" in the command line.
Assuming you changed the "Output Directory" setting of your project, it is stored in the project's .vcxproj file. Just try it, change the setting, save the project and have a look-see with a text editor:
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>Example</OutDir>
</PropertyGroup>
I changed the setting to "Example".
If you did not change the setting then MSBuild computes the value of the property (aka macro). Pretty visible from the IDE, it glues the values of $(SolutionDir) and $(Configuration) together.
Those properties in turn are set by the IDE, based on the platform target and the configuration you have selected in the Build > Configuration Manager dialog. If you build from the command line then you use MSBuild's /property option to select what you want to build.
Note how the environment plays no role at all. If you need an environment variable because you are running some other kind of build tool then you'd do so by using the SET command in a pre- or post-build event. Like:
SET outdir="$(OutDir)"
Using double-quotes to avoid trouble with pathnames that contain a space.
Why are you assuming they're saved? They're not; they exist solely within the build process
these ar basically macros ; you can find the output directory in : Properties->General->Output Directory
For more info check this

Missing header files for VTK

I installed Visual Studio 2010, Qt and Cmake. I configured them. Then I wanted to test by an example code. However, the program cannot find the header files. I searched on the internet and found that there might be a problem with the PATH.
Then, I followed this way that results in failure:
I wrote each folder name separately by putting semicolon between them to
Project > Properties > C/C++ > General > Additional Include Directories.
In this way, program found the header files but it gave me an error LNK1104. I think it happened because the Path for file name expands to more than 260 characters. I learned that from this site.
I tried to find one folder that I can write to PATH. I think it's lib file. But I could not find it.
what should I do to fix this problem?
Setting two values in visual studio will remove this error.
Go to Properties of the project -> C/C++ -> All Options -> Set the correct value for "Additional Options".
Go to Properties of the project -> Linker -> Input -> Set correct the value for "Additional Dependencies".
If you create the project using CMake, then these values will be setup automatically.

warning MSB8012 : make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile)

I am getting the following error when building my code.
C:\Program Files
(x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(990,5):
warning MSB8012:
TargetPath(E:\Study\FWIF\demola\ext-libs\libcommoncpp2-1.6.0\w32\Debug\ccgnu2.dll)
does not match the Linker's OutputFile property value
g\CapeCommon14.dll). This may cause your project to build incorrectly.
To correct this, please make sure that $(OutDir), $(TargetName) and
$(TargetExt) property values match the value specified in
%(Link.OutputFile).
I hope that some one will know what to do.
Did you upgrade a project to Visual Studio 2010 from a previous version? If so, this is a well-known issue.
Visual Studio 2010 C++ Project Upgrade Guide
http://blogs.msdn.com/b/vcblog/archive/2010/03/02/visual-studio-2010-c-project-upgrade-guide.aspx
Warnings during upgrade
Here are some of the common warnings that you may run into during conversion:
1) Linker output directory
One of the warnings you may see when upgrading you applications is MSB8012: $(TargetPath) and Linker’s OutputFile property value does not match:
MSB8012: $(TargetExt) ('.dll') does not match the Linker's OutputFile property value 'C:\foo\Debug\MFCActiveX.ocx' ('.ocx') in project configuration 'Debug|Win32'. This may cause your project to build incorrectly. To correct this, please make sure that $(TargetExt) property value matches the value specified in %(Link.OutputFile).
MSB8012: $(TargetPath) ('C:\foo\Debug\MFCActiveX.dll') does not match the Linker's OutputFile property value 'C:\foo\Debug\MFCActiveX.ocx' ('C:\foo\Debug\MFCActiveX.ocx') in project configuration 'Debug|Win32'. This may cause your project to build incorrectly. To correct this, please make sure that $(TargetPath) property value matches the value specified in %(Link.OutputFile).
Link.OutputFile is the value defined at Linker -> General -> Output File on the property page. By default, its value is $(OutDir)$(TargetName)$(TargetExt), which is the same as the value of $(TargetPath). When we convert an application from a previous version, however, there is not an easy way for conversion to parse Link.OutputFile to figure out what exactly the values are for $(TargetName) and $(TargetExt), as different customers may have formatted them in different ways. To work around that, we decided to preserve the value of Linker.OutputFile during conversion. After conversion, $(TargetName) will default to $(ProjectName). $(TargetExt) will default to the default extension for the application type: .dll for Dynamic Library, .lib for Static Library and .exe for Application. Link.OutputFile value will be preserved. Warning MSB8012 will be issued in the conversion log if Link.OutputFile and $(TargetPath) are not the same. You will get the same warnings when building the application.
$(OutDir), $(TargetName) and $(TargetExt) are exposed on the "General" property page, as "Output Directory", "Target Name", "Target Extension", respectively. You can manually change the values of these properties so that you no longer get the warning.
If your project produces Import Library (Linker -> Advanced -> Import Library), you may need to change the Output folder of the Import Library as well after conversion if the Linker output directory is not the default output directory. Otherwise, the generated import lib maybe in a different directory than the linker output.
Debugging.Command is set to default $(TargetPath) after conversion. You may need to make changes so that the right executable will be launched upon F5 (Debugging) or Ctrl + F5 (Start without debugging).
See also here Stackoverflow MSB8012.
What worked for me when converting a VS2008 C++ project to VS2012: right click the project in solution explorer, select properties, in the pop-up: configuration properties, linker, general. Select Output file on the right, this gives a drop-down, select inherent from parent or project defaults. Click apply. This gives the default linker setting: $(OutDir)$(TargetName)$(TargetExt). Re-build the project and the warning should no longer appear.
The same problem occured to me for debug DLLs, that I wanted to have a trailing "D" in the basename. For example, foo.dll (Release) but fooD.dll (Debug). When you refine the output name in the Linker settings of the Debug-Configuration -- the ugly MSB8012 warning occurs.
The only solution that works with Visual-Studio 2010 seems to be a Postbuild-Event for the Debug-Configuration:
#echo off
echo Copying $(OutDir)$(TargetName)$(TargetExt) as $(TargetName)D$(TargetExt)
copy /Y $(OutDir)$(TargetName)$(TargetExt) $(OutDir)$(TargetName)D$(TargetExt)
I had the scenario where my executable name was different than the project name AND I wanted it to build the executable/dll to a different location than where the project was located.
1)Change the default project name to be different.
General->TargetName
< my executable name>
2) Output to a different location where I want the executable to build.
General->OutputDirectory
< my new location goes here >
3) Update the Linker settings.
Linker->General
new value: $(OutDir)$(TargetName)$(TargetExt)
This takes on the new settings from 1 and 2.
I obtained the same error after converting from old project to VS 2010.
To fix this I created empty project of the same type (e.g. .dll, .lib, .exe).
Then I copied its default values in Project Propeties to my project for Output Directory, Intermediate directory and Output File
Goto Project->Properties->Configuration Properties -> Linker->General section
Specify 'Output File' as $(OutDir)$(TargetName)$(TargetExt)
I managed to fix a similar issue by editing the vcxproj file manually.
The OutDir and TargetName settings were at the bottom of the project file.
...
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(OUTPUT_DIRECTORY)\</OutDir>
<IntDir>$(ProjectDir)\$(Configuration)\$(ProjectName)\</IntDir>
<TargetName>$(ProjectName)</TargetName>
</PropertyGroup>
</Project>
Moving the block above the ClCompile block solved the issue.
I solved this by comparing the project to a very similar project that was working properly. All of the settings in the project properties matched but I found the following extra lines in the vcxproj file of the malfunctioning project:
<Lib>
<OutputFile>.\MCtlDrvX.lib</OutputFile>
</Lib>
I deleted them and the message went away and the output went to the directory specified in the project settings.

How do I set a path in Visual Studio?

How do I set a path for DLL files to be searched in Visual Studio for a particular project alone?
Now I am setting it in the environment path variable, but I would like better control over this.
Search MSDN for "How to: Set Environment Variables for Projects". (It's Project>Properties>Configuration Properties>Debugging "Environment" and "Merge Environment" properties for those who are in a rush.)
The syntax is NAME=VALUE and macros can be used (for example, $(OutDir)).
For example, to prepend C:\Windows\Temp to the PATH:
PATH=C:\WINDOWS\Temp;%PATH%
Similarly, to append $(TargetDir)\DLLS to the PATH:
PATH=%PATH%;$(TargetDir)\DLLS
You have a couple of options:
You can add the path to the DLLs to the Executable files settings under Tools > Options > Projects and Solutions > VC++ Directories (but only for building, for executing or debugging here)
You can add them in your global PATH environment variable
You can start Visual Studio using a batch file as I described here and manipulate the path in that one
You can copy the DLLs into the executable file's directory :-)
If you only need to add one path per configuration (debug/release), you could set the debug command working directory:
Project | Properties | Select Configuration | Configuration Properties
| Debugging | Working directory
Repeat for each project configuration.
Set the PATH variable, like you're doing. If you're running the program from the IDE, you can modify environment variables by adjusting the Debugging options in the project properties.
If the DLLs are named such that you don't need different paths for the different configuration types, you can add the path to the system PATH variable or to Visual Studio's global one in Tools | Options.
None of the answers solved exactly my problem (the solution file I was running was trying to find xcopy to copy a dll after generation).
What solved it for me was going into menu "Project -> Properties"
Then in the window that opens choosing on the left pane: "Configuration Properties -> VC++ Directories
On the right pane under "General" choosing "Executable Directories "
And then adding:
$(SystemRoot)\system32;$(SystemRoot);$(SystemRoot)\System32\Wbem;$(SystemRoot)\System32\WindowsPowerShell\v1.0\;$(ExecutablePath)

Resources