How to export environment variables globally?

Hi,

I have a C++ project with Doxygen documentation. I set variables in the CMake script, such as

set(P4LBM_HOME ${CMAKE_CURRENT_SOURCE_DIR})
set(P4LBM_DOC ${P4LBM_HOME}/docs)
add_custom_target(docs
        COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
        COMMENT "Generating API documentation with Doxygen"
        VERBATIM)

In Doxyfile.in, I read the values of these variables using e.g.

HTML_FOOTER = @P4LBM_DOC@/doxygen_footer.html

The documentation is built successfully with make docs.


Now I want to be able to build the documentation in GitLab CI without building the main code and without CMake. So I replace the CMake set commands with environment variables in the .gitlab-ci.yml file:

pages:
  stage: deploy
  script:
    - mkdir build
    - export ROOT=$PWD
    - export P4LBM_DOC=$ROOT/docs
    - doxygen docs/Doxyfile.in

Environment variables in Doxygen are read with the $(...) syntax, not with @...@. In the example above:

HTML_FOOTER = $(P4LBM_DOC)/doxygen_footer.html

Once I perform these changes in Doxyfile.in, the documentation builds properly on the CI.


Now I cannot build the documentation locally with CMake using make docs because Doxyfile.in expects environment variables, not CMake variables. And adding the ENV keywords, e.g.

set(ENV{P4LBM_DOC} ${P4LBM_HOME}/docs)

does not make a difference, probably because CMake cannot inject environment variables into the parent process. Is there a way to let Doxygen know about these environment variables from within CMake? Alternatively, I thought about writing the documentation creation commands

export ROOT=$PWD
export P4LBM_DOC=$ROOT/docs
doxygen docs/Doxyfile.in

into a Bash script and call this script from CMake. The drawback is that it would only work on OSs which can interpret Bash scripts.

You can replace your doxygen command in your cmake with

add_custom_target(docs
        COMMAND ${CMAKE_COMMAND} -E env VAR=val
           ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
        COMMENT "Generating API documentation with Doxygen"
        VERBATIM)
1 Like
add_custom_target(docs
		COMMAND ${CMAKE_COMMAND} -E env P4LBM_DOC=${P4LBM_HOME}/docs LBMGRID_DOC ${P4LBM_HOME}/visualization DOXYGEN_IN=${P4LBM_HOME}/docs/Doxyfile.in DOXYGEN_OUT=${CMAKE_CURRENT_BINARY_DIR}/Doxyfile.out ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
        COMMENT "Generating API documentation with Doxygen"
        VERBATIM)

gives me the following error:

Generating API documentation with Doxygen
No such file or directory
make[3]: *** [CMakeFiles/docs.dir/build.make:71: CMakeFiles/docs] Error 1
make[2]: *** [CMakeFiles/Makefile2:555: CMakeFiles/docs.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:562: CMakeFiles/docs.dir/rule] Error 2
make: *** [Makefile:202: docs] Error 2

Where can I check the paths generated by CMake and a verbose error message?

looks like your command is missing an = after LBMGRID_DOC

Rookie mistake. Thanks a lot, it works perfectly!

1 Like