How to modify environment variables passed to custom CMake target?

A portable way of setting environment variables for a custom target is to use CMake’s command-line tool mode command env:

env [--unset=NAME]... [NAME=VALUE]... COMMAND [ARG]...

Run command in a modified environment.

E.g.:

add_custom_target(newtarget ${CMAKE_COMMAND} -E env NAME=VALUE somecommand)

Also see Command Line Tool Mode.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)