[CMake] enviroment variables (ice cream builds)

Izaak Beekman ibeekman at umiacs.umd.edu
Wed Jun 19 15:40:42 EDT 2013


You probably are aware of the following points, but I'm going to share them
anyway.

1) You should be able to set environment variables at cmake time with
set(ENV{my_var} "my_value"). I think that this would need to be done before
cmake starts searching for the compilers etc, so before any
enable_language() or project() calls. Presumably this will be set in the
environment in which cmake tests the compilers for functionality, but I'm
not 100% sure on this. If so this should get you past the cmake errors
cited in your message. I think that CMake determines the compilers and
tests them for functionality and then stores this info in the cache. You
could also check the user's environment (that it's properly configured) by
referencing environment variables from within your CMake files using the
$ENV{var} syntax. This way if the environment is wrong at cmake time it can
at least be detected (although no guarantees for compile time).

2) Now, point one only really applies at cmake time. If you don't rerun
cmake, there is no guarantee that the variable is set at compile time. If
the compiler depends on these variables to be set to function properly you
need to ensure they're present. A really ugly work around could be to
create a phony target on which all the other targets depend that checks for
the environment variables to be properly set and complains if they are not,
or, even sets them if they aren't properly set. I have no experience with
Ninja, but this approach should be feasible with make.

3) Could you setup scripts for your users to source (possibly from one of
their "dot" files, .bashrc or .bash_profile or .profile) that would
configure their build environment for the compiler they want to use? Or
implement GNU modules? The Intel compilers on linux provide scripts that
(mostly) configure you build environment to use the specified version of
the compiler. If you want to switch compiler versions, just source the
script associated with that compiler. However, CMake stores the compiler
(in the cache, I think) that was originally specified, so ideally you would
setup a separate build tree after changing compilers, or at least delete
the cache.

I think 3 is the sanest approach. You can put tests in the cmake files to
check if the user has failed to setup their environment. If you're really
paranoid tests could be added as phony targets too, but IMHO if someone
knows enough to want to pick a specific compiler version to compile their
code, they should be capable of some simple development environment setup
and management.

I am pretty new to CMake, so my apologies if my advice/understanding is
incorrect.  Also, I haven't tested any of these approaches, other than 3,
myself.

Good luck,
Izaak Beekman
===================================
(301)244-9367
UMD-CP Visiting Graduate Student
Aerospace Engineering
ibeekman at umiacs.umd.edu
ibeekman at umd.edu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130619/5bf97633/attachment.htm>


More information about the CMake mailing list