Dhindhimathai
Dhindhimathai

Reputation: 33

Environment variable not found by cmake

I'm working on Ubuntu 14.04 with ROS Indigo and I need to use Geometry Tools Wild Magic 5 for developing a package.

I have exported the path to Wild Magic folder as an environment variable by modifying .bashrc as follows:

export WM5_PATH=/home/user/catkin_ws/src/GeometricTools/WildMagic5/SDK

This is done to specify locations of header files in the CMakeLists.txt file of the package I'm coding:

include_directories(
    include
    $ENV{WM5_PATH}/Include/
)

Previously, in the same cmake file I check if the environmental variable is correctly set:

if (NOT DEFINED ENV{WM5_PATH})
    MESSAGE (FATAL_ERROR "Wild Magic Engine 5.14 missing")
endif()

Now, while building the package using catkin build the environment variable is not found (the if above is entered). But by using printenv in the terminal I can see that the environment variable WM5_PATH is actually there.

How could I solve this problem?

Upvotes: 3

Views: 8104

Answers (1)

Florian
Florian

Reputation: 43038

I've just given your example a try and it works fine in my Ubuntu bash shell.

# export WM5_PATH=/home/user/catkin_ws/src/GeometricTools/WildMagic5/SDK
# cmake ..
-- Configuring done
-- Generating done
-- Build files have been written to: ...

So I suspect your cmake executable runs in another environment (e.g. an IDE).

To check what your CMake does see as an environment you could add the following to your CMakeLists.txt:

execute_process(
    COMMAND ${CMAKE_COMMAND} -E environment
)

Reference

Upvotes: 4

Related Questions