Correct usuage of target_compile_option MP for Visual Studio

According to the documents for MP in the MSVC website MP takes an optional digit to limit the number of parallel compilation units a single target will generate at a time. I wanted to always turn on MP for my users, but allow them to optionally limit the number of threads by using a variable in the cache. So in my bigger libraries we automatically include the following.

target_compile_options(libbiogears_cdm PRIVATE $<$<PLATFORM_ID:Windows>:/bigobj>  PRIVATE $<$<PLATFORM_ID:Windows>:/MP${Biogears_BUILD_PARALLEL_LEVEL}>)

The problem I have is that while hard coding a number like /MP5 seems to work the following code seems to just ignore the limiter when it is present and just use all available threading. The second thing I don’t understand is where to look up in the MSVC UI if the correct flag is being sent. When I run the following code. The Properties page C++ -> Multi-processor Compilation has a value of yes, but there is no place for the GUI to report the value of the limiter and when I look at the compiler flags C++->Command Line MP is the first option but has no parameter

/MP /GS /W3 /Zc:wchar_t /I"D:\remotes\sed-stash\core\worktrees\libpy\projects\biogears\libBiogears\include" /I"D:\remotes\sed-stash\core\worktrees\libpy\projects\biogears\libBiogears\src" /I"D:\remotes\sed-stash\core\worktrees\libpy\build-msvc16\projects\biogears" /I"D:\remotes\sed-stash\core\worktrees\libpy\build-msvc16\projects\biogears-common" /I"D:\remotes\sed-stash\core\worktrees\libpy\projects\biogears-common\include" /I"D:\remotes\sed-stash\core\worktrees\libpy\projects\biogears\libCDM\include" /I"D:\remotes\sed-stash\external\windows-vc16-amd64\include\eigen3" /I"D:\remotes\sed-stash\external\windows-vc16-amd64\include" /Gm- /O2 /Ob2 /Fd"D:\remotes\sed-stash\core\worktrees\libpy\build-msvc16\outputs\Release\bin\libbiogears.pdb" /Zc:inline /fp:precise /D "WIN32" /D "_WINDOWS" /D "NDEBUG" /D "_SCL_SECURE_NO_WARNINGS" /D "_CRT_SECURE_NO_WARNINGS" /D "NOMINMAX" /D "BIOGEARS_THROW_READONLY_EXCEPTIONS" /D "BIOGEARS_THROW_NAN_EXCEPTIONS" /D "LOG4CPP_HAS_DLL" /D "BIOGEARS_COMMON_BUILD_STATIC" /D "CMAKE_INTDIR=\"Release\"" /D "biogears_EXPORTS" /D "_WINDLL" /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /GR /Gd /MD /std:c++14 /Fa"libbiogears.dir\Release\" /EHsc /nologo /Fo"libbiogears.dir\Release\" /Fp"libbiogears.dir\Release\libbiogears.pch" /diagnostics:column 

To further complicate this if I replace ${Biogears_BUILD_PARALLEL_LEVEL} with 5 then after a regeneration step the UI looks the same but the task manager clearly shows only 5 files being compiled at a time. So, I have two questions.

  1. Should the variable expansion in a generator expression work as in the above code?
  2. Does anyone know what file or where in the UI can confirm the MP limit if one is given to speed up debugging of the issue?

From the docs:

The /MP option can reduce the total time to compile the source files on the command line. The /MP option causes the compiler to create one or more copies of itself, each in a separate process. Then these copies simultaneously compile the source files. Consequently, the total time to build the source files can be significantly reduced.

Syntax

/MP[processMax]

Arguments

processMax
(Optional) The maximum number of processes that the compiler can create.

The processMax argument must range from 1 through 65536. Otherwise, the compiler issues warning message D9014, ignores the processMax argument, and assumes the maximum number of processes is 1.

If you omit the processMax argument, the compiler retrieves the number of effective processors on your computer from the operating system, and creates a process for each processor.

  1. Yes, it should work. But note that the expansion will happen immediately, i.e. at configure time when the generator expression is defined, not at generate time when it’s epxanded & used. So the variable must be set correctly at the time the target_compile_options() call happens. I would double-check that the variable holds what you think it does at that point.

  2. I can confirm I can’t see the number anywhere in the UI either. However, it’s present in the generated .vcxproj in a <ProcessorNumber> element, so you can check that using a text editor or XML viewer.

Thanks, I’ll review the proj file for that field and see what is going on. I did not know a out the other control variable now I have to figure out which I actually want. I have found MP almost linearly scales so I think that’s right, but I’ll test the other as well

Awsome responses.