11import cp from "node:child_process" ;
2+ import path from "node:path" ;
23
34import type { GypBinding } from "./gyp.js" ;
45
@@ -10,6 +11,7 @@ export type GypToCmakeListsOptions = {
1011 napiVersion ?: number ;
1112 executeCmdExpansions ?: boolean ;
1213 unsupportedBehaviour ?: "skip" | "warn" | "throw" ;
14+ transformWinPathsToPosix ?: boolean ;
1315} ;
1416
1517function isCmdExpansion ( value : string ) {
@@ -31,6 +33,7 @@ export function bindingGypToCmakeLists({
3133 napiVersion = DEFAULT_NAPI_VERSION ,
3234 executeCmdExpansions = true ,
3335 unsupportedBehaviour = "skip" ,
36+ transformWinPathsToPosix = true ,
3437} : GypToCmakeListsOptions ) : string {
3538 function mapExpansion ( value : string ) : string [ ] {
3639 if ( ! isCmdExpansion ( value ) ) {
@@ -48,6 +51,14 @@ export function bindingGypToCmakeLists({
4851 return [ value ] ;
4952 }
5053
54+ function transformPath ( input : string ) {
55+ if ( transformWinPathsToPosix ) {
56+ return input . split ( path . win32 . sep ) . join ( path . posix . sep ) ;
57+ } else {
58+ return input ;
59+ }
60+ }
61+
5162 const lines : string [ ] = [
5263 "cmake_minimum_required(VERSION 3.15)" ,
5364 //"cmake_policy(SET CMP0091 NEW)",
@@ -67,11 +78,13 @@ export function bindingGypToCmakeLists({
6778
6879 const escapedJoinedSources = target . sources
6980 . flatMap ( mapExpansion )
81+ . map ( transformPath )
7082 . map ( escapePath )
7183 . join ( " " ) ;
7284
7385 const escapedJoinedIncludes = ( target . include_dirs || [ ] )
7486 . flatMap ( mapExpansion )
87+ . map ( transformPath )
7588 . map ( escapePath )
7689 . join ( " " ) ;
7790
0 commit comments