google / draco

Draco is a library for compressing and decompressing 3D geometric meshes and point clouds. It is intended to improve the storage and transmission of 3D graphics.
https://google.github.io/draco/
Apache License 2.0
6.48k stars 963 forks source link

Fix build error on Windows with Clang #1069

Open SpinnerX opened 4 months ago

SpinnerX commented 4 months ago

Resolves #1018

SpinnerX commented 3 months ago

The build was failing with Clang on Windows due to order of precedence of the macros for determining file size.

C:\Users\heraa.conan2\p\b\draco1d23f170ed5b0\b\src\src\draco\io\stdio_file_reader.cc:91:48: error: use of undeclared identifier 'ftello'; did you mean 'ftell'?

The _FILE_OFFSET_BITS macro is defined in the file cmake\draco_build_definitions.cmake. The code in question is the part below.

if(NOT MSVC)
    if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
      # Ensure 64-bit platforms can support large files.
      list(APPEND draco_defines "_LARGEFILE_SOURCE" "_FILE_OFFSET_BITS=64")
    endif()

When _FILE_OFFSET_BITS is defined, it uses the linux only C API which fails on Windows. I decided to only change the macro order in the header file src\draco\io\stdio_file_reader.cc because I wasn't sure if there were other potential use cases for this macro in the future.