godot-cpp icon indicating copy to clipboard operation
godot-cpp copied to clipboard

CMake configuration error when passing quoted GODOT_CUSTOM_API_FILE path argument

Open PierceLBrooks opened this issue 3 years ago • 1 comments

Hello! The following commands will produce an error while attempting to generate the bindings with Python:

git clone https://github.com/godotengine/godot-cpp.git
cd godot-cpp
git checkout master
mkdir build
cd build
cmake -DGODOT_CUSTOM_API_FILE="C:/path/to/extension_api.json" ..

For me, this looks like:

-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19044.
File "<string>", line 1
import binding_generator; binding_generator.print_file_list(""C:/path/to/extension_api.json"", "C:/path/to/godot-cpp/build", headers=True, sources=True)
^
SyntaxError: invalid syntax
CMake Error at CMakeLists.txt:149 (add_custom_command):
add_custom_command Wrong syntax.  A TARGET or OUTPUT must be specified.

In the case of backslash characters being used on Windows machines instead of Unix-style forward slashes for path separators, this other message could be seen instead:

-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19044.
File "<string>", line 1
import binding_generator; binding_generator.print_file_list(""C:/path/to/extension_api.json"", "C:/path/to/godot-cpp/build", headers=True, sources=True)
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
CMake Error at CMakeLists.txt:149 (add_custom_command):
add_custom_command Wrong syntax.  A TARGET or OUTPUT must be specified.

I intend to resolve at least the first case with a pull request soon. The second case is a little trickier given how the binding generator script is invoked, and that there is currently no native support in the CMake language for automatically and easily escaping special characters in strings without simply making use of some kind of brute force regex replacement operation.

https://gitlab.kitware.com/cmake/cmake/-/issues/21494

PierceLBrooks avatar Sep 24 '22 04:09 PierceLBrooks

I'm trying to reproduce your case, and am unable to.. on windows 11 python 3 master branch this works without problem. cmake --fresh ../ -G"Ninja" -DGODOT_GDEXTENSION_DIR:PATH='C:\Godot\src\godot-cpp\gdextension  test\' cmake --fresh ../ -G"Ninja" -DGODOT_CUSTOM_API_FILE:PATH="C:\Godot\src\godot-cpp\gdextension  test\extension_api.json"

I can even mix slashes in the command cmake --fresh ../ -G"Ninja" -DGODOT_CUSTOM_API_FILE:PATH="C:\Godot\src/godot-cpp/gdextension  test/extension_api.json"

Both work without issue.

Git blame shows no appreciable changes after this issue date.

The error stating A TARGET or OUTPUT must be specified is about the previous execute_command not adding anything to GENERATED_FILES_LIST which set up the following command for a syntax error.

If GENERATED_FILES_LIST is empty then you get this failure, and I can make it happen if I have no gdextension_api.json at the specified location.

enetheru avatar Sep 24 '24 06:09 enetheru

I cannot replicate the error, I've tried all combinations of path separators, windows, and msys environments. I'm considering this solved.

enetheru avatar Nov 26 '24 09:11 enetheru

Closing per @enetheru's testing

dsnopek avatar Nov 26 '24 16:11 dsnopek