[CMake] CMake Function, how do I pass out strings or lists?

kent williams nkwmailinglists at gmail.com
Wed Jan 26 12:24:48 EST 2011


The CMakeLists.txt below illustrates the problem:
-------------------------------------------------------------
cmake_minimum_required(VERSION 2.8)
project(testo)

function(set_a_var var value)
  set(${var} ${value})
  message("${var} = ${${var}}")
endfunction()

set_a_var(testo "HELLO!")

message("outside func testo=${testo}")
------------------------------------------------------------
The output is:
------------------------------------------------------------
cmake ../CompilerFlags
testo = HELLO!
outside func testo=
-- Configuring done
-- Generating done
-- Build files have been written to: /scratch/kent/CompilerFlags/build
-------------------------------------------------------------

I gather from looking in the CMake Modules that you have to set the
variable to be Cached, but won't this result in some cases in the
CMakeCache.txt getting stuffed full of definititions only relevant to
function calls?

Not that I want to, but what if you started computing factorials?


More information about the CMake mailing list