draco_install.cmake 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # Copyright 2021 The Draco Authors
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not
  4. # use this file except in compliance with the License. You may obtain a copy of
  5. # the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. # License for the specific language governing permissions and limitations under
  13. # the License.
  14. if(DRACO_CMAKE_DRACO_INSTALL_CMAKE_)
  15. return()
  16. endif() # DRACO_CMAKE_DRACO_INSTALL_CMAKE_
  17. set(DRACO_CMAKE_DRACO_INSTALL_CMAKE_ 1)
  18. include(CMakePackageConfigHelpers)
  19. include(GNUInstallDirs)
  20. # Sets up the draco install targets. Must be called after the static library
  21. # target is created.
  22. macro(draco_setup_install_target)
  23. set(bin_path "${CMAKE_INSTALL_BINDIR}")
  24. set(data_path "${CMAKE_INSTALL_DATAROOTDIR}")
  25. set(includes_path "${CMAKE_INSTALL_INCLUDEDIR}")
  26. set(libs_path "${CMAKE_INSTALL_LIBDIR}")
  27. foreach(file ${draco_sources})
  28. if(file MATCHES "h$")
  29. list(APPEND draco_api_includes ${file})
  30. endif()
  31. endforeach()
  32. list(REMOVE_DUPLICATES draco_api_includes)
  33. # Strip $draco_src_root from the file paths: we need to install relative to
  34. # $include_directory.
  35. list(TRANSFORM draco_api_includes REPLACE "${draco_src_root}/" "")
  36. foreach(draco_api_include ${draco_api_includes})
  37. get_filename_component(file_directory ${draco_api_include} DIRECTORY)
  38. set(target_directory "${includes_path}/draco/${file_directory}")
  39. install(FILES ${draco_src_root}/${draco_api_include}
  40. DESTINATION "${target_directory}")
  41. endforeach()
  42. install(FILES "${draco_build}/draco/draco_features.h"
  43. DESTINATION "${includes_path}/draco/")
  44. install(TARGETS draco_decoder DESTINATION "${bin_path}")
  45. install(TARGETS draco_encoder DESTINATION "${bin_path}")
  46. if(DRACO_TRANSCODER_SUPPORTED)
  47. install(TARGETS draco_transcoder DESTINATION "${bin_path}")
  48. endif()
  49. if(MSVC)
  50. install(
  51. TARGETS draco
  52. EXPORT dracoExport
  53. RUNTIME DESTINATION "${bin_path}"
  54. ARCHIVE DESTINATION "${libs_path}"
  55. LIBRARY DESTINATION "${libs_path}")
  56. else()
  57. install(
  58. TARGETS draco_static
  59. EXPORT dracoExport
  60. DESTINATION "${libs_path}")
  61. if(BUILD_SHARED_LIBS)
  62. install(
  63. TARGETS draco_shared
  64. EXPORT dracoExport
  65. RUNTIME DESTINATION "${bin_path}"
  66. ARCHIVE DESTINATION "${libs_path}"
  67. LIBRARY DESTINATION "${libs_path}")
  68. endif()
  69. endif()
  70. if(DRACO_UNITY_PLUGIN)
  71. install(TARGETS dracodec_unity DESTINATION "${libs_path}")
  72. endif()
  73. if(DRACO_MAYA_PLUGIN)
  74. install(TARGETS draco_maya_wrapper DESTINATION "${libs_path}")
  75. endif()
  76. # pkg-config: draco.pc
  77. configure_file("${draco_root}/cmake/draco.pc.template"
  78. "${draco_build}/draco.pc" @ONLY NEWLINE_STYLE UNIX)
  79. install(FILES "${draco_build}/draco.pc" DESTINATION "${libs_path}/pkgconfig")
  80. # CMake config: draco-config.cmake
  81. configure_package_config_file(
  82. "${draco_root}/cmake/draco-config.cmake.template"
  83. "${draco_build}/draco-config.cmake"
  84. INSTALL_DESTINATION "${data_path}/cmake/draco")
  85. write_basic_package_version_file(
  86. "${draco_build}/draco-config-version.cmake"
  87. VERSION ${DRACO_VERSION}
  88. COMPATIBILITY AnyNewerVersion)
  89. export(
  90. EXPORT dracoExport
  91. NAMESPACE draco::
  92. FILE "${draco_build}/draco-targets.cmake")
  93. install(
  94. EXPORT dracoExport
  95. NAMESPACE draco::
  96. FILE draco-targets.cmake
  97. DESTINATION "${data_path}/cmake/draco")
  98. install(FILES "${draco_build}/draco-config.cmake"
  99. "${draco_build}/draco-config-version.cmake"
  100. DESTINATION "${data_path}/cmake/draco")
  101. endmacro()