[CMake] CONFIGURE_FILE, Windows and Native vs CMake Paths

Michael Wild themiwi at gmail.com
Sun Aug 8 03:36:42 EDT 2010


On 8. Aug, 2010, at 5:45 , Brian Davis wrote:

> I am using configure_file to generate a batch file on the fly with CMake
> based on location of Libs found (adding to PATH env var in batch script) and
> I was wondering if there is a way to not have to create a lot of variables
> for native paths such as below
> 
> --snip CMakelists.txt --
> SET( GTK2_ROOT_DIR "C:/Program Files/Gtk+" )
> 
> file(TO_NATIVE_PATH ${GTK2_ROOT_DIR} GTK2_ROOT_DIR_NATIVE )
> 
> message( "\tConfiguring batch file" )
> CONFIGURE_FILE( run_glade_test1.txt
> ${CMAKE_CURRENT_SOURCE_DIR}/run_glade_test1.bat )
> --end snip--
> 
> -snip run_glade_test1.txt--
> SET PWD=%CD%
> 
> set PATH=${GTK2_ROOT_DIR_NATIVE}\lib
> 
> GladeGTKTest2.exe
> 
> -end snip--
> 
> by default configure_file uses whatever the variable is set to and will not
> convert to native when generating files.

Well, I don't think there's a way around it. But you can use a loop to do it:

foreach(var GTK2_ROOT_DIR SOME_OTHER_PATH ANOTHER_PATH)
  file(TO_NATIVE_PATH ${${var}} ${var}_NATIVE)
endforeach()

Another thing, though: Never, ever, configure a file into the source tree. Doing so is a recipe for disaster...

Michael


More information about the CMake mailing list