Power cmake in parallel .Co compilation before binding

I have a project with 5 libraries, each of which consists of 10 C ++ source files, and then 10 executable files that depend on the libraries. Each library also depends on the previous one. Using CMake and then "make -j 50" on a 48-core Ubuntu computer, I first need to wait for each library to build on 10 cores or less (basically less, since one .C file takes several minutes to compile), then my executables are built in parallel.

I would like to first run all .Co compilations in parallel in all .C source files (I know how to get this list in the CMake variable), and then only run the linker in the order indicated by the dependencies.

Is there a way to do this with CMake, for example by setting a fake target or something like that? (I just want to recompile the .C files that have been modified).

+4
source share
1 answer

The way to do this is to add a false target consisting of all the sources for each of the library goals in CMake. An example of CMakeLists.txt might be ...

set(ONE_SRC one/a.c one/b.c)
set(TWO_SRC two/a.c two/b.c)

# pre-compile
add_library(all ${ONE_SRC} ${TWO_SRC})

add_library(one ${ONE_SRC})
add_library(two ${TWO_SRC})

add_dependencies(one all)
add_dependencies(two one)

Liball.so goal is to compile all the sources needed for all other libraries, and it should break the false relationship between source files and libone.so libtwo.so at startup make, ninjaregardless of whether ... it will be possible to compile the parallelism of purpose.

CMake ${ONE_SRC} ${TWO_SRC} . ccache, . .

ccache ccache $PATH.

jason@io ~ $ ll ~/bin/ccache
total 0
lrwxrwxrwx 1 jason jason 15 May 12  2013 c++ -> /usr/bin/ccache*
lrwxrwxrwx 1 jason jason 15 May 12  2013 cc -> /usr/bin/ccache*
lrwxrwxrwx 1 jason jason 15 Apr 27 21:38 clang -> /usr/bin/ccache*
lrwxrwxrwx 1 jason jason 15 Apr 27 21:38 clang++ -> /usr/bin/ccache*
lrwxrwxrwx 1 jason jason 15 May 12  2013 g++ -> /usr/bin/ccache*
lrwxrwxrwx 1 jason jason 15 Oct  6  2013 gcc -> /usr/bin/ccache*
lrwxrwxrwx 1 jason jason 15 May 12  2013 x86_64-pc-linux-gnu-c++ -> /usr/bin/ccache*
lrwxrwxrwx 1 jason jason 15 May 12  2013 x86_64-pc-linux-gnu-g++ -> /usr/bin/ccache*
lrwxrwxrwx 1 jason jason 15 May 12  2013 x86_64-pc-linux-gnu-gcc -> /usr/bin/ccache*

ccache .

# ccache

export CCACHE_DIR="/var/ccache/${USER}"
export CCACHE_SIZE="4G"
export CCACHE_COMPRESS="1"
+1

Source: https://habr.com/ru/post/1540617/


All Articles