[Cmake] Environment variables

hvanderpool@xn-tech.com hvanderpool at xn-tech . com
Wed, 24 Sep 2003 10:31:09 -0700


Is there any way to retrieve the value of environment variables directly
with CMake.  I have been able to create make files with values that look
like an environment variable and work but it is not very elegant.  See ARGS
lines below.

      GET_FILENAME_COMPONENT(filename ${CMAKE_BUILD_TOOL} NAME_WE)
      IF (filename MATCHES msdev)
            ADD_CUSTOM_COMMAND(
                  SOURCE ${APCORE_SOURCE_DIR}/y_tab.c
                  COMMAND copy
                  ARGS y_tab.c "%CMAKE_CURRENT_SOURCE%\\parse.cpp"
                  TARGET APCORE
                  OUTPUTS parse.cpp)
      ELSE (filename MATCHES msdev)
            ADD_CUSTOM_COMMAND(
                  SOURCE ${APCORE_SOURCE_DIR}/y_tab.c
                  COMMAND copy
                  ARGS y_tab.c "$(CMAKE_CURRENT_SOURCE)\\parse.cpp"
                  TARGET APCORE
                  OUTPUTS parse.cpp)
      ENDIF (filename MATCHES msdev)

My current goal is to be able to detect if environment variables are set
and supply their values as defaults in the CMake GUI.