How to make CMake generated INSTALL be generated when selecting "Build solution" - visual-studio

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 ..

Related

Use CMake to set Debugging->Environment string for Visual Studio project

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()

Select MSVS build configuration when generating a buildsystem with CMake

I have a multiplatform CMake project, and occasionally I have to build it manually for Windows. I generate a buildsystem like this:
cmake -DCMAKE_BUILD_TYPE=Release -G"Visual Studio 16 2019" -A x64 ../path/to/source
Then I open *sln file and press F7 to build. It runs for 40 minutes, and after that I understand that I didn't select proper configuration in the combobox. It's annoying! When command line option was -DCMAKE_BUILD_TYPE=Release, but combobox was set to Debug, build fails after spending a decent time.
Is it possible to generate an MSVS project with build configuration selected from command line?
Note that I'm aware of msbuild command and it's -p:Configuration=xxxxx flag. The question is about cases when for some reason you need to build from Visual Studio's GUI.
Changing the selected configuration for the GUI is not possible with CMake at this moment.
The main reason for this is that this information is stored in the .suo file generated by Visual Studio. CMake itself only generates the project and solution files, while the .suo file will be generated by Visual Studio itself.
Alternatively, use CMake's command line build option for this. After configuring your project and generating the VS .sln file from CMake as usual, simply run:
cmake --build <path_to_build_directory> --config Release
This works independently of the selected generator and is the most reliable way of building CMake projects.

how to send visual studio configuration options from cmake

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

FreeGLUT 3.0.0 Visual Studio solution?

Where is the Visual Studio solution for FreeGLUT 3.0.0? I know the 2.8.1 has one, but 3.0.0 does not. I would really like to use the latest version.
Use the included CMakeLists.txt to create a Visual Studio solution:
How to build freeglut with CMake on Windows (MS Visual Studio)
Download CMake (http://www.cmake.org/cmake/resources/software.html).
Get one of the releases from the binary distribution section.
Run the CMake installer, install wherever you like.
Launch CMake via Start > Program Files > CMake 2.8 > CMake (GUI)
(note that the shortcut put by the installer on your desktop does NOT
point to the CMake GUI program!)
In the "Where is the source code" box, type or browse to the root
directory of your freeglut source (so that's /freeglut, not
/freeglut/src).
In the "Where to build the binaries" box, type or browse to any
folder you like - this will be where the Visual Studio solution will be
generated. This folder does not have to exist yet.
Hit the Configure button near the bottom of the window.
Pick your target compiler, make sure that its installed on your
system of course!
Answer Ok when asked if you want to create the build directory.
Wait for the configure process to finish.
The screen will now have some configuration options on it, for
instance specifying whether you want to build static and/or shared
libraries (see below for a complete list). When you've selected your
options, click the Configure button again.
The Generate button at the bottom will now be enabled. Click Generate.
The build files will now be generated in the location you picked.
You can now navigate to the build directory you specified in step 5.
Open the freeglut.sln file that was generated in your build directory,
and compile as usual

How to set project properties of visual studio 2013 using cmake?

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\">")

Resources