@@ -126,6 +126,50 @@ describe("bindingGypToCmakeLists", () => {
126126 } ) ;
127127 } ) ;
128128
129+ describe ( "cflags" , ( ) => {
130+ it ( "should add cflags as target-specific compile options" , ( ) => {
131+ const output = bindingGypToCmakeLists ( {
132+ projectName : "some-project" ,
133+ gyp : {
134+ targets : [
135+ {
136+ target_name : "foo" ,
137+ sources : [ "foo.cc" ] ,
138+ cflags : [ "-fPIC" , "-Wall" , "-DNAME=value with space" ] ,
139+ } ,
140+ ] ,
141+ } ,
142+ } ) ;
143+
144+ assert (
145+ output . includes (
146+ "target_compile_options(foo PRIVATE -fPIC -Wall -DNAME=value\\ with\\ space)" ,
147+ ) ,
148+ `Expected output to include target_compile_options:\n${ output } ` ,
149+ ) ;
150+ } ) ;
151+
152+ it ( "should expand cflags command output into compile options" , ( ) => {
153+ const output = bindingGypToCmakeLists ( {
154+ projectName : "some-project" ,
155+ gyp : {
156+ targets : [
157+ {
158+ target_name : "foo" ,
159+ sources : [ "foo.cc" ] ,
160+ cflags : [ "<!@echo -fPIC -Wall" ] ,
161+ } ,
162+ ] ,
163+ } ,
164+ } ) ;
165+
166+ assert (
167+ output . includes ( "target_compile_options(foo PRIVATE -fPIC -Wall)" ) ,
168+ `Expected expanded cflags in target_compile_options:\n${ output } ` ,
169+ ) ;
170+ } ) ;
171+ } ) ;
172+
129173 describe ( "namespaced targets" , ( ) => {
130174 const gyp = {
131175 targets : [ { target_name : "addon" , sources : [ "addon.cc" ] } ] ,
@@ -174,6 +218,7 @@ describe("bindingGypToCmakeLists", () => {
174218 sources : [ "addon.cc" ] ,
175219 include_dirs : [ "include" ] ,
176220 defines : [ "FOO" ] ,
221+ cflags : [ "-fPIC" ] ,
177222 } ,
178223 ] ,
179224 } ,
@@ -186,6 +231,7 @@ describe("bindingGypToCmakeLists", () => {
186231 "target_link_libraries(some-project-addon PRIVATE weak-node-api)" ,
187232 "target_include_directories(some-project-addon PRIVATE include)" ,
188233 "target_compile_definitions(some-project-addon PRIVATE FOO)" ,
234+ "target_compile_options(some-project-addon PRIVATE -fPIC)" ,
189235 "target_compile_features(some-project-addon PRIVATE cxx_std_17)" ,
190236 ] ) {
191237 assert (
0 commit comments