[CMake] How to source a shell script from CMAKE
Brad King
brad.king at kitware.com
Fri Feb 10 18:12:48 EST 2006
Linton, Tom wrote:
> But what I want to do is to source a file that sets up various
> paths and environment variables in addition to the compiler
> paths. Yes, I could manually do this
> within CMakeLists.txt but I'd rather source the actual file that
> is installed in the compiler distribution tree, to ensure I am
> using the correct environment. And I want to do it from within
> CMakeLists.txt rather than in a .bashrc or other personal file
> because these builds are being done by many people and I want
> the configuration to be fully defined in the CMakeLists.txt file
> itself.
CMake is not a build system and does not do a build, but instead
generates a native build system. A fundamental assumption that CMake
makes is that it is executed from the same environment that will be used
to perform the build once the build system is generated. It uses this
environment to detect the compiler location and a bunch of other
settings. Even if CMake were to magically load the environment during
its configuration process the user would still have to setup a shell
with the proper environment in order to actually build.
What you probably want is to start a prompt with the compiler
environment already sourced and then run "cmake" (all), "ccmake" (UNIX),
or "CMakeSetup" (Windows) from there. Once CMake generates the build
system you can use the same prompt to start the build.
On UNIX it is easy to source the script by hand or create a desktop menu
item that invokes a shell that pre-loads the script. On Windows you can
create a shortcut that runs cmd.exe and sources the .bat file. This is
the way the MS .NET compilers provide command line environments.
-Brad
More information about the CMake
mailing list