With a command
qmake -tp vc -r
I'm generating Visual Studio .sln file and a bunch of .vcxproj files from corresponding Qt .pro file and a bunch of .pri files.
I would like those generated .vcxproj files to import my own .props file. A path to which I can provide to qmake or embed it in those .pro/.pri files.
Is it possible? If so then how?
Since by my research it seems that this can by only done by adding a custom extension (which I would have to write first...) to mkspecs...
Judging by qmake source code, it's not possible. I've looked into qmake\generators\win32\msbuild_objectmodel.cpp in both Qt4.8.5 and latest Qt5 version, and the only Property Sheets that are added by qmake are Microsoft.Cpp.*.props (of various kinds):
xml << tag("Import")
<< attrTag("Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props")
<< attrTag("Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')")
<< closetag()
<< closetag();
I have solved this problem by creating a quick Python script, that does the post-processing on the generated *.vcxproj files:
for l in fileinput.FileInput('Project.vcxproj', inplace=1):
print l,
if 'PropertySheets' in l:
print ' <Import Project="YourPropertySheets.props" />'
Of course, it would be better to patch the qmake with the new functionality, but since there are only three people including you and me that are bothered with this, I believe the hack to be the optimal solution.
Related
I'm trying to use CMake to add an entire directory structure to my Visual Studio project. I know it is possible in VS because I already succeed by manually copying the root folder of the structure in the same directory of the project and by selecting "Include in Project". However, I'm not sure that it would be possible with CMake.
My .vcxproj contains this ItemGroup after this manual operation:
<ItemGroup>
<Text Include="asd\test.txt" />
<Text Include="asd\asd2\test.txt" />
</ItemGroup>
As you can see I just added two folders and two txt files. This produces the result I'm trying to achieve.
Any idea on how to generate this with CMake?
CMake is meant to hide the details of the build/OS environment from the user. This requires some generalization across platforms/environments. So it's difficult to get an exact copy of a manual made .vcxproj project.
You can add any files to CMake targets - explicitly including none-source files - that will then be added by CMake to generated IDE projects.
If I understand your particular case correctly the problem is to get Text instead of None tool name in ItemGroup source file's listing.
Since CMake version 3.7 you can use VS_TOOL_OVERRIDE source files property to override CMake's default for non-source files.
The following small example:
cmake_minimum_required(VERSION 3.7)
project(HelloWorld)
file(WRITE main.cpp [=[
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
}
]=])
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/asd/test.txt" "")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/asd/asd2/test.txt" "")
add_executable(HelloWorld "main.cpp" "asd/test.txt" "asd/asd2/test.txt")
set_source_files_properties(
"asd/test.txt"
"asd/asd2/test.txt"
PROPERTIES VS_TOOL_OVERRIDE "Text"
)
Does give your expected results. CMake just generates absolute paths by default.
Reference
C++ CMake (add non-built files)
I'm generating Visual Studio 2013 projects with Qt 5.3 qmake. In my .pro file, I've got the following line:
MOC_DIR = $$BUILD_DIR/<DEBUG OR RELEASE>/moc
If I message($$MOC_DIR), the path is correctly formed. However, when I build in VS, the moc_<CLASS>.cpp files are not generated in that location, but instead end up in the same directory as the .pro. I get the following warning during compilation:
Two or more files with the name of moc_<CLASS>.cpp will produce outputs to the same location
That's not surprising, because if I look at the contents of the generated .vcxproj, I see the following (irrelevant tags/text elided ...):
<CustomBuild Include="..\include\Class.hpp">
...
<Outputs Condition="...Release...">moc_Class.cpp;%(Outputs)</Outputs>
...
<Outputs Condition="...Debug...">moc_Class.cpp;%(Outputs)</Outputs>
...
</CustomBuild>
Why does is my custom MOC_DIR being ignored?
Other VS2013 projects generated with Qt5 qmake were placing the moc_<CLASS>.cpp files in the specified location, as expected, so my suspicion was that something else in the .pro was interfering.
I'm using Boost (1.55) and while adding Boost to the project, I came across the issue described in this SO question: link.
I added the following lines to the top of my .pro:
load(moc)
QMAKE_MOC += -DBOOST_MPL_IF_HPP_INCLUDED
... and that sorted out my macro argument mismatch bug. It also caused the bug described here. Calling load(moc) before setting MOC_DIR for some reason causes qmake to ignore the custom MOC_DIR. If you reorder load(moc) to be after MOC_DIR is set, everything works as expected.
My .vcxproj now looks as it should, my moc_<CLASS>.cpp files now placed into the correct <BUILD>/debug/moc or <BUILD>/release/moc directories.
However: I still get the same MSB8027 build warnings. This appears to be a known bug in Visual Studio. It confuses the situation, though, as I only broke the moc locations when I added load(moc), but I got the warning before the problem was introduced, while it existed, and now even after it's fixed! For now I'm disabling the warning; see Felix Huang's answer here.
I'm about to start doing some benchmarking/testing of our builds, and I'd like to drive the whole thing from a command line. I am aware of DevEnv but am not convinced it can do what I want.
If I could have a single file built within a single project, I'd be happy.
Can this be done?
The magical incantation is as follows. Note that this has only been tested with VS 2010 - I have heard this is the first version of Visual Studio with this capability:
The Incantation
<msbuild> <project> <settings> <file>
Where
msbuild is a path to MSBuild.exe. Usually this should be set up for you by the VS2010 bat file so the right one will end up in your PATH, but if not I found one at C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe
project is the path to the vcxproj file within which your source file resides.
settings include the following:
/p:Configuration="Debug" // or whatever your Configuration is
/p:Platform=x64 // or x86
/t:ClCompile // to specify specifically you're looking to compile the file
file is actually another setting:
/p:SelectedFiles="path_to_file"
Notes
For <project> I had to specify a project (vcxproj) file instead of a solution (sln) file. The sln I would have used has multiple projects within it, so there would have been extra work to go that route anyhow (if it can even be done).
For the /p:Platform=x64 setting, there are several environment variables that pivot on what platform you are targeting (x64 v. x86) so make sure you set those up properly via Visual Studio's vcvarsall.bat.
Regarding path_to_file in the SelectedFiles parameter, this path must be the path as specified in the project file. If the path does not match the path used in the project file to reference the source, it doesn't seem to work.
I have a project where the source files are in source/ and some shader files in data/ (those are not compiled, but instead loaded by the code). I'd like these files to show up in my CMake-generated VS2010 project files so I can edit them comfortably. What's a good way to do this? Ideally, they'd be in a separate project, but anything that works is good.
Thanks!
I can't comment (reputation too low) but is this what you want ?
http://www.cmake.org/pipermail/cmake/2006-May/009291.html
EDIT: if the above link stops working at some time, the idea is to add the files to Visual Studio like an ordinary source file. Since the IDE has no compile tool associated with it, it will be ignored. Quoting the list's discussion:
You could add arbitrary files to a target - as long as VS has no
"automatic" rule to compile them (e.g. .cc, .cpp etc)
I am adding .html files to libraries/executable or using a dummy target e.g:
ADD_EXECUTABLE(dummy dummy.cpp
"${CMAKE_CURRENT_BINARY_DIR}/Doc/index.html")
SOURCE_GROUP command may be useful, too.
and also
I think you have to take care that they are added only to VS IDE
generator builds,
in particular NOT to makefiles.
Thus we are using something like this:
IF (CMAKE_BUILD_TOOL MATCHES "(msdev|devenv)")
ADD_EXECUTABLE( hello ${SOURCES} ${HEADER} ${DOC})
ELSE (CMAKE_BUILD_TOOL MATCHES "(msdev|devenv)")
ADD_EXECUTABLE( hello ${SOURCES} )
ENDIF (CMAKE_BUILD_TOOL MATCHES "(msdev|devenv)")
Credit to Jan Woetzel
Since I write a command line program to check cpp files, and it need lib path and include path of those cpp files.
How can I get the include and lib path info from visual studio project? Our project uses property sheets to make up those information.
It is made up from 3 distinct sources:
Tools + Options, Projects and Solutions, VC++ Directories. In turn built up from several registry keys
the settings in your .vsprops project property sheets
the settings in your .vcproj project
The first part is the hardest, you can get it by running vc\vsvarsall.bat. The .vsprops and .vcproj files are XML, easy to parse.
If you just want to find out what the command line should look like then you can get it from the buildlog.htm file, produced when building from the IDE. Or you could use vcbuild.exe on the command line to build your project from the .vcproj file. Or you could build using devenv.exe /build.
Check out the Visual Studio project files - they're typically only XML files, so you should be able to extract out whatever you need from those, really. Just a matter of understanding and parsing your XML contents in the project file, really.