draco_install.cmake 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. if(DRACO_INSTALL)
  24. set(bin_path "${CMAKE_INSTALL_BINDIR}")
  25. set(data_path "${CMAKE_INSTALL_DATAROOTDIR}")
  26. set(includes_path "${CMAKE_INSTALL_INCLUDEDIR}")
  27. set(libs_path "${CMAKE_INSTALL_LIBDIR}")
  28. foreach(file ${draco_sources})
  29. if(file MATCHES "h$")
  30. list(APPEND draco_api_includes ${file})
  31. endif()
  32. endforeach()
  33. list(REMOVE_DUPLICATES draco_api_includes)
  34. # Strip $draco_src_root from the file paths: we need to install relative to
  35. # $include_directory.
  36. list(TRANSFORM draco_api_includes REPLACE "${draco_src_root}/" "")
  37. foreach(draco_api_include ${draco_api_includes})
  38. get_filename_component(file_directory ${draco_api_include} DIRECTORY)
  39. set(target_directory "${includes_path}/draco/${file_directory}")
  40. install(FILES ${draco_src_root}/${draco_api_include}
  41. DESTINATION "${target_directory}")
  42. endforeach()
  43. install(FILES "${draco_build}/draco/draco_features.h"
  44. DESTINATION "${includes_path}/draco/")
  45. install(TARGETS draco_decoder DESTINATION "${bin_path}")
  46. install(TARGETS draco_encoder DESTINATION "${bin_path}")
  47. if(DRACO_TRANSCODER_SUPPORTED)
  48. install(TARGETS draco_transcoder DESTINATION "${bin_path}")
  49. endif()
  50. if(MSVC)
  51. install(
  52. TARGETS draco
  53. EXPORT dracoExport
  54. RUNTIME DESTINATION "${bin_path}"
  55. ARCHIVE DESTINATION "${libs_path}"
  56. LIBRARY DESTINATION "${libs_path}")
  57. else()
  58. install(
  59. TARGETS draco_static
  60. EXPORT dracoExport
  61. DESTINATION "${libs_path}")
  62. if(BUILD_SHARED_LIBS)
  63. install(
  64. TARGETS draco_shared
  65. EXPORT dracoExport
  66. RUNTIME DESTINATION "${bin_path}"
  67. ARCHIVE DESTINATION "${libs_path}"
  68. LIBRARY DESTINATION "${libs_path}")
  69. endif()
  70. endif()
  71. if(DRACO_UNITY_PLUGIN)
  72. install(TARGETS dracodec_unity DESTINATION "${libs_path}")
  73. endif()
  74. if(DRACO_MAYA_PLUGIN)
  75. install(TARGETS draco_maya_wrapper DESTINATION "${libs_path}")
  76. endif()
  77. # pkg-config: draco.pc
  78. configure_file("${draco_root}/cmake/draco.pc.template"
  79. "${draco_build}/draco.pc" @ONLY NEWLINE_STYLE UNIX)
  80. install(FILES "${draco_build}/draco.pc" DESTINATION "${libs_path}/pkgconfig")
  81. # CMake config: draco-config.cmake
  82. configure_package_config_file(
  83. "${draco_root}/cmake/draco-config.cmake.template"
  84. "${draco_build}/draco-config.cmake"
  85. INSTALL_DESTINATION "${data_path}/cmake/draco")
  86. write_basic_package_version_file(
  87. "${draco_build}/draco-config-version.cmake"
  88. VERSION ${DRACO_VERSION}
  89. COMPATIBILITY AnyNewerVersion)
  90. export(
  91. EXPORT dracoExport
  92. NAMESPACE draco::
  93. FILE "${draco_build}/draco-targets.cmake")
  94. install(
  95. EXPORT dracoExport
  96. NAMESPACE draco::
  97. FILE draco-targets.cmake
  98. DESTINATION "${data_path}/cmake/draco")
  99. install(FILES "${draco_build}/draco-config.cmake"
  100. "${draco_build}/draco-config-version.cmake"
  101. DESTINATION "${data_path}/cmake/draco")
  102. endif(DRACO_INSTALL)
  103. endmacro()