Locate an environment module implementation and make commands available to CMake scripts to use them. This is compatible with both Lua-based Lmod and TCL-based EnvironmentModules.
This module is intended for the use case of setting up the compiler and library environment within a CTest Script (ctest -S). It can also be used in a CMake Script (cmake -P).
Note
The loaded environment will not survive past the end of the calling process. Do not use this module in project code (CMakeLists.txt files) to load a compiler environment; it will not be available during the build. Instead load the environment manually before running CMake or using the generated build system.
set(CTEST_BUILD_NAME "CrayLinux-CrayPE-Cray-dynamic")
set(CTEST_BUILD_CONFIGURATION Release)
set(CTEST_BUILD_FLAGS "-k -j8")
set(CTEST_CMAKE_GENERATOR "Unix Makefiles")
...
find_package(EnvModules REQUIRED)
env_module(purge)
env_module(load modules)
env_module(load craype)
env_module(load PrgEnv-cray)
env_module(load craype-knl)
env_module(load cray-mpich)
env_module(load cray-libsci)
set(ENV{CRAYPE_LINK_TYPE} dynamic)
...
This module will set the following variables in your project:
The following cache variable will be set:
This defines the following CMake functions for interacting with environment modules:
Execute an aribitrary module command:
env_module(cmd arg1 ... argN)
env_module(
COMMAND cmd arg1 ... argN
[OUTPUT_VARIABLE <out-var>]
[RESULT_VARIABLE <ret-var>]
)
The options are:
Swap one module for another:
env_module_swap(out_mod in_mod
[OUTPUT_VARIABLE <out-var>]
[RESULT_VARIABLE <ret-var>]
)
This is functionally equivalent to the module swap out_mod in_mod shell command. The options are:
Retrieve the list of currently loaded modules:
env_module_list(<out-var>)
This is functionally equivalent to the module list shell command. The result is stored in <out-var> as a properly formatted CMake semicolon-separated list variable.
Retrieve the list of available modules:
env_module_avail([<mod-prefix>] <out-var>)
This is functionally equivalent to the module avail <mod-prefix> shell command. The result is stored in <out-var> as a properly formatted CMake semicolon-separated list variable.