Cpp Compiler flags not accessible in the swift for Cpp-Swift Interop

I have a project that has Cpp code and swift code and I m making some calls from swift to cpp. For this I m using the Cpp-swift interop mechanism introduced in swift 5.9 for making direct calls between swift and cpp.

I m using module.modulemap file to expose the cpp code to swift. I am facnig an error when I try to access a cpp header that are using the cpp compiler flags in some static assert statements. These methods are working fine in cpp however, when I try to access these methods from swift using the modulemap file, the compiler flags are not being identified by swift, and produces the below error

error: use of undeclared identifier 'TW_KERNEL_WINDOWS'.

This is my module.modulemap file:

module CoreModule {
    
   header  "ProcessStates.hpp"  //cpp header that contains compiler flags 
    export *
}

below is the cpp header code that I m trying to access in swift:

#pragma once

// if the given condition is false – treat as an error
#define     STATIC_CHECKFALSE(condition, message)            static_assert (condition, message)

STATIC_CHECKFALSE ((TW_KERNEL_WINDOWS == 0) || (TW_KERNEL_WINDOWS == 1), "TW_KERNEL_WINDOWS can only be 0 or 1");

Can someone help, why is this happening and how to resolve this?

These methods are working fine in cpp however

How is TW_KERNEL_WINDOWS being set in your normal C++ code?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I m setting these preprocessor compillation flags in the cmake file using add_compile_definitions command. These flags are appearing in the Swift Compiler custom flags(under Active Compilation Conditions), But the swift is producing an error as above.

Hmmm, CMake, that’s not really my area of expertise. I think you might be better off asking this one on Swift Forums.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I have reproduced this problem without cmake. Can you help now?

I have an Xcode project containing a cpp target and a swift target. I am making direct swift to cpp call by exposing cpp to swift using the modulemap file. For the cpp target, I have defined some macros which I m using in the cpp header contained in the modulemap file. I m able to successfully build the cpp target. However, when I build the swift target I get an error message stating that the macros are not declared. When swift tries to import the cpp header via the clang module, it is not able to identify the cpp macros.

I m setting the macros in the Compiler flags for the cpp file. You can see this in the image below. One of the macro(WINDOW_KERNEL) is defined with some value.

error:Use of undeclared identifier 'WIN32' error:Use of undeclared identifier 'WINDOW_KERNEL'

I have also tried setting the cpp macros in Apple clang but it's also not identified in swift.

Cpp Compiler flags not accessible in the swift for Cpp-Swift Interop
 
 
Q