noloader / cryptopp-cmake

CMake files for Crypto++ project
BSD 3-Clause "New" or "Revised" License
92 stars 68 forks source link

Cannot find header file <winapifamily.h> #47

Closed SylvainCorlay closed 2 years ago

SylvainCorlay commented 5 years ago

Removing the line in CMakeLists.txt adding the winapifamily include resolves that issue.

noloader commented 5 years ago

Yeah, I've seen a problem similar to this before. The problem is, we can't figure out how to get CMake to use LIB and INCLUDE directories from the environment. For example, open an ARM Developer Prompt and:

% set
...
INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\
MSVC\14.16.27023\ATLMFC\include;C:\Program Files (x86)\Microsoft Visual Studio\2
017\BuildTools\VC\Tools\MSVC\14.16.27023\include;C:\Program Files (x86)\Windows
Kits\NETFXSDK\4.6.1\include\um;C:\Program Files (x86)\Windows Kits\10\include\10
.0.17763.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shar
ed;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um;C:\Program Fil
es (x86)\Windows Kits\10\include\10.0.17763.0\winrt;C:\Program Files (x86)\Windo
ws Kits\10\include\10.0.17763.0\cppwinrt
...
LIB=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC
\14.16.27023\lib\ARM64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.17763.0\u
crt\arm64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.17763.0\um\arm64;
LIBPATH=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\
MSVC\14.16.27023\lib\ARM64;C:\Program Files (x86)\Microsoft Visual Studio\2017\B
uildTools\VC\Tools\MSVC\14.16.27023\lib\x86\store\references;C:\Program Files (x
86)\Windows Kits\10\UnionMetadata\10.0.17763.0;C:\Program Files (x86)\Windows Ki
ts\10\References\10.0.17763.0;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;

The directories with the files are available, but CMake does not use them???

I think your best option is to remove it manually like you did.

smessmer commented 5 years ago

Running into the same issue. What is this header supposed to do? Will commenting it out break something?

noloader commented 5 years ago

@smessmer,

If I recall correctly, <winapifamily.h> sets up Windows Phone and Windows store apps (formerly Metro apps and whatever else Microsoft calls them). The phone and store apps use that partitioning scheme Microsoft came up with. They include the macros like:

If you don't use the header then there's a risk we will misdetect the platform. Getting the platform is right is important for some cases like determining how to get random numbers from the operating system:

#ifdef CRYPTOPP_WIN32_AVAILABLE
# if !defined(WINAPI_FAMILY)
#   define NONBLOCKING_RNG_AVAILABLE
#   define OS_RNG_AVAILABLE
# elif defined(WINAPI_FAMILY)
#   if (WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))
#     define NONBLOCKING_RNG_AVAILABLE
#     define OS_RNG_AVAILABLE
#   elif !(WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))
#     if ((WINVER >= 0x0A00 /*_WIN32_WINNT_WIN10*/) || (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/))
#       define NONBLOCKING_RNG_AVAILABLE
#       define OS_RNG_AVAILABLE
#     endif
#   endif
# endif
#endif
noloader commented 5 years ago

I think your best option is to remove <winapifamily.h> manually like you did.

By the way, if anyone can figure out how to tell CMake to find the <winapifamily.h> header and use it, then I'm happy to add that patch, too.

petermost commented 3 years ago

I think your best option is to remove <winapifamily.h> manually like you did.

By the way, if anyone can figure out how to tell CMake to find the <winapifamily.h> header and use it, then I'm happy to add that patch, too.

I'm using the downloaded version cryptopp-cmake-CRYPTOPP_8_2_0.zip. In order to fix the problem, I simply had to remove the quotes around the header winapifamiliy.h. So the line 450 in the CMakeList.txt file becomes: list(APPEND CRYPTOPP_COMPILE_OPTIONS "/FIwinapifamily.h") That fixed the problem for me.

HTH

CleanHit commented 3 years ago

Using the release tag CRYPTOPP_8_2_0 gave me this error to because of list(APPEND CRYPTOPP_COMPILE_OPTIONS "/FI\"winapifamily.h\"") in line 450. The current master branch has this instead in line 395 list(APPEND CRYPTOPP_COMPILE_OPTIONS /FI winapifamily.h), this solved the error Cannot find header file during build for me.

My environment info: OS: Windows 10 IDE: Visual Studio Code Compiler: MSVC/14.28.29333 CMake: 3.19.1

noloader commented 3 years ago

Should the use of <winapifamily.h> be guarded with CHECK_INCLUDE_FILE?

I think it is always included because you need a SDK nowadays on MS platforms.

noloader commented 2 years ago

I think this is what is needed for Visual Studio:

  INCLUDE (CheckIncludeFiles)
  CHECK_INCLUDE_FILES (winapifamily.h HAVE_WINAPIFAMILY_H)
  if (HAVE_WINAPIFAMILY_H)
    list(APPEND CRYPTOPP_COMPILE_OPTIONS "/FIwinapifamily.h")
  endif()

It looks like Visual Studio no longer pukes on <winapifamily.h> with it.

I finally get to close a CMake issue.