From de03021a06886dcc5f364b2d8e3bc0348b898d76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Wed, 21 May 2025 11:25:04 +0200 Subject: [PATCH 1/2] Add test for command expansion --- packages/gyp-to-cmake/src/transformer.test.ts | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/packages/gyp-to-cmake/src/transformer.test.ts b/packages/gyp-to-cmake/src/transformer.test.ts index 47975995..f59fca5f 100644 --- a/packages/gyp-to-cmake/src/transformer.test.ts +++ b/packages/gyp-to-cmake/src/transformer.test.ts @@ -48,4 +48,39 @@ describe("bindingGypToCmakeLists", () => { assert(output.includes("add_library(foo SHARED file\\ with\\ spaces.cc")); }); + + describe("command expansions", () => { + it("should expand", () => { + const output = bindingGypToCmakeLists({ + projectName: "some-project", + gyp: { + targets: [ + { + target_name: "foo", + sources: [" { + const output = bindingGypToCmakeLists({ + projectName: "some-project", + gyp: { + targets: [ + { + target_name: "foo", + sources: [" Date: Wed, 21 May 2025 11:44:34 +0200 Subject: [PATCH 2/2] Emit "defines" via target_compile_definitions --- packages/gyp-to-cmake/src/gyp.ts | 1 + packages/gyp-to-cmake/src/transformer.test.ts | 24 +++++++++++++++++++ packages/gyp-to-cmake/src/transformer.ts | 22 ++++++++++++----- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/packages/gyp-to-cmake/src/gyp.ts b/packages/gyp-to-cmake/src/gyp.ts index cdde0d75..fdd209ef 100644 --- a/packages/gyp-to-cmake/src/gyp.ts +++ b/packages/gyp-to-cmake/src/gyp.ts @@ -7,6 +7,7 @@ export type GypTarget = { target_name: string; sources: string[]; include_dirs?: string[]; + defines?: string[]; }; export type GypBinding = { diff --git a/packages/gyp-to-cmake/src/transformer.test.ts b/packages/gyp-to-cmake/src/transformer.test.ts index f59fca5f..ba3de13f 100644 --- a/packages/gyp-to-cmake/src/transformer.test.ts +++ b/packages/gyp-to-cmake/src/transformer.test.ts @@ -83,4 +83,28 @@ describe("bindingGypToCmakeLists", () => { assert(output.includes("add_library(foo SHARED bar baz")); }); }); + + describe("defines", () => { + it("should add defines as target-specific compile definitions", () => { + const output = bindingGypToCmakeLists({ + projectName: "some-project", + gyp: { + targets: [ + { + target_name: "foo", + sources: ["foo.cc"], + defines: ["FOO", "BAR=value"], + }, + ], + }, + }); + + assert( + output.includes( + "target_compile_definitions(foo PRIVATE FOO BAR=value)" + ), + `Expected output to include target_compile_definitions:\n${output}` + ); + }); + }); }); diff --git a/packages/gyp-to-cmake/src/transformer.ts b/packages/gyp-to-cmake/src/transformer.ts index aa1b5e6f..ca2d45b4 100644 --- a/packages/gyp-to-cmake/src/transformer.ts +++ b/packages/gyp-to-cmake/src/transformer.ts @@ -17,7 +17,7 @@ function isCmdExpansion(value: string) { return trimmedValue.startsWith("