Is there a way to set globally a cmake property?

Let's say I build multiple cmake-based projects. I want to build them with a global property always defined.

For example, let's say I want to build always with sccache. For that, for each project, I need to do:

cmake <dir> -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache

I end up writing that a lot, so it'd be useful to avoid it. I know I can create a wrapper for my C compiler that calls into sccache, and:

export CC=/path/to/sccache/gcc

(for example).

Similarly, I could write a wrapper or shell alias on top of cmake that just called cmake -D....

But I would've expected to be able to do something like:

export CMAKE_CXX_COMPILER_LAUNCHER=sccache
export CMAKE_C_COMPILER_LAUNCHER=sccache

There doesn't seem to be a way to do this. Is there one? I generally don't like to change CC and CXX globally because they may cause issues with other build systems or what not.

Upvotes: 1

Views: 441

Answers (1)

albestro
albestro

Reputation: 121

I'm wondering if a dedicated toolchain script may be helpful for your needs.

Give a look at its documentation here

Then you would have to define -DCMAKE_TOOLCHAIN_FILE=<toolchain_script> each time you want to use that preset of variables.

Upvotes: 1

Related Questions