BASE_DIRS in `target_sources()`

Hi all.
What would be the correct approach for:
Say I have a ./src/utils/utils.ixx, and, in that file, I want to include:

  • ./extern/include/generator.hpp
  • and two windows headers, namely:
    • $ENV{WindowsSdkDir}/Include/$ENV{WindowsSDKVersion}/um/windows.h and
    • $ENV{WindowsSdkDir}/Include/$ENV{WindowsSDKVersion}/ucrt/conio.h

I would then link my other modules with the utils module, so that I could use the functionality from it.

I have tried everything and no matter what I do, I get errors saying that the um/windows.h and ucrt/conio.h should be in one of the base dirs, although I literaly hard-coded the expanded version of $ENV{WindowsSdkDir}/Include/$ENV{WindowsSDKVersion}/; still, it only considers relative paths and, therefore, will look into ./src/utils/

I have tried using two targets, one for the headers [using HEADERS as the type and adding $ENV{WindowsSdkDir}/Include/$ENV{WindowsSDKVersion}/ for the base dir] and one for the generator.hpp + utils.ixx and it will say that it can’t determine the linker language from the HEADERS setup, etc.

What would be the appropriate approach here?
I would basically #include the generator file and the windows headers in the utils.ixx file, do what I needed to do with them, and simply link utils with the other libs, so I could call functions from utils.

Thank you.

Are you trying to add um/windows.h and ucrt/conio.h to the file list of your target? That seems wrong to me. I would model this as something like:

add_library(WindowsHeaders IMPORTED INTERFACE)
target_include_directories(WindowsHeaders INTERFACE $ENV{WindowsSdkDir}/Include/…)

and then link to WindowsHeaders as needed.

1 Like

It seemed wrong to me too, I just didn’t know what else to do :joy:, or how to model it to use with my C++20 Modules; I, however, knew that I would need to have that “INTERFACE” keyword somehow, somewhere haha.
So, basically, I should have the two targets separate - create a target for the windows headers and make my own modules their own thing and then just do the linking.
I didn’t know about that construct [ add_library(WindowsHeaders IMPORTED INTERFACE)].
Thank you very much :raised_hands:, Ben.