[CMake] Get program output in a variable?

Filipe Sousa filipe at ipb.pt
Sun Jan 15 16:06:23 EST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Zachary Pincus wrote:
> Hi guys,
> 
> I'm trying to make a better CMake script to find the presence of the  
> Numerical Python libraries and their include directories. The easiest  
> way to do this in some cases (e.g. with the newest version of said  
> libraries, now called numpy) is to query the module itself within  
> python.
> 
> Is there a good way within CMake to run a program? TRY_RUN seems to  
> want to compile a file first... I'd just like to run something like:
> "${PYTHON_EXECUTABLE} -c 'import numpy; print numpy.get_module_include 
> ()'"
> and get the output in a CMake variable.
> 
> Is this possible? If so, something similar might be a better way of  
> finding things like the python include path and so forth, rather than  
> looking in hard-coded places in a FindPythonLibs.cmake file.
> 
> Zach
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
> 
> 


fsousa at neptuno ~ $ cmake --help-command EXEC_PROGRAM
cmake version 2.3-20060115
EXEC_PROGRAM
Run and executable program during the processing of the CMakeList.txt
file.

	EXEC_PROGRAM(Executable [directory in which to run]
		[ARGS <arguments to executable>]
		[OUTPUT_VARIABLE <var>]
		[RETURN_VALUE <var>])

The executable is run in the optionally specified directory.  The
executable can include arguments if it is double quoted, but it is
better to use the optional ARGS argument to specify arguments to the
program.  This is because cmake will then be able to escape spaces in
the executable path.  An optional argument OUTPUT_VARIABLE specifies a
variable in which to store the output.  To capture the return value of
the execution, provide a RETURN_VALUE.  If OUTPUT_VARIABLE is
specified, then no output will go to the stdout/stderr of the console
running cmake.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFDyrlPbQdNYqwwwCwRAh2cAJ0bpHD7E60UDJ6icc6B53kOEjwEsQCeLpcC
qt/9wpyBBN+0xw2BpsDn31E=
=RVrF
-----END PGP SIGNATURE-----


More information about the CMake mailing list