@@ -19,7 +19,7 @@ function isCmdExpansion(value: string) {
1919 return trimmedValue . startsWith ( "<!" ) ;
2020}
2121
22- function escapePath ( source : string ) {
22+ function escapeSpaces ( source : string ) {
2323 return source . replace ( / / g, "\\ " ) ;
2424}
2525
@@ -65,27 +65,33 @@ export function bindingGypToCmakeLists({
6565 //"cmake_policy(SET CMP0042 NEW)",
6666 `project(${ projectName } )` ,
6767 "" ,
68- `add_compile_definitions(-DNAPI_VERSION=${ napiVersion } )` ,
68+ // Declaring a project-wide NAPI_VERSION as a fallback for targets that don't explicitly set it
69+ `add_compile_definitions(NAPI_VERSION=${ napiVersion } )` ,
6970 ] ;
7071
7172 for ( const target of gyp . targets ) {
7273 const { target_name : targetName } = target ;
7374
7475 // TODO: Handle "conditions"
75- // TODO: Handle "defines"
7676 // TODO: Handle "cflags"
7777 // TODO: Handle "ldflags"
7878
7979 const escapedJoinedSources = target . sources
8080 . flatMap ( mapExpansion )
8181 . map ( transformPath )
82- . map ( escapePath )
82+ . map ( escapeSpaces )
8383 . join ( " " ) ;
8484
8585 const escapedJoinedIncludes = ( target . include_dirs || [ ] )
8686 . flatMap ( mapExpansion )
8787 . map ( transformPath )
88- . map ( escapePath )
88+ . map ( escapeSpaces )
89+ . join ( " " ) ;
90+
91+ const escapedJoinedDefines = ( target . defines || [ ] )
92+ . flatMap ( mapExpansion )
93+ . map ( transformPath )
94+ . map ( escapeSpaces )
8995 . join ( " " ) ;
9096
9197 lines . push (
@@ -94,7 +100,12 @@ export function bindingGypToCmakeLists({
94100 `set_target_properties(${ targetName } PROPERTIES PREFIX "" SUFFIX ".node")` ,
95101 `target_include_directories(${ targetName } PRIVATE ${ escapedJoinedIncludes } \${CMAKE_JS_INC})` ,
96102 `target_link_libraries(${ targetName } PRIVATE \${CMAKE_JS_LIB})` ,
97- `target_compile_features(${ targetName } PRIVATE cxx_std_17)`
103+ `target_compile_features(${ targetName } PRIVATE cxx_std_17)` ,
104+ ...( escapedJoinedDefines
105+ ? [
106+ `target_compile_definitions(${ targetName } PRIVATE ${ escapedJoinedDefines } )` ,
107+ ]
108+ : [ ] )
98109 // or
99110 // `set_target_properties(${targetName} PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO)`,
100111 ) ;
0 commit comments