Findassimplib.cmake 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. # assimp depends on ZLIB. For maximum compatibility here, we use the
  9. # official ZLIB library name, ie, ZLIB::ZLIB and not o3de 3rdParty::ZLIB.
  10. # O3DE's zlib package will define both. If we're in O3DE we can also
  11. # auto-download ZLIB.
  12. if (NOT TARGET ZLIB::ZLIB)
  13. if (COMMAND ly_download_associated_package)
  14. ly_download_associated_package(ZLIB REQUIRED MODULE)
  15. endif()
  16. find_package(ZLIB)
  17. endif()
  18. # this file actually ingests the library and defines targets.
  19. set(TARGET_WITH_NAMESPACE "3rdParty::assimplib")
  20. if (TARGET ${TARGET_WITH_NAMESPACE})
  21. return()
  22. endif()
  23. set(LIB_NAME "assimp")
  24. set(${LIB_NAME}_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/assimp/include)
  25. set(${LIB_NAME}_BIN_DIR ${CMAKE_CURRENT_LIST_DIR}/assimp/bin)
  26. set(${LIB_NAME}_LIBS_DIR ${CMAKE_CURRENT_LIST_DIR}/assimp/lib)
  27. if (${PAL_PLATFORM_NAME} STREQUAL "Linux")
  28. set(${LIB_NAME}_LIBRARY_DEBUG ${${LIB_NAME}_BIN_DIR}/libassimp.so.5.4.3)
  29. set(${LIB_NAME}_LIBRARY_RELEASE ${${LIB_NAME}_BIN_DIR}/libassimp.so.5.4.3)
  30. set(${LIB_NAME}_STATIC_LIBRARY_DEBUG ${${LIB_NAME}_LIBS_DIR}/libassimp.a)
  31. set(${LIB_NAME}_STATIC_LIBRARY_RELEASE ${${LIB_NAME}_LIBS_DIR}/libassimp.a)
  32. elseif (${PAL_PLATFORM_NAME} STREQUAL "Mac")
  33. set(${LIB_NAME}_LIBRARY_DEBUG ${${LIB_NAME}_BIN_DIR}/libassimp.5.4.3.dylib)
  34. set(${LIB_NAME}_LIBRARY_RELEASE ${${LIB_NAME}_BIN_DIR}/libassimp.5.4.3.dylib)
  35. set(${LIB_NAME}_STATIC_LIBRARY_DEBUG ${${LIB_NAME}_LIBS_DIR}/libassimp.a)
  36. set(${LIB_NAME}_STATIC_LIBRARY_RELEASE ${${LIB_NAME}_LIBS_DIR}/libassimp.a)
  37. elseif (${PAL_PLATFORM_NAME} STREQUAL "Windows")
  38. set(${LIB_NAME}_LIBRARY_DEBUG ${${LIB_NAME}_BIN_DIR}/debug/assimp-vc143-mtd.dll)
  39. set(${LIB_NAME}_LIBRARY_RELEASE ${${LIB_NAME}_BIN_DIR}/release/assimp-vc143-mt.dll)
  40. set(${LIB_NAME}_STATIC_LIBRARY_DEBUG ${${LIB_NAME}_LIBS_DIR}/debug/assimp-vc143-mtd.lib)
  41. set(${LIB_NAME}_STATIC_LIBRARY_RELEASE ${${LIB_NAME}_LIBS_DIR}/release/assimp-vc143-mt.lib)
  42. endif()
  43. # set it to a generator expression for multi-config situations
  44. set(${LIB_NAME}_DYNLIB $<IF:$<CONFIG:Debug>,${${LIB_NAME}_LIBRARY_DEBUG},${${LIB_NAME}_LIBRARY_RELEASE}>)
  45. # Order of linking is not enforced by target_link_libraries on some compilers
  46. # To workaround this problem, we wrap the static lib in an imported lib and mark the dependency there. That makes
  47. # the DAG algorithm to sort them in the order we need.
  48. add_library(${TARGET_WITH_NAMESPACE}::imported STATIC IMPORTED)
  49. set_target_properties(${TARGET_WITH_NAMESPACE}::imported
  50. PROPERTIES
  51. IMPORTED_LOCATION_DEBUG ${${LIB_NAME}_STATIC_LIBRARY_DEBUG}
  52. IMPORTED_LOCATION_PROFILE ${${LIB_NAME}_STATIC_LIBRARY_RELEASE}
  53. IMPORTED_LOCATION_RELEASE ${${LIB_NAME}_STATIC_LIBRARY_RELEASE}
  54. )
  55. target_link_libraries(${TARGET_WITH_NAMESPACE}::imported
  56. INTERFACE 3rdParty::zlib
  57. )
  58. add_library(${TARGET_WITH_NAMESPACE} INTERFACE IMPORTED GLOBAL)
  59. ly_target_include_system_directories(TARGET ${TARGET_WITH_NAMESPACE} INTERFACE ${${LIB_NAME}_INCLUDE_DIR})
  60. set_target_properties(${TARGET_WITH_NAMESPACE} PROPERTIES
  61. INTERFACE_IMPORTED_LOCATION "${${LIB_NAME}_DYNLIB}"
  62. )
  63. target_link_libraries(${TARGET_WITH_NAMESPACE}
  64. INTERFACE ${TARGET_WITH_NAMESPACE}::imported
  65. )
  66. set(3RDPARTY_ASSIMP_RUNTIME_DEPENDENCIES "${${LIB_NAME}_DYNLIB}")
  67. # install Python bindings to AssImp (i.e. PyAssImp)
  68. ly_pip_install_local_package_editable(${CMAKE_CURRENT_LIST_DIR}/assimp/port/PyAssimp pyassimp)
  69. set(${LIB_NAME}_FOUND True)