Makefiles: Multiple targets not built in parallel
If I specify multiple --target
flags on the command line along with --parallel
, the targets are built sequentially, not in parallel.
For example, if I have the following CMakeLists.txt file:
cmake_minimum_required(VERSION 3.24.0)
project(parallel-test LANGUAGES CXX)
add_executable(a a.cpp)
add_executable(b b.cpp)
Then the following command runs sequentially.
$ cmake .
$ cmake --build . --target a --target b --parallel
[ 50%] Building CXX object CMakeFiles/a.dir/a.cpp.o
[100%] Linking CXX executable a
[100%] Built target a
[ 50%] Building CXX object CMakeFiles/b.dir/b.cpp.o
[100%] Linking CXX executable b
[100%] Built target b
But if I omit the --target
flags then the project is indeed built in parallel.
$ cmake --build . --parallel
[ 25%] Building CXX object CMakeFiles/a.dir/a.cpp.o
[ 50%] Building CXX object CMakeFiles/b.dir/b.cpp.o
[ 75%] Linking CXX executable b
[100%] Linking CXX executable a
[100%] Built target b
[100%] Built target a
Can CMake be changed to build targets in parallel in the first case as well?
CMake version: 3.24.1
OS version: Ubuntu 18.04.6 LTS
Edited by Brad King