[CMake] CMAKE_CURRENT_SOURCE_DIR with different values: bug?

Alexander Neundorf a.neundorf-work at gmx.net
Wed Jun 17 17:38:40 EDT 2009


On Monday 15 June 2009, Bruno Nery wrote:
> Hello,
>
>    This problem happens when I need to use ${CMAKE_CURRENT_SOURCE_DIR}
> inside a script, but for an out-of-source build. When echoed from the
> CMakeLists.txt file, it outputs the right value (i.e., the source
> folder) However, when echoed from inside the script, it outputs the
> build folder name (source folder/build). Attached is a "Hello World"
> project that reproduces the bug (if it's really a bug) - could anyone
> please verify it? CMake version is 2.4.6.

It's not a bug, it's a feature.
No, seriously, it's exptected behaviour.
The script is executed by another cmake, and for that cmake 
CMAKE_CURRENT_SOURCE_DIR is independent from the CMAKE_CURRENT_SOURCE_DIR in 
the cmake which is processing the CMakeLists.txt.
You can set variables for the script:
add_custom_command(OUTPUT ...
  COMMAND 
${CMAKE_COMMAND} -DMY_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} -Pmyscript.cmake )

and then use MY_CURRENT_SOURCE_DIR in myscript.cmake

Alex


More information about the CMake mailing list