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_FLAGSvariable.For further info on these commands do:
cmake --help-variable "CMAKE_<LANG>_FLAGS_DEBUG"cmake --help-command set_target_propertiescmake --help-property COMPILE_FLAGSThe Visual Studio compiler options are listed here.