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()
Related
I am able to CMake build this HelloWorld example project using cmakelists.txt file and generate a visual studio project.
project(helloworld LANGUAGES C CXX)
cmake_minimum_required(VERSION 3.5)
find_package(Idlpp-cxx REQUIRED)
if (NOT TARGET CycloneDDS-CXX::ddscxx)
find_package(CycloneDDS-CXX REQUIRED)
endif()
# Convenience function, provided by the Idlpp-cxx that generates a CMake
# target for the given IDL file. The function calls Idlcpp-cxx to generate
# source files and compiles them into a library.
idl_ddscxx_generate(ddscxxHelloWorldData_lib "HelloWorldData.idl")
add_executable(ddscxxHelloworldPublisher publisher.cpp)
add_executable(ddscxxHelloworldSubscriber subscriber.cpp)
# Link both executables to idl data type library and ddscxx.
target_link_libraries(ddscxxHelloworldPublisher ddscxxHelloWorldData_lib CycloneDDS-CXX::ddscxx)
target_link_libraries(ddscxxHelloworldSubscriber ddscxxHelloWorldData_lib CycloneDDS-CXX::ddscxx)
set_property(TARGET ddscxxHelloworldPublisher PROPERTY CXX_STANDARD 11)
set_property(TARGET ddscxxHelloworldSubscriber PROPERTY CXX_STANDARD 11)
I need to create the same project without cmakelists.txt and CMake
How to do this only using visual studio? where to define those commands in CMakelists.txt in visual studio if I create an empty c++ project
I have tried this making an empty project.
I don't know how to idl_ddscxx_generate and target_link_libraries perform in VS....
idl_ddscxx_generate has to run if IDL file has changed
target_link_libraries is required if I added new source files to the project....
Make a new, empty Visual Studio project.
Copy all source files except the CMake files.
Do whatever you do in a Visual Studio project. Add files, targets, dependecies, … If you are not sure, look up what is written in the CMakeLists.txt file.
Delete all CMake files in your original project and copy your Visual Studio project files.
Add these changes (deleted CMake files, added VS project files) to your Subversion repository, maybe do this in a branch that others can test it, report back, and improve the change. Once done, merge the branch.
Probably, add step 0.: Learn how Visual Studio organizes its project. Make a tutorial, take some training.
Remark: Whatever your problem is with CMake, you missed something. But you can find this out later and revert your changes and pick up CMake up again.
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 ..
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\">")
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