FindFseeko.cmake 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # CMake support for fseeko
  2. #
  3. # Based on FindLFS.cmake by
  4. # Copyright (C) 2016 Julian Andres Klode <jak@debian.org>.
  5. #
  6. # Permission is hereby granted, free of charge, to any person
  7. # obtaining a copy of this software and associated documentation files
  8. # (the "Software"), to deal in the Software without restriction,
  9. # including without limitation the rights to use, copy, modify, merge,
  10. # publish, distribute, sublicense, and/or sell copies of the Software,
  11. # and to permit persons to whom the Software is furnished to do so,
  12. # subject to the following conditions:
  13. #
  14. # The above copyright notice and this permission notice shall be
  15. # included in all copies or substantial portions of the Software.
  16. #
  17. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  21. # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  22. # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  23. # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  24. # SOFTWARE.
  25. #
  26. # This defines the following variables
  27. #
  28. # FSEEKO_DEFINITIONS - List of definitions to pass to add_definitions()
  29. # FSEEKO_COMPILE_OPTIONS - List of definitions to pass to add_compile_options()
  30. # FSEEKO_LIBRARIES - List of libraries and linker flags
  31. # FSEEKO_FOUND - If there is Large files support
  32. #
  33. include(CheckCSourceCompiles)
  34. include(FindPackageHandleStandardArgs)
  35. include(CMakePushCheckState)
  36. # Check for the availability of fseeko()
  37. # The cases handled are:
  38. #
  39. # * Native fseeko()
  40. # * Preprocessor flag -D_LARGEFILE_SOURCE
  41. #
  42. function(_fseeko_check)
  43. set(_fseeko_cppflags)
  44. cmake_push_check_state()
  45. set(CMAKE_REQUIRED_QUIET 1)
  46. set(CMAKE_REQUIRED_DEFINITIONS ${LFS_DEFINITIONS})
  47. message(STATUS "Looking for native fseeko support")
  48. check_symbol_exists(fseeko stdio.h fseeko_native)
  49. cmake_pop_check_state()
  50. if (fseeko_native)
  51. message(STATUS "Looking for native fseeko support - found")
  52. set(FSEEKO_FOUND TRUE)
  53. else()
  54. message(STATUS "Looking for native fseeko support - not found")
  55. endif()
  56. if (NOT FSEEKO_FOUND)
  57. # See if it's available with _LARGEFILE_SOURCE.
  58. cmake_push_check_state()
  59. set(CMAKE_REQUIRED_QUIET 1)
  60. set(CMAKE_REQUIRED_DEFINITIONS ${LFS_DEFINITIONS} "-D_LARGEFILE_SOURCE")
  61. check_symbol_exists(fseeko stdio.h fseeko_need_largefile_source)
  62. cmake_pop_check_state()
  63. if (fseeko_need_largefile_source)
  64. message(STATUS "Looking for fseeko support with _LARGEFILE_SOURCE - found")
  65. set(FSEEKO_FOUND TRUE)
  66. set(_fseeko_cppflags "-D_LARGEFILE_SOURCE")
  67. else()
  68. message(STATUS "Looking for fseeko support with _LARGEFILE_SOURCE - not found")
  69. endif()
  70. endif()
  71. set(FSEEKO_DEFINITIONS ${_fseeko_cppflags} CACHE STRING "Extra definitions for fseeko support")
  72. set(FSEEKO_COMPILE_OPTIONS "" CACHE STRING "Extra compiler options for fseeko support")
  73. set(FSEEKO_LIBRARIES "" CACHE STRING "Extra definitions for fseeko support")
  74. set(FSEEKO_FOUND ${FSEEKO_FOUND} CACHE INTERNAL "Found fseeko")
  75. endfunction()
  76. if (NOT FSEEKO_FOUND)
  77. _fseeko_check()
  78. endif()
  79. find_package_handle_standard_args(FSEEKO "Could not find fseeko. Set FSEEKO_DEFINITIONS, FSEEKO_COMPILE_OPTIONS, FSEEKO_LIBRARIES." FSEEKO_FOUND)