[CMake] Adding custom environment variables to generated Makefile

Carlchristian Eckert c.eckert at hzdr.de
Thu Jul 17 09:06:05 EDT 2014


Hello,

We are migrating our project from standard Unix Makefiles to CMake. The
old Makefile contained a line that cleared an environment variable like
this:

export CPLUS_INCLUDE_PATH=

This step is necessary due to some library/path confusion in combination
with 3rd party libraries on some systems.

However, I was unable to find a way to generate such a command (or any
other way to define environment variables) inside the generated Makefile.

The closest I got was something like
add_custom_target(
  workaround
  sed -i '3i\\\\n\#Workaround\ for\ Thrust\ bug\\nexport\
CPLUS_INCLUDE_PATH=' Makefile
)
This kind of works, but you have to run
make workaround
each time after generating the Makefile (and if you forget to do it, the
build will fail later)


Other projects [1] that use CMake just tell their users to run
unset CPLUS_INCLUDE_PATH
in their shell to work around the issue, which I try to avoid.

Is there any automated way to do this when generating the Makefile?



[1]
http://www.libama.org/documentation.html?tx_restdoc_pi1[doc]=installation|configuration|cuda


More information about the CMake mailing list