cmake configure project with ewdk toolchain

I am unable to configure a project while inside an EWDK environment because cmake searches for resources in the wrong place.
The setup: installed visual studio 2019 with an SDK (something that will bring the windows kits), and have the ewdk 2022 version as a mounted iso.
Activating the ewdk environment then running cmake .. in the project results in the following error:

$> cmake .. -G "Visual Studio 17 2022"
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19045.
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:8 (project):
  No CMAKE_C_COMPILER could be found.

CMake Error at CMakeLists.txt:8 (project):
  No CMAKE_CXX_COMPILER could be found.

-- Configuring incomplete, errors occurred!

Looking at it with procmon it seems that cmake is opening some registries to find installed versions of visual studio and windows kits, it finds the 2019 version (which is not good) and uses that, totally disregarding the environment it is running in.

Do you know how this can be avoided? Can I specify some environment variables that would stop cmake for looking elsewhere and use what it has in the environment? Or any ideas on how I could navigate this problem.

Thank you :slight_smile:

Try using Ninja instead. It will uses the compilers provided by the EWDK environment.

cmake … -G “Ninja”

with Ninja I can use the actual environment (even though ewdk doesn’t define everything that would be needed apparently and will just have to track some libraries, but it should work now). I was hoping for something that I wouldn’t be needed to download extra tools but I guess this is a simple solution.

Thank you :slight_smile:

1 Like

Did simply using ninja as the generator work or were there further steps that had to be taken?

I’m having a similar issue but with code that isn’t mine. I’m using vcpkg to build zlib within the EWDK environment. zlib is already using ninja, but the CMake configure step fails.

Logs/output can be found Support EWDK for building packages · microsoft/vcpkg · Discussion #27449 · GitHub

I’m guessing there is something between CMake and vcpkg. I’m not an expert in either so if there are any CMake experts that can see anything in the logs that doesn’t look correct, your help is greatly appreciated.

it wasn’t “that simple”, EWDK doesn’t seem to define library paths, in order to run the configure i had to add some things to the environment after activating the ewdk:

set LIB=%LIB%;%WindowsSdkDir%\Lib\%Version_Number%\um\x64;%WindowsSdkDir%\Lib\%Version_Number%\ucrt\x64;%WindowsSdkDir%\Lib\%Version_Number%\km\x64

that line should make you pass the “compile simple test” that is done at cmake configuration. Currently I am still having problems with some missing libraries, but i didn’t have time to see what else is missing.

Looking at your logs the error is not explicit but might be the same as I encountered - cmake is unable to open some <name>.lib, if you get that again after the line I gave above to update the lib you could do something like dir /s *<name>.lib and add that path to the lib too (@thxkiwi tag for visibility)

Thanks. Looks like the vcpkg+cmake issue is related to how vcpkg invokes CMake.

It took both LIB and INCLUDE to get it building but I did get zlib to build via directly invoking cmake.

To handle the setup of the correct env vars I modified the EWDK\BuildEnv\setdevenv.cmd to set LIB and INCLUDE depending on x86 or amd64 (similar to the “platform” values that can be passed to EWDK LaunchBuildEnv.cmd)

REM
REM   This is where you add your custom build environment settings.
REM 
REM
REM
REM   Put global custom environment settings before specifying targeted custom configs
REM  
REM   GLOBAL Settings

REM  SET SRCROOT=D:\_NTROOT
set VS160COMNTOOLS=%VS170COMNTOOLS%

set WindowsSdk_IncludePath=%WindowsSdkDir%Include\%Version_Number%\ucrt;%WindowsSdkDir%Include\%Version_Number%\um;%WindowsSdkDir%Include\%Version_Number%\shared;%WindowsSdkDir%Include\%Version_Number%\winrt;%WindowsSdkDir%Include\%Version_Number%\cppwinrt
set INCLUDE=%INCLUDE%;%WindowsSdk_IncludePath%

set WindowsSdk_LibraryPath_x64=%WindowsSdkDir%Lib\%Version_Number%\ucrt\x64;%WindowsSdkDir%Lib\%Version_Number%\um\x64;%WindowsSdkDir%Lib\%Version_Number%\km\x64

set WindowsSdk_LibraryPath_x86=%WindowsSdkDir%Lib\%Version_Number%\ucrt\x86;%WindowsSdkDir%Lib\%Version_Number%\um\x86;%WindowsSdkDir%Lib\%Version_Number%\km\x86

REM  Specfic targeted environment settings

if /i "%1" == "" goto :EOF 

echo Setting up custom environment for :Custom%1
goto :Custom%1

:Customamd64
echo Setting LIB for WindowsSdk_LibraryPath_x64
REM    :Custom<argument> - if multiple custom environments will be specified, you must change %1 to <specified argument>
REM     Where <Argument> is MyConfig
REM     Example :CustomMyConfig
set LIB=%LIB%;%WindowsSdk_LibraryPath_x64%
goto :EOF

:Customx86
echo Setting LIB for WindowsSdk_LibraryPath_x86
set LIB=%LIB%;%WindowsSdk_LibraryPath_x86%

goto :EOF
REM   Add additional :Custom<Argument> for each specific build type


:EOF

Incase it’s useful, I maintain a few CMake Toolchains for Windows in the MarkSchofield/WindowsToolchain repo, and one of them is for the EWDK - Windows.EWDK.toolchain.cmake. If you specify that toolchain and invoke CMake from a EWDK build window, then it should configure CMake using the configuration of the build window. There’s a a “ewdk” preset in the example folder you can use to try it out.