Skip to content

Commit

Permalink
Fix potentially invalid macro name in generated version header (#38)
Browse files Browse the repository at this point in the history
* Fix potentially invalid macro name in generated version header

The generated name was invalid if the target name contained characters
that are not legal in macro identifiers. This commit replaces all
illegal characters with the underscore "_".

* Update CMakeLists.txt

---------

Co-authored-by: Lars Melchior <[email protected]>
  • Loading branch information
jan-moeller and TheLartians authored Nov 19, 2023
1 parent 28f6118 commit ac46aef
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ function(packageProject)
endif()

string(TOUPPER ${PROJECT_NAME} UPPERCASE_PROJECT_NAME)
# ensure that the generated macro does not include invalid characters
string(REGEX REPLACE [^a-zA-Z0-9] _ UPPERCASE_PROJECT_NAME ${UPPERCASE_PROJECT_NAME})
configure_file(
${PACKAGE_PROJECT_ROOT_PATH}/version.h.in
${PROJECT_VERSION_INCLUDE_DIR}/${PROJECT_VERSION_HEADER} @ONLY
Expand Down

0 comments on commit ac46aef

Please sign in to comment.