Skip to content

CMake: handle _INCLUDE_DIR not leveraged at compile time #3132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 8, 2025

Conversation

jmckenna
Copy link
Contributor

@jmckenna jmckenna commented May 15, 2025

Background

  • the issue affects those on Windows compiling their own libraries, but also pointing to their include folders separately, with CMake's xxx_INCLUDE_DIR setting for each of their dependent libraries
  • since the 3.9.3 release those include dir settings have not been leveraged by CMake at compile time (meaning: all libs will be reported as found by CMake, but then at compile time, CMake will not find the include files)
    • many common packaging systems get around the CMake xxx_INCLUDE_DIR not finding include files by keeping all include files in the same directory (so something like the path of curl/curl.h can always be found by any other library's files)
      • most likely your test environment here uses Conda or vcpkg or some other system that does exactly that
  • so you might have been noticing Windows users since the 4.9.3 release saying "hi I compile all my libraries myself but recently I have this compile error for netcdf-c of zlib.h - no such file or directory, or curl/curl.h, or mfhdf.h, etc

Environment

  • Windows & Visual Studio compiler
  • compiled all dependent external libraries myself/themselves
    • in my case: such as hdf4 & hdf5 (git master from today), curl, zlib, etc etc
  • testing with today's netcdf-c git main

Error messages during compile

  • with Curl enabled
C:\netcdf-c-git-jmckenna\libdispatch\ddispatch.c(28): fatal error C1083: Cannot open include file: 'curl/curl.h': No such file or directory
  • with HDF4 enabled
C:\netcdf-c-git-jmckenna\libhdf4\hdf4file.c(14): fatal error C1083: Cannot open include file: 'mfhdf.h': No such file or directory
  • with zlib enabled
C:\netcdf-c-git-jmckenna\plugins\H5Zdeflate.c(23): fatal error C1083: Cannot open include file: 'zlib.h': No such file or directory

Workarounds

  • see this pull request for the workarounds
  • this pull request as-is will fix the user reported compile errors
    • however, most likely there is a more elegant way to handle this
      • such as moving that target_include_directories statement from CMakeLists.txt from the top, down into some other if (NETCDF_ENABLE_xxx) section of that CMakeLists.txt)
        • I just don't know which plugins etc require these includes, so it will need input here from the netcdf-c maintainers

My goal here is to post my workaround, and hopefully help other packagers, and maybe, just maybe, get these changes included in the next netcdf-c release

Thanks again,

@jmckenna
Copy link
Contributor Author

Important to stress again: CMake reports all libraries as found, the compile errors will happen not when you run the cmake command, but during the compile command (however you choose to generate your MSVC scripts).

@WardF WardF merged commit 49ca844 into Unidata:main Jul 8, 2025
63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants