OpenVDBUtils.cmake 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. # Copyright (c) DreamWorks Animation LLC
  2. #
  3. # All rights reserved. This software is distributed under the
  4. # Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
  5. #
  6. # Redistributions of source code must retain the above copyright
  7. # and license notice and the following restrictions and disclaimer.
  8. #
  9. # * Neither the name of DreamWorks Animation nor the names of
  10. # its contributors may be used to endorse or promote products derived
  11. # from this software without specific prior written permission.
  12. #
  13. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  14. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  15. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  16. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  17. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
  18. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  19. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. # IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
  25. # LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
  26. #
  27. #[=======================================================================[.rst:
  28. OpenVDBUtils.cmake
  29. ------------------
  30. A utility CMake file which provides helper functions for configuring an
  31. OpenVDB installation.
  32. Use this module by invoking include with the form::
  33. include ( OpenVDBUtils )
  34. The following functions are provided:
  35. ``OPENVDB_VERSION_FROM_HEADER``
  36. OPENVDB_VERSION_FROM_HEADER ( <header_path>
  37. VERSION [<version>]
  38. MAJOR [<version>]
  39. MINOR [<version>]
  40. PATCH [<version>] )
  41. Parse the provided version file to retrieve the current OpenVDB
  42. version information. The file is expected to be a version.h file
  43. as found in the following path of an OpenVDB repository:
  44. openvdb/version.h
  45. If the file does not exist, variables are unmodified.
  46. ``OPENVDB_ABI_VERSION_FROM_PRINT``
  47. OPENVDB_ABI_VERSION_FROM_PRINT ( <vdb_print>
  48. [QUIET]
  49. ABI [<version>] )
  50. Retrieve the ABI version that an installation of OpenVDB was compiled
  51. for using the provided vdb_print binary. Parses the result of:
  52. vdb_print --version
  53. If the binary does not exist or fails to launch, variables are
  54. unmodified.
  55. #]=======================================================================]
  56. function(OPENVDB_VERSION_FROM_HEADER OPENVDB_VERSION_FILE)
  57. cmake_parse_arguments(_VDB "" "VERSION;MAJOR;MINOR;PATCH" "" ${ARGN})
  58. if(NOT EXISTS ${OPENVDB_VERSION_FILE})
  59. return()
  60. endif()
  61. file(STRINGS "${OPENVDB_VERSION_FILE}" openvdb_version_str
  62. REGEX "^#define[\t ]+OPENVDB_LIBRARY_MAJOR_VERSION_NUMBER[\t ]+.*"
  63. )
  64. string(REGEX REPLACE "^.*OPENVDB_LIBRARY_MAJOR_VERSION_NUMBER[\t ]+([0-9]*).*$" "\\1"
  65. _OpenVDB_MAJOR_VERSION "${openvdb_version_str}"
  66. )
  67. file(STRINGS "${OPENVDB_VERSION_FILE}" openvdb_version_str
  68. REGEX "^#define[\t ]+OPENVDB_LIBRARY_MINOR_VERSION_NUMBER[\t ]+.*"
  69. )
  70. string(REGEX REPLACE "^.*OPENVDB_LIBRARY_MINOR_VERSION_NUMBER[\t ]+([0-9]*).*$" "\\1"
  71. _OpenVDB_MINOR_VERSION "${openvdb_version_str}"
  72. )
  73. file(STRINGS "${OPENVDB_VERSION_FILE}" openvdb_version_str
  74. REGEX "^#define[\t ]+OPENVDB_LIBRARY_PATCH_VERSION_NUMBER[\t ]+.*"
  75. )
  76. string(REGEX REPLACE "^.*OPENVDB_LIBRARY_PATCH_VERSION_NUMBER[\t ]+([0-9]*).*$" "\\1"
  77. _OpenVDB_PATCH_VERSION "${openvdb_version_str}"
  78. )
  79. unset(openvdb_version_str)
  80. if(_VDB_VERSION)
  81. set(${_VDB_VERSION}
  82. ${_OpenVDB_MAJOR_VERSION}.${_OpenVDB_MINOR_VERSION}.${_OpenVDB_PATCH_VERSION}
  83. PARENT_SCOPE
  84. )
  85. endif()
  86. if(_VDB_MAJOR)
  87. set(${_VDB_MAJOR} ${_OpenVDB_MAJOR_VERSION} PARENT_SCOPE)
  88. endif()
  89. if(_VDB_MINOR)
  90. set(${_VDB_MINOR} ${_OpenVDB_MINOR_VERSION} PARENT_SCOPE)
  91. endif()
  92. if(_VDB_PATCH)
  93. set(${_VDB_PATCH} ${_OpenVDB_PATCH_VERSION} PARENT_SCOPE)
  94. endif()
  95. endfunction()
  96. ########################################################################
  97. ########################################################################
  98. function(OPENVDB_ABI_VERSION_FROM_PRINT OPENVDB_PRINT)
  99. cmake_parse_arguments(_VDB "QUIET" "ABI" "" ${ARGN})
  100. if(NOT EXISTS ${OPENVDB_PRINT})
  101. if(NOT OpenVDB_FIND_QUIETLY)
  102. message(WARNING "vdb_print not found! ${OPENVDB_PRINT}")
  103. endif()
  104. return()
  105. endif()
  106. set(_VDB_PRINT_VERSION_STRING "")
  107. set(_VDB_PRINT_RETURN_STATUS "")
  108. if(${_VDB_QUIET})
  109. execute_process(COMMAND ${OPENVDB_PRINT} "--version"
  110. RESULT_VARIABLE _VDB_PRINT_RETURN_STATUS
  111. OUTPUT_VARIABLE _VDB_PRINT_VERSION_STRING
  112. ERROR_QUIET
  113. OUTPUT_STRIP_TRAILING_WHITESPACE
  114. )
  115. else()
  116. execute_process(COMMAND ${OPENVDB_PRINT} "--version"
  117. RESULT_VARIABLE _VDB_PRINT_RETURN_STATUS
  118. OUTPUT_VARIABLE _VDB_PRINT_VERSION_STRING
  119. OUTPUT_STRIP_TRAILING_WHITESPACE
  120. )
  121. endif()
  122. if(${_VDB_PRINT_RETURN_STATUS})
  123. if(NOT OpenVDB_FIND_QUIETLY)
  124. message(WARNING "vdb_print returned with status ${_VDB_PRINT_RETURN_STATUS}")
  125. endif()
  126. return()
  127. endif()
  128. set(_OpenVDB_ABI)
  129. string(REGEX REPLACE ".*abi([0-9]*).*" "\\1" _OpenVDB_ABI ${_VDB_PRINT_VERSION_STRING})
  130. if(${_OpenVDB_ABI} STREQUAL ${_VDB_PRINT_VERSION_STRING})
  131. set(_OpenVDB_ABI "")
  132. endif()
  133. unset(_VDB_PRINT_RETURN_STATUS)
  134. unset(_VDB_PRINT_VERSION_STRING)
  135. if(_VDB_ABI)
  136. set(${_VDB_ABI} ${_OpenVDB_ABI} PARENT_SCOPE)
  137. endif()
  138. endfunction()