Search code examples
premake

Premake on windows gets incorrect realpath


I need to create define in premake that give me absolute path to project (Windows and Linux). I used

 defines {'ABSOLUTE_PATH="' ..path.getabsolute('.').. '"'}

But it's not working for me. define returns eg. c:/aaa/bbb/ccc and windows need c:\\aaa\\bbb\\ccc I also tried with

defines {'ABSOLUTE_PATH="' ..os.realpath('.').. '"'} 

but it gives me c:\aaa\bbb\ccc and that makes error "incorrectly formed universal character name". Is there easy way to get correctly generated value?


Solution

  • You are probably looking for something more like this:

    defines { 'ABSOLUTE_PATH="%{prj.abspath}"' }
    

    Using this token ensures that you will get the actual path where the project is generated, which depending on your project may or may not be the same as the current working directory.

    But you could also try:

    defines { 'ABSOLUTE_PATH="' .. path.translate(os.getcwd()) .. '"' }