vcproj files for Visual Studio contain various settings or properties which affect the build. For instance, a few of the ones that a project that I'm trying to convert to cmake uses are
StringPooling="true"
RuntimeLibrary="2"
TreatWChar_tAsBuiltInType="true"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
There are of course plenty of others that could be set. The question is how to set them when the project is generated using cmake. Does anyone have any idea how to set these sort of properties when using cmake other than editing the vcproj file after the fact? I can't find anything explaining how these sort of properties might be set via cmake. The only ones that I know how to set are ones that cmake specifically has cross-platform stuff for (e.g. PreprocessorDefinitions
or AdditionalIncludeDirectories
). But I need to be able to set ones that are specific to Visual Studio.
For the flags you've listed, you'd add the following to your CMakeLists.txt:
You can group these in one call if you want:
If you only need to add a flag to a single target (say,
MyTestExe
), you can do:Options set via this target-specific method will override any conflicting ones in the general
CMAKE_CXX_FLAGS
variable.For further info on these commands do:
cmake --help-variable "CMAKE_<LANG>_FLAGS_DEBUG"
cmake --help-command set_target_properties
cmake --help-property COMPILE_FLAGS
The Visual Studio compiler options are listed here.
Each of these properties corresponds to a command-line option of the compiler (
cl
). You set these command line options in your CMakeList (using variables likeCMAKE_CXX_FLAGS
, commands likeadd_definitions()
and properties likeCOMPILE_FLAGS
) and CMake automatically translates them to the settings in .vc[x]proj files when generating them. Those it does not understand are just added as "Additional command-line options".