Skip to content

Comments

Fix generating draco project files from a directory containing special characters#1140

Open
whiteh0le wants to merge 1 commit intogoogle:mainfrom
whiteh0le:cmake_draco_install_fix
Open

Fix generating draco project files from a directory containing special characters#1140
whiteh0le wants to merge 1 commit intogoogle:mainfrom
whiteh0le:cmake_draco_install_fix

Conversation

@whiteh0le
Copy link

If you try to generate draco project files from a directory containing any regex special characters cmake will fail.

In my case, draco is inside a directory called "c++" and, because "+" is a regex special character, cmake fails to generate the project files with the following error:

$ cmake ..
RegularExpression::compile(): Nested *?+.
RegularExpression::compile(): Error in compile.
CMake Error at cmake/draco_install.cmake:42 (list):
  list sub-command TRANSFORM, action REPLACE: Failed to compile regex
  "C:/repos/c++/draco/src/draco/".
Call Stack (most recent call first):
  CMakeLists.txt:1152 (draco_setup_install_target)

As you can see, the error occurs at line 42 of cmake/draco_install.cmake:

list(TRANSFORM draco_api_includes REPLACE "${draco_src_root}/" "")

As per the cmake documentation, the REPLACE action of the TRANSFORM subcommand expects a regular expression as its first argument, in our case, this is the ${draco_src_root} variable containing the project's path.

The problem is that the code assumes that the directory path is a regex therefore it must not contain any special characters.

The solution is simple, replace the faulty list transform command by a directory-aware alternative. I choose the file RELATIVE_PATH command:

file(RELATIVE_PATH relative_file ${draco_src_root} ${file})
list(APPEND draco_api_includes ${relative_file})

This command will compute the relative path to the files correctly, even if the directory contains special characters.

With these changes cmake will now correctly generate the project files:

$ cmake ..
-- Configuring done (6.5s)
-- Generating done (1.1s)
-- Build files have been written to: C:/repos/c++/draco/build_dir

@google-cla
Copy link

google-cla bot commented Feb 16, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant