[CMake] Custom Commands and Environmnt Settings for PATH and LD_LIBRARY_PATH

Jörg Kreuzberger j.kreuzberger at procitec.de
Fri Apr 11 05:32:57 EDT 2014


Hi!

Had an issue with cmake custom commands - was able to solve it after serveral hours. But i think this is realy an issue for an improvement

I. What i wanted to do:

I wanted to add a simple custom command

add_custom_command( OUTPUT <out>
                    COMMAND <mycommand> ... )

<mycommand> is a target, the path to the target is resolved perfectly by cmake for all configurations required (linux, win/jom, win/mingw, win/vs2012 )

BUT

the command requires additional dlls (QT + INTELIPP). so i have to add something like

add_custom_command( OUTPUT <out>
                    COMMAND set PATH="%PATH%;${QT_BINARY_DIR};${INTELIPP_LIBRARY_DIR}"
                    COMMAND <mycommand> ... )

and then the mess began.

My issues:

- For windows path handling (paths seperated by semicolon) it is a mess to set the path this way, you have to quote, escape semicolons etc
- You get errors that the PATH is to long .. 
- The path is then set for the complete compilation process, not just for the command / dependent for the generator
- handling is os specific, so you have several nearly same implementations

After reading serveral threads i ended in this solution

- create a batch/shell script for the command i want to start. This ensures path modifications are local. Creation is done via a configure_file step

- Append the %PATH% in the batch/shell script. This avoids the mess with cmake string list coversions (splitting path into space sepearated lists)

- But i now get issues with:
  - i must provide full path to <mycommand>, this is not resolved by cmake any more
  - full puth for vs is dependend on $(Outdir) or $(Configuration) that is for sure not available in the scripts
  - so search/replace the variables int the commands

So i solved, it, but the "workload" to get into a solution here is to much, especially if you want to support the multiconfiguration environment for visual studio. Here the issue is that the configure_file is done on configuration, but the Build_type can only be determined on build and therefore the path in the script to <mycommand> must be set via arguments to the script.

So it would help to have a possiblity to have a custom command like this:

add_custom_command( OUTPUT <out>
                    COMMAND ..
                    COMMAND ..
                    ENVIRONMENT PATH=$ENV{PATH}
                    ENVIRONMENT LD_LIBRARY=

So my questions:

if i would provide such a macro how can i:
- DISABLE cmake string handling in arguments to ENVIRONMENT, not just by quoting adding "" 
- ENSURE that the environment settings are LOCAL to the custom command


Thanks for support....


More information about the CMake mailing list