In my vs2013 project file, I have "Program database file name" (from Project Properties->C/C++->Output Files) to $(IntDir)vc$(PlatformToolsetVersion).pdb.
I know how to do this manualy, but for cmake i don't know.
How can I set this property from cmake?
You can use target properties COMPILE_PDB_NAME for the name and COMPILE_PDB_OUTPUT_DIRECTORY for the directory.
If you want to use the Visual Studio variables, you can try to use it directly in the variables above. If that's not working, a fallback is always to add the corresponding compiler options. In you case /Fd:
if (MSVC)
add_compile_options("/Fd\"$(IntDir)vc$(PlatformToolsetVersion).pdb\"")
endif()
or with generator expressions:
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/Fd\"$(IntDir)vc$(PlatformToolsetVersion).pdb\">")
Related
Is there a command in CMake to set the value in Visual Studio when you right click on a project, go to Properties, then Debugging->Environment.
I like to put a string like this in that value:
PATH=C:/libs/vtk/bin/bin/$(Configuration);%PATH%
This allows me to maintain where DLLs are for a project on a project-by-project basis. Any help would be appreciated, thanks!
See Support VS_DEBUGGER_ENVIRONMENT in cmake projects.
You need to add the following CMake code fragment in your project CMakeLists.txt
if(WIN32)
set_target_properties(chebyshev_polynomials_demo
PROPERTIES VS_DEBUGGER_ENVIRONMENT "PATH=%PATH%;$<TARGET_FILE_DIR:Qt5::Core>;"
)
endif()
I use CMake to configure and generate makefiles for a Microsoft MPI project that I build and run from Visual Studio 2017. In order to run the project, I need to modify the VS solution configuration settings. Under Configuration Settings->Debugging, I want to specify "Command" and "Command Arguments" from the CMakeLists.txt. I can do this manually but I want to set it up from the CMakeLists.txt. Are there commands to do this?
CMake 3.12 introduced two new target properties for that purpose: VS_DEBUGGER_COMMAND and VS_DEBUGGER_COMMAND_ARGUMENTS. Set these properties in the following way:
set_target_properties(targetName PROPERTIES
VS_DEBUGGER_COMMAND "debug_command"
VS_DEBUGGER_COMMAND_ARGUMENTS "debug_arguments")
for anyone look for a solution on visual studio code with cmake extension, here is a solution:
change program field in launch.json to ${command:cmake.launchTargetPath},
launch.json
ref:
link
I have a Visual Studio 2015 solution generated by CMake. CMake created a "INSTALL" project that copies all the files I requested (using Cmake's install command in my CMakeLists.txt files).
This "INSTALL" project is skipped when I request a full solution build
I tried to add set_target_properties(INSTALL PROPERTIES EXCLUDE_FROM_ALL FALSE) but this reports set_target_properties Can not find target to add properties to: INSTALL.
How can I make "INSTALL" be generated by default? I'd like the checkbox surrounded in red in screenshot below to be enabled automatically:
You can use CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD:
set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
After some checking, it seems that there is a single common function that sets which projects are part of default build.
cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild
Here is the part that does the check:
const std::string propertyName =
"CMAKE_VS_INCLUDE_" + *t + "_TO_DEFAULT_BUILD";
// inspect CMAKE_VS_INCLUDE_<*t>_TO_DEFAULT_BUILD properties
So as was mentioned in Florian's answer, you should be able to use CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD as well any custom project using
set(CMAKE_VS_INCLUDE_<custom project name>_TO_DEFAULT_BUILD 1)
Moreover, the variable can be added as an option on cmake launch from command line.
For VS 2017:
cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD=ON ..
I need to generate a C++ header file that describes the compiler used.
Traditionally we used the CMake command:
configure( ${PROJECT_SOURCE_DIR}/configure.h.in ${PROJECT_BINARY_DIR}/configure.h )
which replaces all string sandwiched by "#" (for example #cxx_compiler_name#) with the value of that variable in the cmake build system.
We have been given the requirement to face out CMake, so is there something equivalent in Visual Studio. I'd like to populate the header file with some of the values in the Visual Studio macros.
You can add your configure.h.in file to the project and set a custom build for it that will run perl or sed and replace whatever needed. Don't forget to add configure.h to output files property so Visual Studio can figure out the dependencies and "build" configure.h.in before other sources that use configure.h.
I'm trying to build a basic Qt "Hello, world!" application inside Visual Studio.
I got the moc step to work (I think), but now I am at a loss as to how to fix this linker error:
1>moc_mainwindow.obj : error LNK2001: unresolved external symbol "public:
static struct QMetaObject const QMainWindow::staticMetaObject"
(?staticMetaObject#QMainWindow##2UQMetaObject##B)
I've done a lot of searching but I am at a loss.
Here are my include directories:
i:\Qt\4.6.3\include\QtCore;
i:\Qt\4.6.3\include\QtGui;
i:\Qt\4.6.3\include;
i:\Qt\4.6.3\include\ActiveQt;
reease;
.;
i:\Qt\4.6.3\mkspecs\win32-msvc2008
Here are the libraries I am linking against:
i:\Qt\4.6.3\lib\QtGui4.lib;
i:\Qt\4.6.3\lib\QtCore4.lib;
gdi32.lib;
comdlg32.lib;
oleaut32.lib;
imm32.lib;
winmm.lib;
winspool.lib;
ws2_32.lib;
ole32.lib;
user32.lib;
advapi32.lib;
libpng.lib;
msimg32.lib;
shell32.lib;
kernel32.lib;
uuid.lib;
Does anyone have any ideas?
qmake will generate the moc voodoo from the header file in .pro file. As you aren't using qmake, by the sound of it, but a native visual studio project, this is probably the cause of the problem.
If you use qmake to generate your visual studio project all your problems will go away and life will be sweet. Probably!
I am using the open 2010.05; obviously you want to substitute the correct path for your version.
set up the environment
start 2010 command environment from the start menu
-set include=%include%;C:\Qt\2010.05\qt\include
-set lib=%lib%;C:\Qt\2010.05\qt\lib
-set path=%path%;C:\Qt\2010.05\qt\bin
-set QMAKESPEC=win32-msvc2010
write code, create files etc
generate the initial pro and makefile and fire up VS
-qmake -tp vc
-qmake
you should now have a makefile - check that it works by running:
-nmake
now launch visual studio
-VCExpress.exe /useenv
-XXX.vcxproj can now be opened
If this doesn't work you may need to build qt at against visual studio. This is very straightforward - go to the qt directory (from within the visual studio express command window) and type:
configure.exe -platform win32-msvc2010 -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-multimedia -no-qt3support -fast
You cannot install the Qt VS plugin on the Express edition of VC++. Assuming you got the moc to compile, you also need to make sure you're including the appropriate libraries (*.lib files) at link time. This goes under Project properties > Linker > Input > Additional Dependencies.
You will need qtcore4.lib at a minimum.
Also make sure the Qt library path is in your library search path. On my computer it's c:\qt\4.6.2\lib.
I was able to get QT to work with Visual C++ Express 2010 using http://rajorshi.net/blog/2009/01/using-qt-with-msvc-express-2008/ and http://portfolio.delinkx.com/files/Qt.pdf as guides. Just in case anyone still is having problems.
Have you create the visual studio project using qmake first? The problem seems to be the moc compilation. Do you have qt plug-in installed and the qt path in enviromental variables? Can you add you hello world code so I can have a look at it?
You need to add commands to generate QT metaclasses, then also include the generated files in your project as c++ code.
Generating the QT metaclasses:
First, add your QT bin path into the Executable Directory. (This is in Configuration Properties > VC++ Directories)
Add your Header files that contain Q_OBJECT macros to the project.
Multi-select your header files, then right click on a header file, click Properties.
Change "Item Type" from "C/C++ Header" to "Custom Build Tool".
Set Command line to this: moc.exe "%(FullPath)" > "$(ProjectDir)MetaObjects\moc_%(Filename).cpp"
Set Description to this: QT: Generate $(ProjectDir)MetaObjects\moc_%(Filename).cpp (optional)
Set Outputs to this: $(ProjectDir)MetaObjects\moc_%(Filename).cpp
Run Build just to make it generate the metaobject code
Add the generated C++ files from the Project Directory Metaobjects folder into your project