@@ -16,6 +16,7 @@ export type GypToCmakeListsOptions = {
1616 defineNapiVersion ?: boolean ;
1717 weakNodeApi ?: boolean ;
1818 appleFramework ?: boolean ;
19+ namespacedTargets ?: boolean ;
1920} ;
2021
2122function isCmdExpansion ( value : string ) {
@@ -50,6 +51,7 @@ export function bindingGypToCmakeLists({
5051 weakNodeApi = false ,
5152 appleFramework = true ,
5253 compileFeatures = [ ] ,
54+ namespacedTargets = false ,
5355} : GypToCmakeListsOptions ) : string {
5456 function mapExpansion ( value : string ) : string [ ] {
5557 if ( ! isCmdExpansion ( value ) ) {
@@ -123,20 +125,26 @@ export function bindingGypToCmakeLists({
123125 escapedIncludes . push ( "${CMAKE_JS_INC}" ) ;
124126 }
125127
128+ const actualTargetName = namespacedTargets
129+ ? `${ projectName } -${ targetName } `
130+ : targetName ;
131+
126132 function setTargetPropertiesLines (
127133 properties : Record < string , string > ,
128134 indent = "" ,
129135 ) : string [ ] {
130136 return [
131- `${ indent } set_target_properties(${ targetName } PROPERTIES` ,
137+ `${ indent } set_target_properties(${ actualTargetName } PROPERTIES` ,
132138 ...Object . entries ( properties ) . map (
133139 ( [ key , value ] ) => `${ indent } ${ key } ${ value ? value : '""' } ` ,
134140 ) ,
135141 `${ indent } )` ,
136142 ] ;
137143 }
138144
139- lines . push ( `add_library(${ targetName } SHARED ${ escapedSources . join ( " " ) } )` ) ;
145+ lines . push (
146+ `add_library(${ actualTargetName } SHARED ${ escapedSources . join ( " " ) } )` ,
147+ ) ;
140148
141149 if ( appleFramework ) {
142150 lines . push (
@@ -161,6 +169,8 @@ export function bindingGypToCmakeLists({
161169 {
162170 PREFIX : "" ,
163171 SUFFIX : ".node" ,
172+ // Ensure the final library use the non-namespaced target name
173+ ...( actualTargetName ? { OUTPUT_NAME : targetName } : { } ) ,
164174 } ,
165175 " " ,
166176 ) ,
@@ -178,31 +188,31 @@ export function bindingGypToCmakeLists({
178188
179189 if ( libraries . length > 0 ) {
180190 lines . push (
181- `target_link_libraries(${ targetName } PRIVATE ${ libraries . join ( " " ) } )` ,
191+ `target_link_libraries(${ actualTargetName } PRIVATE ${ libraries . join ( " " ) } )` ,
182192 ) ;
183193 }
184194
185195 if ( escapedIncludes . length > 0 ) {
186196 lines . push (
187- `target_include_directories(${ targetName } PRIVATE ${ escapedIncludes . join (
197+ `target_include_directories(${ actualTargetName } PRIVATE ${ escapedIncludes . join (
188198 " " ,
189199 ) } )`,
190200 ) ;
191201 }
192202
193203 if ( escapedDefines . length > 0 ) {
194204 lines . push (
195- `target_compile_definitions(${ targetName } PRIVATE ${ escapedDefines . join ( " " ) } )` ,
205+ `target_compile_definitions(${ actualTargetName } PRIVATE ${ escapedDefines . join ( " " ) } )` ,
196206 ) ;
197207 }
198208
199209 if ( compileFeatures . length > 0 ) {
200210 lines . push (
201- `target_compile_features(${ targetName } PRIVATE ${ compileFeatures . join ( " " ) } )` ,
211+ `target_compile_features(${ actualTargetName } PRIVATE ${ compileFeatures . join ( " " ) } )` ,
202212 ) ;
203213 }
204214
205- // `set_target_properties(${targetName } PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO)`,
215+ // `set_target_properties(${actualTargetName } PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO)`,
206216 }
207217
208218 if ( ! weakNodeApi ) {
0 commit comments