0

I have a cmake project and I'm using the msvc 2019 generator on windows 10.

I can successfully build with the following:

cmake -S . -B build
cd build
cmake --build . -- /m

I'm interested in passing the /m switch to msbuild.exe within the CMakeLists.txt itself.

I've tried the following without success as arguments get passed to cl.exe:

if(MSVC)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /m")
    message(STATUS "NOTICE: Setting parallel build for msbuild.exe")
    add_definitions(/M)
endif()

Also bonus question: How does -- work in the last cmake command above? I'm struggling finding documentation on it.

A M
  • 14,694
  • 5
  • 19
  • 44
David
  • 692
  • 8
  • 21
  • Does this answer your question? [How to set compiler options with CMake in Visual Studio 2017](https://stackoverflow.com/questions/45995784/how-to-set-compiler-options-with-cmake-in-visual-studio-2017) – GAVD Nov 03 '22 at 03:21
  • @GAVD No, I need to set the msbuild flags and not the compiler flags. – David Nov 03 '22 at 03:39
  • Your first question: At the moment this seems not an available feature to CMake. Second question: [Build Tool args doc](https://cmake.org/cmake/help/latest/manual/cmake.1.html?highlight=parallel#cmdoption-cmake--build-0). If you are trying to introduce reproducible CMake builds, maybe [CMake build presets' 'jobs' section](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html#build-preset) can be of some help. – Johnny_xy Nov 06 '22 at 23:46

1 Answers1

0

The answer as @Johnny_xy pointed out is you can't. You need to use ninja as the cmake generator.

cmake -S . -B build -G Ninja Multi-Config
cd build
cmake --build .

link to ninja releases: https://github.com/ninja-build/ninja/releases

ninja build time: 17.51s cmake default build time: 44.54s

David
  • 692
  • 8
  • 21