eclipse-cdt / cdt

Eclipse CDT™ C/C++ Development Tools
http://eclipse.org/cdt
Eclipse Public License 2.0
309 stars 201 forks source link

CMake projects created with special characters generate uncompilable example #288

Open jonahgraham opened 1 year ago

jonahgraham commented 1 year ago

Describe the bug

Using any characters that are not legal for C identifiers in the project names causes compiler errors (except (space) which is handled already).

To Reproduce Steps to reproduce the behavior:

  1. Create a new C/C++ Project
  2. Choose CMake project (the small Hello World example)
  3. Create a project name with - (dashes) in it
  4. Attempt to build project

For example, call the project example-cmake-project and observe that the config.h.in is invalid C code:

#define example-cmake-project_VERSION_MAJOR @example-cmake-project_VERSION_MAJOR@
#define example-cmake-project_VERSION_MINOR @example-cmake-project_VERSION_MINOR@

PR #105 introduced the config.h.in file and it does have special handling for spaces, but needs it for other characters too:

https://github.com/eclipse-cdt/cdt/blob/1783120eb77b9cd7d1a9ed02143ba18ef748ef68/cmake/org.eclipse.cdt.cmake.core/templates/simple/config.h.in#L1-L2

cc: @mbooth101

mbooth101 commented 1 year ago

The problem seems more general....

Creating a project called: Cake & ice-cream is 100% perfect, A+++ experience, don't @ me.

It fails at the first non alphanumeric character and results in this error (i.e. the ampersand ruins the XML manifest):

Loading template manifest
javax.xml.bind.UnmarshalException
 - with linked exception:
[org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 16; The entity name must immediately follow the '&' in the entity reference.]

Same error occurs for all core build project types (Make/CMake/Meson)