Establish `conda` environment

All the documentation I could find about using a `conda` environment is related to `python`.

I am using `conda` to install C++ tooling like `cmake` and `conan`.
I want to be able to select `conda` environments in `CLion` when doing C++ development.
It seems the approach is to use a script to configure the environment.

https://www.jetbrains.com/help/clion/how-to-create-toolchain-in-clion.html#env-scripts

The example script referenced is buried in the yocto system.

https://docs.yoctoproject.org/sdk-manual/extensible.html#running-the-extensible-sdk-environment-setup-script

https://blog.jetbrains.com/clion/2021/09/clion-starts-2021-3-eap/#ability_to_initialize_toolchain_environment_via_script

I found the ticket where the capability was added but I am not finding an example.
https://youtrack.jetbrains.com/issue/CPP-11768/Ability-to-initialize-toolchain-environment-via-script


I presumed the script is something like the following:

#!/bin/bash -e
conda activate cts
export CMAKE=$(type -p cmake)

...but that does not appear to work.
Could you provide a sample script?

 

 

3 comments
Comment actions Permalink

You can create a symlink for the actual CMake location in the script to a known location, and specify this path to this CMake symlink in CLion's toolchain panel. Does this work?

0
Comment actions Permalink

https://www.jetbrains.com/help/clion/how-to-create-toolchain-in-clion.html#env-scripts --
"You can point CLion to the script that initializes the environment for your project without the need to set the variables manually.
This is helpful, for example, when you need to initialize compiler variables, add custom ones, or modify the PATH."

"a toolchain is a set of all the necessary tools required for building and running your application:

  • the CMake executable (CMake projects),
  • the build tool,
  • the C/C++ compilers,
  • the debugger binary, and
  • the working environment."

You are saying the script only directly sets the working environment? 
That is, the other objects in the toolchain may only be indirectly modified by the environment script?

How does Intellij / CLion go about detecting the other elements of the toolchain? It looks like CMake and the debugger must be fully specified (or use the bundled version) and then `cmake` is used to detect the build-tool, c-compiler, c++compiler.
Is this correct?

0
Comment actions Permalink

Thanks, with a slight modification to your approach I got the desired behavior.
Rather than a symlink I use a `cmake-wrapper.sh`.

#!/bin/bash
${CMAKE_EXEC} "$@"

In conjunction with the following environment script.

#!/bin/bash --login

# >>> mamba initialize >>>
# !! Contents within this block are managed by 'mamba init' !!
export MAMBA_EXE="/home/me/.local/bin/micromamba";
export MAMBA_ROOT_PREFIX="/home/me/micromamba";
__mamba_setup="$('/home/me/.local/bin/micromamba' shell hook --shell bash --prefix '/home/me/micromamba' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__mamba_setup"
else
if [ -f "/home/me/micromamba/etc/profile.d/micromamba.sh" ]; then
. "/home/me/micromamba/etc/profile.d/micromamba.sh"
else
export PATH="/home/me/micromamba/bin:$PATH" # extra space after export prevents interference from conda init
fi
fi
unset __mamba_setup
# <<< mamba initialize <<<

micromamba activate cts

export CMAKE_EXEC=$(type -p cmake)


I can probably simplify this second script, but you get the idea.
It would be nice if this `cmake-wrapper` behavior were added to the list of options {Bundled, Custom, Env-Variable}.

0

Please sign in to leave a comment.